changeset 5527:071a9ea18363 draft

log: Allow logopen to be called without logclose logclose is meant to free resources. On Linux this means that _log_prog is also free'd and once in the chroot we cannot work it out again. As such allow logopen to close what it needs to so that reopening works.
author Roy Marples <roy@marples.name>
date Fri, 30 Oct 2020 15:16:02 +0000
parents b1a3d9055662
children 274d31419935
files src/dhcpcd.c src/logerr.c src/logerr.h src/privsep-root.c
diffstat 4 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcpcd.c	Fri Oct 30 14:19:16 2020 +0000
+++ b/src/dhcpcd.c	Fri Oct 30 15:16:02 2020 +0000
@@ -1426,7 +1426,6 @@
 			if (ps_root_logreopen(ctx) == -1)
 				logerr("ps_root_logreopen");
 		} else {
-			logclose();
 			if (logopen(ctx->logfile) == -1)
 				logerr("logopen");
 		}
--- a/src/logerr.c	Fri Oct 30 14:19:16 2020 +0000
+++ b/src/logerr.c	Fri Oct 30 15:16:02 2020 +0000
@@ -452,6 +452,13 @@
 
 	(void)setvbuf(stderr, ctx->log_buf, _IOLBF, sizeof(ctx->log_buf));
 
+#ifndef SMALL
+	if (ctx->log_file != NULL) {
+		fclose(ctx->log_file);
+		ctx->log_file = NULL;
+	}
+#endif
+
 	if (ctx->log_opts & LOGERR_LOG_PID)
 		opts |= LOG_PID;
 	openlog(getprogname(), opts, LOGERR_SYSLOG_FACILITY);
--- a/src/logerr.h	Fri Oct 30 14:19:16 2020 +0000
+++ b/src/logerr.h	Fri Oct 30 15:16:02 2020 +0000
@@ -102,8 +102,10 @@
 void logsettag(const char *);
 #endif
 
+/* Can be called more than once. */
 int logopen(const char *);
+
+/* Should only be called at program exit. */
 void logclose(void);
-int logreopen(void);
 
 #endif
--- a/src/privsep-root.c	Fri Oct 30 14:19:16 2020 +0000
+++ b/src/privsep-root.c	Fri Oct 30 15:16:02 2020 +0000
@@ -562,7 +562,6 @@
 		}
 		break;
 	case PS_LOGREOPEN:
-		logclose();
 		err = logopen(ctx->logfile);
 		break;
 #ifdef AUTH