From: Roy Marples Date: Wed, 22 Jan 2020 12:00:10 +0000 (+0000) Subject: logging: Always log to syslog(3). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=730ce26da503f523748c7910558fc769131779ac;p=thirdparty%2Fdhcpcd.git logging: Always log to syslog(3). --logfile may not work that well in a chroot on receipt of SIGUSR2 because the path is of course different. Might have to drop this option soon as I have no good ideas on how to resolve it :( --- diff --git a/src/dhcpcd.8.in b/src/dhcpcd.8.in index 9a9978ed..d41bf40a 100644 --- a/src/dhcpcd.8.in +++ b/src/dhcpcd.8.in @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 15, 2020 +.Dd January 22, 2020 .Dt DHCPCD 8 .Os .Sh NAME @@ -357,8 +357,9 @@ Some badly configured DHCP servers reject unknown vendorclassids. To work around it, try and impersonate Windows by using the MSFT vendorclassid. .It Fl j , Fl Fl logfile Ar logfile Writes to the specified -.Ar logfile -rather than +.Ar logfile . +.Nm +still writes to .Xr syslog 3 . The .Ar logfile @@ -837,5 +838,13 @@ RFC\ 6603, RFC\ 6704, RFC\ 7217, RFC\ 7550, RFC\ 7844. .Sh AUTHORS .An Roy Marples Aq Mt roy@marples.name .Sh BUGS +If +.Nm +is running in a +.Xr chroot 2 +then re-opening the +.Fl Fl logfile +from SIGUSR2 may not work. +.Pp Please report them to .Lk http://roy.marples.name/projects/dhcpcd diff --git a/src/dhcpcd.c b/src/dhcpcd.c index f0456ce6..df2aff95 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -345,7 +345,8 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) !(ctx->options & DHCPCD_DAEMONISE)) return; - loginfox("forked to background, child pid %d", getpid()); + /* Don't use loginfo because this makes no sense in a log. */ + fprintf(stderr, "forked to background, child pid %d\n", getpid()); i = EXIT_SUCCESS; if (write(ctx->fork_fd, &i, sizeof(i)) == -1) logerr("write"); @@ -1371,6 +1372,7 @@ dhcpcd_signal_cb(int sig, void *arg) return; case SIGUSR2: loginfox(sigmsg, "SIGUSR2", "reopening log"); + /* XXX This may not work that well in a chroot */ logclose(); if (logopen(ctx->logfile) == -1) logerr(__func__); diff --git a/src/dhcpcd.conf.5.in b/src/dhcpcd.conf.5.in index 8bb71a57..e7988304 100644 --- a/src/dhcpcd.conf.5.in +++ b/src/dhcpcd.conf.5.in @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 15, 2020 +.Dd January 22, 2020 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -458,8 +458,9 @@ will recover from link buffer overflows, this may not be desirable on heavily loaded systems. .It Ic logfile Ar logfile Writes to the specified -.Ar logfile -rather than +.Ar logfile . +.Nm dhcpcd +still writes to .Xr syslog 3 . The .Ar logfile diff --git a/src/logerr.c b/src/logerr.c index 9545095b..b33204d9 100644 --- a/src/logerr.c +++ b/src/logerr.c @@ -207,18 +207,14 @@ vlogmessage(int pri, const char *fmt, va_list args) if (!(ctx->log_opts & LOGERR_LOG)) return len; -#ifdef SMALL +#ifndef SMALL + if (ctx->log_file != NULL && + (pri != LOG_DEBUG || (ctx->log_opts & LOGERR_DEBUG))) + len = vlogprintf_r(ctx, ctx->log_file, fmt, args); +#endif + vsyslog(pri, fmt, args); return len; -#else - if (ctx->log_file == NULL) { - vsyslog(pri, fmt, args); - return len; - } - if (pri == LOG_DEBUG && !(ctx->log_opts & LOGERR_DEBUG)) - return len; - return vlogprintf_r(ctx, ctx->log_file, fmt, args); -#endif } #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)) #pragma GCC diagnostic pop diff --git a/src/privsep-root.c b/src/privsep-root.c index 747852be..71b4bebb 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -206,8 +206,8 @@ ps_root_run_script(struct dhcpcd_ctx *ctx, const void *data, size_t len) #define st_atimespec st_atim #define st_mtimespec st_mtim #endif -static ssize_t -ps_root_docopy(struct dhcpcd_ctx *ctx, const char *file) +ssize_t +ps_root_docopychroot(struct dhcpcd_ctx *ctx, const char *file) { char path[PATH_MAX], buf[BUFSIZ], *slash; @@ -300,7 +300,7 @@ ps_root_dofileop(struct dhcpcd_ctx *ctx, void *data, size_t len, uint8_t op) switch(op) { case PS_COPY: - return ps_root_docopy(ctx, path); + return ps_root_docopychroot(ctx, path); case PS_UNLINK: return (ssize_t)unlink(path); default: diff --git a/src/privsep-root.h b/src/privsep-root.h index d7f3148a..5a9a0130 100644 --- a/src/privsep-root.h +++ b/src/privsep-root.h @@ -35,6 +35,7 @@ pid_t ps_root_start(struct dhcpcd_ctx *ctx); int ps_root_stop(struct dhcpcd_ctx *ctx); ssize_t ps_root_readerror(struct dhcpcd_ctx *); +ssize_t ps_root_docopychroot(struct dhcpcd_ctx *, const char *); ssize_t ps_root_copychroot(struct dhcpcd_ctx *, const char *); ssize_t ps_root_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t); ssize_t ps_root_unlink(struct dhcpcd_ctx *, const char *); diff --git a/src/privsep.c b/src/privsep.c index f0fd444f..79547295 100644 --- a/src/privsep.c +++ b/src/privsep.c @@ -119,6 +119,10 @@ ps_init(struct dhcpcd_ctx *ctx) chmod(path, 0755) == -1) logerr("%s: %s", __func__, path); + /* Ensure we have a localtime to correctly format dates. */ + if (ps_root_docopychroot(ctx, "/etc/localtime") == -1 && errno!=ENOENT) + logerr("%s: %s", __func__, "/etc/localtime"); + ctx->options |= DHCPCD_PRIVSEP; return 0; }