]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
logging: Always log to syslog(3).
authorRoy Marples <roy@marples.name>
Wed, 22 Jan 2020 12:00:10 +0000 (12:00 +0000)
committerRoy Marples <roy@marples.name>
Wed, 22 Jan 2020 12:00:10 +0000 (12:00 +0000)
--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 :(

src/dhcpcd.8.in
src/dhcpcd.c
src/dhcpcd.conf.5.in
src/logerr.c
src/privsep-root.c
src/privsep-root.h
src/privsep.c

index 9a9978edd1f940a0df7e3e9e4dce511a925e026e..d41bf40a2bf8a34bbb5318175b6b0a39afcbe548 100644 (file)
@@ -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
index f0456ce6b10adcfe434d5bf79ea61e73b3777678..df2aff95e8c84c0c9ff276caa6a6b2056465f9b7 100644 (file)
@@ -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__);
index 8bb71a57f9e71efb19bd98585a5b5b8d9b7128bc..e7988304676874d16a167cee10004d003992374b 100644 (file)
@@ -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
index 9545095b0a685a872696dcd38928db9c590f4121..b33204d9424469d4fa4ec894ac8a752d8601ea54 100644 (file)
@@ -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
index 747852bee6e92372512a99d25225f681db38b466..71b4bebb649950f49f3dae483633b626a3e90913 100644 (file)
@@ -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:
index d7f3148a23c156f262ba03517d81473c1f62f5dd..5a9a0130085eef09db05bca3497a96eeccd58932 100644 (file)
@@ -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 *);
index f0fd444f81afd33d44acf0621d57eca3ad4c88aa..795472950075b92088b2623fffa5f956edc4be14 100644 (file)
@@ -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;
 }