From: yasuoka Date: Mon, 1 Jul 2024 03:48:57 +0000 (+0000) Subject: Call daemon(3) before parse_config() since parse_config() of radiusd(8) X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8c9be2452f661d049ba9fef2a4c5a0ca74467417;p=openbsd Call daemon(3) before parse_config() since parse_config() of radiusd(8) starts some sub processes and parent-child relationship with them must be kept. But we want to show config error on stderr, so keep stdio files open and close them after parse_config(). --- diff --git a/usr.sbin/radiusd/radiusd.c b/usr.sbin/radiusd/radiusd.c index b0544ac9d9e..91f4a112c96 100644 --- a/usr.sbin/radiusd/radiusd.c +++ b/usr.sbin/radiusd/radiusd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd.c,v 1.39 2024/07/01 03:31:29 yasuoka Exp $ */ +/* $OpenBSD: radiusd.c,v 1.40 2024/07/01 03:48:57 yasuoka Exp $ */ /* * Copyright (c) 2013, 2023 Internet Initiative Japan Inc. @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -89,6 +90,7 @@ static void radiusd_module_request_decoration( struct radiusd_module *, struct radius_query *); static void radiusd_module_response_decoration( struct radiusd_module *, struct radius_query *); +static void close_stdio(void); static int imsg_compose_radius_packet(struct imsgbuf *, uint32_t, u_int, RADIUS_PACKET *); @@ -144,6 +146,9 @@ main(int argc, char *argv[]) TAILQ_INIT(&radiusd->listen); TAILQ_INIT(&radiusd->query); + if (!noaction && debug == 0) + daemon(0, 1); /* pend closing stdio files */ + if (parse_config(conffile, radiusd) != 0) errx(EXIT_FAILURE, "config error"); log_init(debug); @@ -153,7 +158,8 @@ main(int argc, char *argv[]) } if (debug == 0) - daemon(0, 0); + close_stdio(); /* close stdio files now */ + event_init(); if ((pw = getpwnam(RADIUSD_USER)) == NULL) @@ -1618,3 +1624,17 @@ imsg_compose_radius_packet(struct imsgbuf *ibuf, uint32_t type, u_int q_id, } return (0); } + +static void +close_stdio(void) +{ + int fd; + + if ((fd = open(_PATH_DEVNULL, O_RDWR)) != -1) { + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + if (fd > STDERR_FILENO) + close(fd); + } +}