From 28fef5effa5e005ff9c95010b6d82fba36cb1702 Mon Sep 17 00:00:00 2001 From: tobhe Date: Mon, 8 Apr 2024 13:18:54 +0000 Subject: [PATCH] Call daemon() only in parent and before proc_exec() to avoid orphaning child processes. Synced from relayd. ok florian@ --- usr.sbin/snmpd/proc.c | 5 ++++- usr.sbin/snmpd/snmpd.c | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/usr.sbin/snmpd/proc.c b/usr.sbin/snmpd/proc.c index 941857b7124..61355cdb59d 100644 --- a/usr.sbin/snmpd/proc.c +++ b/usr.sbin/snmpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.30 2024/01/16 13:33:12 claudio Exp $ */ +/* $OpenBSD: proc.c,v 1.31 2024/04/08 13:18:54 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(0, 0) == -1) + fatal("failed to daemonize"); + /* * Create the children sockets so we can use them * to distribute the rest of the socketpair()s using diff --git a/usr.sbin/snmpd/snmpd.c b/usr.sbin/snmpd/snmpd.c index d3ecfd6f027..c48b2a959d6 100644 --- a/usr.sbin/snmpd/snmpd.c +++ b/usr.sbin/snmpd/snmpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.c,v 1.50 2023/12/22 13:04:30 martijn Exp $ */ +/* $OpenBSD: snmpd.c,v 1.51 2024/04/08 13:18:54 tobhe Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter @@ -222,8 +222,6 @@ main(int argc, char *argv[]) env->sc_engine_boots = 0; proc_init(ps, procs, nitems(procs), debug, argc0, argv0, proc_id); - if (!debug && daemon(0, 0) == -1) - err(1, "failed to daemonize"); log_procinit("parent"); log_info("startup"); -- 2.20.1