summaryrefslogtreecommitdiffstats
path: root/src/privsep.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-11-29 22:11:46 +0000
committerRoy Marples <roy@marples.name>2019-11-29 22:11:46 +0000
commit3063ebb6c8ac7c96196fa923cdd5f7c0384de23b (patch)
tree2d7280e8b0b12bf39073ec42e3bda342affe0474 /src/privsep.c
parentbb0b9d36b97324630874be5175d9faa42d1df3b9 (diff)
downloaddhcpcd-3063ebb6c8ac7c96196fa923cdd5f7c0384de23b.tar.xz
dhcpcd: Rework daemonisation
Now that we spawn helper processes for priviledge separation, we need to fork() and setssid() much earlier. Infact, pretty much from the get go of starting up. dhcpcd_daemonise now writes to the launcher signal pipe about the result of "daemonisation", even though it's already deamonised at this point. This allows dhcpcd to keep the helper processes running when started by the system init at boot.
Diffstat (limited to 'src/privsep.c')
-rw-r--r--src/privsep.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/privsep.c b/src/privsep.c
index 1ef46873..63d558a1 100644
--- a/src/privsep.c
+++ b/src/privsep.c
@@ -150,10 +150,26 @@ create_sp:
}
ctx->options |= DHCPCD_UNPRIV | DHCPCD_FORKED;
+ if (ctx->fork_fd != -1) {
+ close(ctx->fork_fd);
+ ctx->fork_fd = -1;
+ }
control_close(ctx);
pidfile_clean();
eloop_clear(ctx->eloop);
+ /* We are not root */
+ if (priv_fd != &ctx->ps_root_fd) {
+ ps_freeprocesses(ctx, recv_ctx);
+ close(ctx->ps_root_fd);
+ ctx->ps_root_fd = -1;
+ }
+
+ if (priv_fd != &ctx->ps_inet_fd) {
+ close(ctx->ps_inet_fd);
+ ctx->ps_inet_fd = -1;
+ }
+
if (eloop_signal_set_cb(ctx->eloop,
dhcpcd_signals, dhcpcd_signals_len, signal_cb, ctx) == -1)
{
@@ -171,21 +187,14 @@ create_sp:
goto errexit;
}
- /* We are not root */
- if (priv_fd != &ctx->ps_root_fd) {
- ps_freeprocesses(ctx, recv_ctx);
- close(ctx->ps_root_fd);
- ctx->ps_root_fd = -1;
- }
-
- if (priv_fd != &ctx->ps_inet_fd) {
- close(ctx->ps_inet_fd);
- ctx->ps_inet_fd = -1;
- }
-
if (callback(recv_ctx) == -1)
goto errexit;
+#if 0
+ /* XXX Why does this cause processes to exit? */
+ close_std();
+#endif
+
if (pw == NULL)
return 0;