chiark / gitweb /
Prep v231.2: Really set an extra wall message (if any) and display it when cancelling...
[elogind.git] / src / login / logind-dbus.c
index 3ad24b1fee20a31c0f8e44a62da9cda53eae991a..9001fbc3597514904053e1f5ec0a674d96baf6b4 100644 (file)
@@ -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"
 #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,9 +1627,17 @@ static int execute_shutdown_or_sleep(
 
         /* 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 */
@@ -2139,6 +2153,9 @@ 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);
@@ -2158,8 +2175,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);