From: Roy Marples Date: Mon, 29 Jun 2020 12:14:21 +0000 (+0100) Subject: privsep: check return of freopen(3) X-Git-Tag: v9.1.3~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9593df81abd6b0508eafad0d45aa6c0e112922ba;p=thirdparty%2Fdhcpcd.git privsep: check return of freopen(3) So shutup some compilers who complain we don't do anything with it. --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index a7324a57..e917b6c4 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -370,15 +370,15 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) 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 @@ printpidfile: } 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); diff --git a/src/privsep.c b/src/privsep.c index 5bbc4863..34e00a40 100644 --- a/src/privsep.c +++ b/src/privsep.c @@ -368,8 +368,9 @@ ps_dostart(struct dhcpcd_ctx *ctx, 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)