chiark / gitweb /
Prep v239: Add support for the new 'suspend-then-hibernate' method.
[elogind.git] / src / login / elogind-dbus.c
index b1384874a066795b8a5401d02d3a7bfd951877de..bed5281458ff93d5d7f564c6affba90790eae257 100644 (file)
 ***/
 
 
-#include "bus-common-errors.h"
-#include "bus-error.h"
-#include "bus-util.h"
 #include "elogind-dbus.h"
-#include "fd-util.h"
 #include "process-util.h"
 #include "sd-messages.h"
 #include "sleep.h"
-#include "sleep-config.h"
 #include "string-util.h"
 #include "strv.h"
 #include "update-utmp.h"
-#include "user-util.h"
 
 
 static int bus_manager_log_shutdown(
@@ -81,23 +75,21 @@ static int bus_manager_log_shutdown(
 
 /* elogind specific helper to make HALT and REBOOT possible. */
 static int run_helper(const char *helper) {
-        pid_t pid = 0;
         int   r   = 0;
 
-        r = safe_fork_full(helper, NULL, 0, FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_WAIT, &pid);
+        r = safe_fork_full(helper, NULL, 0, FORK_RESET_SIGNALS|FORK_REOPEN_LOG, NULL);
 
         if (r < 0)
                 return log_error_errno(errno, "Failed to fork run %s: %m", helper);
 
-        if (pid == 0) {
+        if (0 == r) {
                 /* Child */
-
                 execlp(helper, helper, NULL);
                 log_error_errno(errno, "Failed to execute %s: %m", helper);
                 _exit(EXIT_FAILURE);
         }
 
-        return r;
+        return 0;
 }
 
 /* elogind specific executor */
@@ -115,11 +107,13 @@ static int shutdown_or_sleep(Manager *m, HandleAction action) {
         case HANDLE_KEXEC:
                 return run_helper(KEXEC);
         case HANDLE_SUSPEND:
-                return do_sleep("suspend", m->suspend_mode, m->suspend_state);
+                return do_sleep(m, "suspend");
         case HANDLE_HIBERNATE:
-                return do_sleep("hibernate", m->hibernate_mode, m->hibernate_state);
+                return do_sleep(m, "hibernate");
         case HANDLE_HYBRID_SLEEP:
-                return do_sleep("hybrid-sleep", m->hybrid_sleep_mode, m->hybrid_sleep_state);
+                return do_sleep(m, "hybrid-sleep");
+        case HANDLE_SUSPEND_THEN_HIBERNATE:
+                return do_sleep(m, "suspend-then-hibernate");
         default:
                 return -EINVAL;
         }
@@ -158,7 +152,7 @@ int execute_shutdown_or_sleep(
                 }
 
                  /* This comes from our patched update-utmp/update-utmp.c */
-                update_utmp(2, argv_utmp, m->bus);
+                update_utmp(2, argv_utmp);
                 strv_free(argv_utmp);
         }