chiark / gitweb /
Prep v239: Add support for the new 'suspend-then-hibernate' method.
[elogind.git] / src / login / elogind-dbus.c
index fe580696b694004107f219c154c28a07ff8fd33e..bed5281458ff93d5d7f564c6affba90790eae257 100644 (file)
@@ -75,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 */
@@ -109,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;
         }
@@ -152,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);
         }