]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
log: Allow logopen to be called without logclose
authorRoy Marples <roy@marples.name>
Fri, 30 Oct 2020 15:16:02 +0000 (15:16 +0000)
committerRoy Marples <roy@marples.name>
Fri, 30 Oct 2020 15:16:02 +0000 (15:16 +0000)
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.

src/dhcpcd.c
src/logerr.c
src/logerr.h
src/privsep-root.c

index 169aeec100bbd29ccd8076b8b5063660dd630985..9e508a69ad3b0858dd81fed47a046ce8ff02d575 100644 (file)
@@ -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");
                }
index f407b2db588fa95f4bbf8130338522a8f8baf281..21e933b898d391c03a6d422558d1daec0f708507 100644 (file)
@@ -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);
index baa43362e3fe81f7789d751faba097304d153548..db1c18b9b39f4b31df46a995bcbf72ca13d22d05 100644 (file)
@@ -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
index afe9c8f68c3108b6b35aeafc8832ac4d74506cc6..70c6cf22a18b607a47944151990d94202193812b 100644 (file)
@@ -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