chiark / gitweb /
Prep v238: Uncomment now needed headers and unmask now needed functions in src/login...
authorSven Eden <yamakuzure@gmx.net>
Tue, 5 Jun 2018 17:08:31 +0000 (19:08 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 5 Jun 2018 17:08:54 +0000 (19:08 +0200)
src/login/elogind-dbus.c
src/login/elogind.c
src/login/logind-core.c
src/login/logind.c
src/login/logind.conf.in

index 16b0b7939504561880411a2e74092b9e640dcac3..638376fd73b8eb089d66e6b0dc1fe2b7bd3149ce 100644 (file)
@@ -81,22 +81,23 @@ static int bus_manager_log_shutdown(
 
 /* elogind specific helper to make HALT and REBOOT possible. */
 static int run_helper(const char *helper) {
-        int pid = fork();
-        if (pid < 0) {
-                return log_error_errno(errno, "Failed to fork: %m");
-        }
+        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);
+
+        if (r < 0)
+                return log_error_errno(errno, "Failed to fork run %s: %m", helper);
 
         if (pid == 0) {
                 /* Child */
 
-                close_all_fds(NULL, 0);
-
                 execlp(helper, helper, NULL);
                 log_error_errno(errno, "Failed to execute %s: %m", helper);
                 _exit(EXIT_FAILURE);
         }
 
-        return wait_for_terminate_and_warn(helper, pid, true);
+        return r;
 }
 
 /* elogind specific executor */
index b8ac7d367f6f175f467f24a9643f07b9dff47567..162de3fd91d9c36c9d7837f1e6c0bfd1b2006e23 100644 (file)
@@ -103,30 +103,24 @@ static int elogind_daemonize(void) {
         log_notice("Parent SID     : %5d", getsid(getpid_cached()));
 #endif // ENABLE_DEBUG_ELOGIND
 
-        child = fork();
+        r = safe_fork_full("daemon leader", NULL, 0, FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_WAIT, &child);
 
-        if (child < 0)
-                return log_error_errno(errno, "Failed to fork: %m");
+        if (r < 0)
+                return log_error_errno(errno, "Failed to fork daemon leader: %m");
 
-        if (child) {
-                /* Wait for the child to terminate, so the decoupling
-                 * is guaranteed to succeed.
-                 */
-                r = wait_for_terminate_and_warn("elogind control child", child, true);
-                if (r < 0)
-                        return r;
+        /* safe_fork_full() Has waited for the child to terminate, so we
+         * are safe to return here. The child already has forked off the
+         * daemon itself.
+         */
+        if (child)
                 return child;
-        }
 
 #ifdef ENABLE_DEBUG_ELOGIND
         log_notice("Child PID      : %5d", getpid_cached());
         log_notice("Child SID      : %5d", getsid(getpid_cached()));
 #endif // ENABLE_DEBUG_ELOGIND
 
-        /* The first child has to become a new session leader. */
-        close_all_fds(NULL, 0);
-
-        /* close_all_fds() does not close 0,1,2 */
+        /* safe_fork_full() does not close stdin/stdout/stderr */
         close(0);
         close(1);
         close(2);
@@ -142,16 +136,20 @@ static int elogind_daemonize(void) {
         umask(0022);
 
         /* Now the grandchild, the true daemon, can be created. */
-        grandchild = fork();
+        r = safe_fork_full("daemon leader", NULL, 0, FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS, &grandchild);
 
-        if (grandchild < 0)
-                return log_error_errno(errno, "Failed to double fork: %m");
+        if (r < 0)
+                return log_error_errno(errno, "Failed to fork daemon: %m");
 
         if (grandchild)
                 /* Exit immediately! */
                 return grandchild;
 
-        close_all_fds(NULL, 0);
+        /* safe_fork_full() does not close stdin/stdout/stderr */
+        close(0);
+        close(1);
+        close(2);
+
         umask(0022);
 
 #ifdef ENABLE_DEBUG_ELOGIND
index 559307c15a26e3df97432a0d9fd1cd002f17de5a..53b11340d899b34d67a8adf3bbf4cee956e965e3 100644 (file)
@@ -31,7 +31,7 @@
 #include "fd-util.h"
 #include "logind.h"
 #include "parse-util.h"
-//#include "process-util.h"
+#include "process-util.h"
 #include "strv.h"
 #include "terminal-util.h"
 #include "udev-util.h"
index 481c5e40e58584f55276d0ad0d71843497f407e3..ec407852a8c78b2927c3bcd59b4048a49fc10d19 100644 (file)
@@ -39,7 +39,7 @@
 #include "dirent-util.h"
 #include "fd-util.h"
 #include "format-util.h"
-//#include "fs-util.h"
+#include "fs-util.h"
 #include "logind.h"
 //#include "process-util.h"
 #include "selinux-util.h"
@@ -785,9 +785,9 @@ static int manager_connect_bus(Manager *m) {
                         "/org/freedesktop/systemd1",
                         "org.freedesktop.systemd1.Manager",
                         "Subscribe",
-#endif // 0
                         NULL, NULL,
                         NULL);
+#endif // 0
         if (r < 0)
                 return log_error_errno(r, "Failed to enable subscription: %m");
 
index b1070d10d2a7ef34115c52b91967a60216066741..97b408ad7a14074ee0cf5c16b9adb7e550c225f0 100644 (file)
@@ -12,8 +12,6 @@
 # See logind.conf(5) for details.
 
 [Login]
-#NAutoVTs=6
-#ReserveVT=6
 #KillUserProcesses=@KILL_USER_PROCESSES@
 #KillOnlyUsers=
 #KillExcludeUsers=root
 #InhibitorsMax=8192
 #SessionsMax=8192
 #UserTasksMax=33%
+
+[Sleep]
+#SuspendState=mem standby freeze
+#SuspendMode=
+#HibernateState=disk
+#HibernateMode=platform shutdown
+#HybridSleepState=disk