From: Roy Marples Date: Fri, 30 Oct 2020 15:16:02 +0000 (+0000) Subject: log: Allow logopen to be called without logclose X-Git-Tag: v9.3.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0525d9d351a1ea9f473f850af2ec4f19f811bc7;p=thirdparty%2Fdhcpcd.git 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. --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 169aeec1..9e508a69 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -1426,7 +1426,6 @@ dhcpcd_signal_cb(int sig, void *arg) if (ps_root_logreopen(ctx) == -1) logerr("ps_root_logreopen"); } else { - logclose(); if (logopen(ctx->logfile) == -1) logerr("logopen"); } diff --git a/src/logerr.c b/src/logerr.c index f407b2db..21e933b8 100644 --- a/src/logerr.c +++ b/src/logerr.c @@ -452,6 +452,13 @@ logopen(const char *path) (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); diff --git a/src/logerr.h b/src/logerr.h index baa43362..db1c18b9 100644 --- a/src/logerr.h +++ b/src/logerr.h @@ -102,8 +102,10 @@ void logsetopts(unsigned int); 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 diff --git a/src/privsep-root.c b/src/privsep-root.c index afe9c8f6..70c6cf22 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -562,7 +562,6 @@ ps_root_recvmsgcb(void *arg, struct ps_msghdr *psm, struct msghdr *msg) } break; case PS_LOGREOPEN: - logclose(); err = logopen(ctx->logfile); break; #ifdef AUTH