From: tobhe Date: Mon, 8 Apr 2024 12:45:18 +0000 (+0000) Subject: Call daemon() only in parent and before proc_exec() to avoid orphaning child X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4c131d564adf044b93f7799413ffca8765a6d798;p=openbsd Call daemon() only in parent and before proc_exec() to avoid orphaning child processes. Synced from relayd. ok kn@ --- diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c index af863cf2710..686f41c88d0 100644 --- a/usr.sbin/httpd/httpd.c +++ b/usr.sbin/httpd/httpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.c,v 1.73 2022/09/02 07:38:14 benno Exp $ */ +/* $OpenBSD: httpd.c,v 1.74 2024/04/08 12:45:18 tobhe Exp $ */ /* * Copyright (c) 2014 Reyk Floeter @@ -220,8 +220,6 @@ main(int argc, char *argv[]) proc_init(ps, procs, nitems(procs), debug, argc0, argv, proc_id); log_procinit("parent"); - if (!debug && daemon(1, 0) == -1) - err(1, "failed to daemonize"); if (ps->ps_noaction == 0) log_info("startup"); diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c index e8b08dd2317..58ea14cc09b 100644 --- a/usr.sbin/httpd/proc.c +++ b/usr.sbin/httpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.43 2024/01/17 08:22:40 claudio Exp $ */ +/* $OpenBSD: proc.c,v 1.44 2024/04/08 12:45:18 tobhe Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -205,6 +205,9 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, privsep_process = PROC_PARENT; proc_setup(ps, procs, nproc); + if (!debug && daemon(1, 0) == -1) + fatal("failed to daemonize"); + /* * Create the children sockets so we can use them * to distribute the rest of the socketpair()s using