X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-dbus.c;h=387b824f78abd8a56291052ba53bf7bfb6d22ba6;hb=265fbcd7e07db9611f3f482b335add2c7979dca5;hp=3ad24b1fee20a31c0f8e44a62da9cda53eae991a;hpb=b4f4684f3a95c915491cd7845911ecdf2622b2c2;p=elogind.git diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 3ad24b1fe..387b824f7 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -41,7 +41,7 @@ #include "path-util.h" #include "process-util.h" #include "selinux-util.h" -//#include "sleep-config.h" +#include "sleep-config.h" //#include "special.h" #include "strv.h" #include "terminal-util.h" @@ -50,9 +50,13 @@ #include "user-util.h" #include "utmp-wtmp.h" -/// Includes needed by elogind: +/// Additional includes needed by elogind #include "update-utmp.h" +#if 1 /// elogind needs this prototype +static int send_prepare_for(Manager *m, InhibitWhat w, bool _active); +#endif // 1 + int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; Session *session; @@ -918,7 +922,9 @@ static int method_release_session(sd_bus_message *message, void *userdata, sd_bu if (r < 0) return r; +#if 1 /// elogind must queue this session session_add_to_gc_queue(session); +#endif // 1 return sd_bus_reply_method_return(message, NULL); } @@ -1621,7 +1627,16 @@ static int execute_shutdown_or_sleep( /* no more pending actions, whether this failed or not */ m->pending_action = HANDLE_IGNORE; - m->action_what = 0; + + /* As elogind can not rely on a systemd manager to call all + * sleeping processes to wake up, we have to tell them all + * by ourselves. */ + if (w == INHIBIT_SLEEP) { + send_prepare_for(m, w, false); + m->action_what = 0; + } else + m->action_what = w; + if (r < 0) return r; #endif // 0 @@ -1664,7 +1679,9 @@ int manager_dispatch_delayed(Manager *manager, bool timeout) { manager->pending_action = HANDLE_IGNORE; manager->action_what = 0; +#if 0 /// It is not a critical error for elogind if suspending fails return r; +#endif // 0 } return 1; @@ -1762,6 +1779,10 @@ int bus_manager_shutdown_or_sleep_now_or_later( m->inhibit_delay_max > 0 && manager_is_inhibited(m, w, INHIBIT_DELAY, NULL, false, false, 0, NULL); + log_debug_elogind("%s called for %s (%sdelayed)", __FUNCTION__, + handle_action_to_string(action), + delayed ? "" : "NOT "); + if (delayed) /* Shutdown is delayed, keep in mind what we * want to do, and start a timeout */ @@ -1858,6 +1879,10 @@ static int method_do_shutdown_or_sleep( if (r < 0) return r; + log_debug_elogind("%s called with action '%s', sleep '%s' (%sinteractive)", + __FUNCTION__, action, sleep_verb, + interactive ? "" : "NOT "); + /* Don't allow multiple jobs being executed at the same time */ if (m->action_what) return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, "There's already a shutdown or sleep operation in progress"); @@ -1873,6 +1898,7 @@ static int method_do_shutdown_or_sleep( r = verify_shutdown_creds(m, message, w, interactive, action, action_multiple_sessions, action_ignore_inhibit, error); + log_debug_elogind("verify_shutdown_creds() returned %d", r); if (r != 0) return r; @@ -1886,6 +1912,8 @@ static int method_do_shutdown_or_sleep( static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; + log_debug_elogind("%s called", __FUNCTION__); + return method_do_shutdown_or_sleep( m, message, HANDLE_POWEROFF, @@ -1900,6 +1928,8 @@ static int method_poweroff(sd_bus_message *message, void *userdata, sd_bus_error static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; + log_debug_elogind("%s called", __FUNCTION__); + return method_do_shutdown_or_sleep( m, message, HANDLE_REBOOT, @@ -1914,6 +1944,8 @@ static int method_reboot(sd_bus_message *message, void *userdata, sd_bus_error * static int method_suspend(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; + log_debug_elogind("%s called", __FUNCTION__); + return method_do_shutdown_or_sleep( m, message, HANDLE_SUSPEND, @@ -2041,6 +2073,8 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ assert(m); assert(message); + log_debug_elogind("%s called", __FUNCTION__); + r = sd_bus_message_read(message, "st", &type, &elapse); if (r < 0) return r; @@ -2139,10 +2173,15 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; bool cancelled; +#if 1 /// elogind needs to construct the message to allow extra wall messages + _cleanup_free_ char *l = NULL; +#endif // 1 assert(m); assert(message); + log_debug_elogind("%s called", __FUNCTION__); + cancelled = m->scheduled_shutdown_type != NULL; reset_scheduled_shutdown(m); @@ -2158,8 +2197,20 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd (void) sd_bus_creds_get_tty(creds, &tty); } +#if 0 /// elogind wants to allow extra cancellation messages utmp_wall("The system shutdown has been cancelled", uid_to_name(uid), tty, logind_wall_tty_filter, m); +#else + r = asprintf(&l, "%s%sThe system shutdown has been cancelled!", + strempty(m->wall_message), + isempty(m->wall_message) ? "" : "\n"); + if (r < 0) { + log_oom(); + return 0; + } + + utmp_wall(l, uid_to_name(uid), tty, logind_wall_tty_filter, m); +#endif // 0 } return sd_bus_reply_method_return(message, "b", cancelled); @@ -2168,6 +2219,8 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd static int method_hibernate(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; + log_debug_elogind("%s called", __FUNCTION__); + return method_do_shutdown_or_sleep( m, message, HANDLE_HIBERNATE, @@ -2182,6 +2235,8 @@ static int method_hibernate(sd_bus_message *message, void *userdata, sd_bus_erro static int method_hybrid_sleep(sd_bus_message *message, void *userdata, sd_bus_error *error) { Manager *m = userdata; + log_debug_elogind("%s called", __FUNCTION__); + return method_do_shutdown_or_sleep( m, message, HANDLE_HYBRID_SLEEP,