diff options
author | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2024-07-01 03:48:58 +0000 |
---|---|---|
committer | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2024-07-01 03:48:58 +0000 |
commit | 5406dbb585b72f5239b080f25499a9e5c8ab14bb (patch) | |
tree | 1a49bce10aab6d41542977ca187d895a6ba60a4e /usr.sbin/radiusd | |
parent | 2183e3373250941aa4d99b693d3b59080b1f2915 (diff) |
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().
Diffstat (limited to 'usr.sbin/radiusd')
-rw-r--r-- | usr.sbin/radiusd/radiusd.c | 24 |
1 files changed, 22 insertions, 2 deletions
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 <imsg.h> #include <md5.h> #include <netdb.h> +#include <paths.h> #include <pwd.h> #include <signal.h> #include <stdbool.h> @@ -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); + } +} |