changeset 5394:b7f0ddd5d9bd draft

dhcpcd: Turn off stderr logging rather than closing stderr And only turn it off when stderr is a tty. A better approach might to open an fd just to log to and redirect stdout/stderr to /dev/null alongside stdin at program start, but that's more code.
author Roy Marples <roy@marples.name>
date Tue, 30 Jun 2020 21:33:24 +0100
parents ff43b6fbd113
children 3ed7914080a9
files src/dhcpcd.c
diffstat 1 files changed, 6 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcpcd.c	Mon Jun 29 13:14:21 2020 +0100
+++ b/src/dhcpcd.c	Tue Jun 30 21:33:24 2020 +0100
@@ -339,6 +339,7 @@
 	return 0;
 #else
 	int i;
+	unsigned int logopts = loggetopts();
 
 	if (ctx->options & DHCPCD_DAEMONISE &&
 	    !(ctx->options & (DHCPCD_DAEMONISED | DHCPCD_NOWAITIP)))
@@ -359,7 +360,7 @@
 		return;
 
 	/* Don't use loginfo because this makes no sense in a log. */
-	if (!(loggetopts() & LOGERR_QUIET))
+	if (!(logopts & LOGERR_QUIET))
 		(void)fprintf(stderr, "forked to background, child pid %d\n",
 		    getpid());
 	i = EXIT_SUCCESS;
@@ -369,16 +370,10 @@
 	eloop_event_delete(ctx->eloop, ctx->fork_fd);
 	close(ctx->fork_fd);
 	ctx->fork_fd = -1;
-#ifdef PRIVSEP
-	if (IN_PRIVSEP(ctx)) {
-		fclose(stdout);
-		fclose(stderr);
-	} else
-#endif
-	{
-		if (freopen(_PATH_DEVNULL, "w", stdout) == NULL ||
-		    freopen(_PATH_DEVNULL, "w", stderr) == NULL)
-			logerr("%s: freopen", __func__);
+
+	if (isatty(STDERR_FILENO)) {
+		logopts &= ~LOGERR_ERR;
+		logsetopts(logopts);
 	}
 #endif
 }