Mercurial > hg > dhcpcd
changeset 5393:ff43b6fbd113 draft
privsep: check return of freopen(3)
So shutup some compilers who complain we don't do anything with it.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 29 Jun 2020 13:14:21 +0100 |
| parents | b6d4660cc8da |
| children | b7f0ddd5d9bd |
| files | src/dhcpcd.c src/privsep.c |
| diffstat | 2 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dhcpcd.c Mon Jun 29 11:54:29 2020 +0100 +++ b/src/dhcpcd.c Mon Jun 29 13:14:21 2020 +0100 @@ -370,15 +370,15 @@ close(ctx->fork_fd); ctx->fork_fd = -1; #ifdef PRIVSEP - if (ctx->options & DHCPCD_PRIVSEP) { - /* Aside from Linux, we don't have access to /dev/null */ + if (IN_PRIVSEP(ctx)) { fclose(stdout); fclose(stderr); } else #endif { - (void)freopen(_PATH_DEVNULL, "w", stdout); - (void)freopen(_PATH_DEVNULL, "w", stderr); + if (freopen(_PATH_DEVNULL, "w", stdout) == NULL || + freopen(_PATH_DEVNULL, "w", stderr) == NULL) + logerr("%s: freopen", __func__); } #endif } @@ -2205,7 +2205,8 @@ } loginfox(PACKAGE "-" VERSION " starting"); - freopen(_PATH_DEVNULL, "r", stdin); + if (freopen(_PATH_DEVNULL, "r", stdin) == NULL) + logerr("%s: freopen", __func__); #ifdef PRIVSEP ps_init(&ctx);
--- a/src/privsep.c Mon Jun 29 11:54:29 2020 +0100 +++ b/src/privsep.c Mon Jun 29 13:14:21 2020 +0100 @@ -368,8 +368,9 @@ if (!(ctx->options & DHCPCD_DEBUG) && (!(ctx->options & DHCPCD_TEST) || loggetopts() & LOGERR_QUIET)) { - (void)freopen(_PATH_DEVNULL, "w", stdout); - (void)freopen(_PATH_DEVNULL, "w", stderr); + if (freopen(_PATH_DEVNULL, "w", stdout) == NULL || + freopen(_PATH_DEVNULL, "w", stderr) == NULL) + logerr("%s: freopen", __func__); } if (flags & PSF_DROPPRIVS)
