summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Eden <yamakuzure@gmx.net>2018-06-05 19:08:31 +0200
committerSven Eden <yamakuzure@gmx.net>2018-06-05 19:08:54 +0200
commit7da69a18714b1010973c89e9c11767789511c785 (patch)
tree948b7f383ade9a5a29bd22fd0aca43d529b99e2e
parent10eaaae37e8445c417f6820907db107194f3fa4f (diff)
Prep v238: Uncomment now needed headers and unmask now needed functions in src/login (4/6)
-rw-r--r--src/login/elogind-dbus.c15
-rw-r--r--src/login/elogind.c36
-rw-r--r--src/login/logind-core.c2
-rw-r--r--src/login/logind.c4
-rw-r--r--src/login/logind.conf.in9
5 files changed, 35 insertions, 31 deletions
diff --git a/src/login/elogind-dbus.c b/src/login/elogind-dbus.c
index 16b0b79..638376f 100644
--- a/src/login/elogind-dbus.c
+++ b/src/login/elogind-dbus.c
@@ -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 */
diff --git a/src/login/elogind.c b/src/login/elogind.c
index b8ac7d3..162de3f 100644
--- a/src/login/elogind.c
+++ b/src/login/elogind.c
@@ -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
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index 559307c..53b1134 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -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"
diff --git a/src/login/logind.c b/src/login/logind.c
index 481c5e4..ec40785 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -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");
diff --git a/src/login/logind.conf.in b/src/login/logind.conf.in
index b1070d1..97b408a 100644
--- a/src/login/logind.conf.in
+++ b/src/login/logind.conf.in
@@ -12,8 +12,6 @@
# See logind.conf(5) for details.
[Login]
-#NAutoVTs=6
-#ReserveVT=6
#KillUserProcesses=@KILL_USER_PROCESSES@
#KillOnlyUsers=
#KillExcludeUsers=root
@@ -36,3 +34,10 @@
#InhibitorsMax=8192
#SessionsMax=8192
#UserTasksMax=33%
+
+[Sleep]
+#SuspendState=mem standby freeze
+#SuspendMode=
+#HibernateState=disk
+#HibernateMode=platform shutdown
+#HybridSleepState=disk