chiark / gitweb /
Prep v231.2: elogind is a stand-alone daemon, so do not exit if suspending the system...
[elogind.git] / src / login / logind-dbus.c
index cb67c668fa9982d262ab68ecf361017b8cc7bcab..387b824f78abd8a56291052ba53bf7bfb6d22ba6 100644 (file)
@@ -1627,8 +1627,6 @@ static int execute_shutdown_or_sleep(
 
         /* no more pending actions, whether this failed or not */
         m->pending_action = HANDLE_IGNORE;
-        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
@@ -1638,6 +1636,9 @@ static int execute_shutdown_or_sleep(
                 m->action_what = 0;
         } else
                 m->action_what = w;
+
+        if (r < 0)
+                return r;
 #endif // 0
 
         /* Make sure the lid switch is ignored for a while */
@@ -1678,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;
@@ -1776,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 */
@@ -1872,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");
@@ -1887,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;
 
@@ -1900,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,
@@ -1914,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,
@@ -1928,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,
@@ -2055,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;
@@ -2153,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);
 
@@ -2172,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);
@@ -2182,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,
@@ -2196,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,