X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Flogind-dbus.c;h=cb67c668fa9982d262ab68ecf361017b8cc7bcab;hp=44fe5e507937acb72c11ed6309267ab66b6faf72;hb=8966408042e1b5b941bc1d52688198c0d63c06f3;hpb=8331cb6e143dc261fd22af9a2a679196822326a9 diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 44fe5e507..cb67c668f 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -41,14 +41,21 @@ #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" #include "udev-util.h" #include "unit-name.h" #include "user-util.h" -//#include "utmp-wtmp.h" +#include "utmp-wtmp.h" + +/// 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; @@ -915,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); } @@ -1548,6 +1557,9 @@ static int execute_shutdown_or_sleep( _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; char *c = NULL; const char *p; +#else + /* needed for update-utmp */ + char** argv_utmp = NULL; #endif // 0 int r; @@ -1588,13 +1600,44 @@ static int execute_shutdown_or_sleep( m->action_what = w; } #else + if (IN_SET(action, HANDLE_HALT, HANDLE_POWEROFF, HANDLE_REBOOT)) { + + /* As we have no systemd update-utmp daemon running, we have to + * set the relevant utmp/wtmp entries ourselves. + */ + + if (strv_extend(&argv_utmp, "elogind") < 0) + return log_oom(); + + if (HANDLE_REBOOT == action) { + if (strv_extend(&argv_utmp, "reboot") < 0) + return log_oom(); + } else { + if (strv_extend(&argv_utmp, "shutdown") < 0) + return log_oom(); + } + + /* This comes from our patched update-utmp/update-utmp.c */ + update_utmp(2, argv_utmp, m->bus); + strv_free(argv_utmp); + } + + /* Now perform the requested action */ r = shutdown_or_sleep(m, action); /* no more pending actions, whether this failed or not */ m->pending_action = HANDLE_IGNORE; - m->action_what = 0; if (r < 0) return r; + + /* 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; #endif // 0 /* Make sure the lid switch is ignored for a while */ @@ -2093,11 +2136,9 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_ } } -#if 0 /// elogind does not support utmp-wtmp r = manager_setup_wall_message_timer(m); if (r < 0) return r; -#endif // 0 if (!isempty(type)) { r = update_schedule_file(m); @@ -2119,7 +2160,6 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd cancelled = m->scheduled_shutdown_type != NULL; reset_scheduled_shutdown(m); -#if 0 /// elogind does not support utmp-wtmp if (cancelled) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; const char *tty = NULL; @@ -2135,7 +2175,6 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd utmp_wall("The system shutdown has been cancelled", uid_to_name(uid), tty, logind_wall_tty_filter, m); } -#endif // 0 return sd_bus_reply_method_return(message, "b", cancelled); } @@ -2346,7 +2385,7 @@ static int property_get_reboot_to_firmware_setup( return sd_bus_message_append(reply, "b", r > 0); #else - return sd_bus_message_append(reply, "b", -EOPNOTSUPP); + return sd_bus_message_append(reply, "b", false); #endif // 0 } @@ -2426,7 +2465,7 @@ static int method_can_reboot_to_firmware_setup( return sd_bus_reply_method_return(message, "s", result); #else - return sd_bus_reply_method_return(message, "s", "na"); + return sd_bus_reply_method_return(message, "s", "no"); #endif // 0 }