]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: check return of freopen(3)
authorRoy Marples <roy@marples.name>
Mon, 29 Jun 2020 12:14:21 +0000 (13:14 +0100)
committerRoy Marples <roy@marples.name>
Mon, 29 Jun 2020 12:14:21 +0000 (13:14 +0100)
So shutup some compilers who complain we don't do anything with it.

src/dhcpcd.c
src/privsep.c

index a7324a573ed30b5c3a4c03233d8b49649934cbdb..e917b6c49ca0157d92f898c0c9c10eeb015367f6 100644 (file)
@@ -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);
index 5bbc486318f347651357704bbe1f0dd2b7bf2c33..34e00a402c999b2d8457ffb23faa68ee09b9fdbb 100644 (file)
@@ -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)