From 572c3e1a583138fa60ee56fc689f4fc126e93176 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sun, 23 Feb 2025 20:23:45 +0000 Subject: [PATCH] Add nosyslog Fixes #472. --- src/dhcpcd.c | 3 --- src/dhcpcd.conf.5.in | 6 ++++-- src/if-options.c | 11 ++++++++++- src/if-options.h | 3 ++- src/logerr.c | 5 ++++- src/script.c | 2 +- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 09c3da24..4a2c0184 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -2173,9 +2173,6 @@ main(int argc, char **argv, char **envp) ctx.options &= ~DHCPCD_DAEMONISE; #endif - if (ctx.options & DHCPCD_DEBUG) - logsetopts(logopts | LOGERR_DEBUG); - if (!(ctx.options & (DHCPCD_TEST | DHCPCD_DUMPLEASE))) { printpidfile: /* If we have any other args, we should run as a single dhcpcd diff --git a/src/dhcpcd.conf.5.in b/src/dhcpcd.conf.5.in index a67c68f7..c8a0f62a 100644 --- a/src/dhcpcd.conf.5.in +++ b/src/dhcpcd.conf.5.in @@ -1,6 +1,6 @@ .\" SPDX-License-Identifier: BSD-2-Clause .\" -.\" Copyright (c) 2006-2024 Roy Marples +.\" Copyright (c) 2006-2025 Roy Marples .\" All rights reserved .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd November 1, 2024 +.Dd February 23, 2025 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -576,6 +576,8 @@ Don't solicit or accept IPv6 Router Advertisements. .It Ic nolink Don't receive link messages about carrier status. You should only set this for buggy interface drivers. +.It Ic nosyslog +Disable writing to syslog(3). .It Ic noup Don't bring the interface up when in manager mode. .It Ic option Ar option diff --git a/src/if-options.c b/src/if-options.c index d931c36e..dd05072e 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -174,6 +174,7 @@ const struct option cf_options[] = { {"request_time", required_argument, NULL, O_REQUEST_TIME}, {"fallback_time", required_argument, NULL, O_FALLBACK_TIME}, {"ipv4ll_time", required_argument, NULL, O_IPV4LL_TIME}, + {"nosyslog", no_argument, NULL, O_NOSYSLOG}, {NULL, 0, NULL, '\0'} }; @@ -740,7 +741,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, } break; case 'd': - ifo->options |= DHCPCD_DEBUG; + logsetopts(loggetopts() | LOGERR_DEBUG); break; case 'e': ARG_REQUIRED; @@ -2548,6 +2549,14 @@ invalid_token: } break; #endif + case O_NOSYSLOG: + { + unsigned int logopts = loggetopts(); + + logopts &= ~LOGERR_LOG; + logsetopts(logopts); + } + break; default: return 0; } diff --git a/src/if-options.h b/src/if-options.h index cd02be18..6fa178fc 100644 --- a/src/if-options.h +++ b/src/if-options.h @@ -63,7 +63,7 @@ #define DHCPCD_RTBUILD (1ULL << 2) #define DHCPCD_GATEWAY (1ULL << 3) #define DHCPCD_STATIC (1ULL << 4) -#define DHCPCD_DEBUG (1ULL << 5) +//#define DHCPCD_DEBUG (1ULL << 5) #define DHCPCD_ARP_PERSISTDEFENCE (1ULL << 6) #define DHCPCD_LASTLEASE (1ULL << 7) #define DHCPCD_INFORM (1ULL << 8) @@ -189,6 +189,7 @@ #define O_IPV4LL_TIME O_BASE + 56 #define O_VSIO O_BASE + 57 #define O_VSIO6 O_BASE + 58 +#define O_NOSYSLOG O_BASE + 59 extern const struct option cf_options[]; diff --git a/src/logerr.c b/src/logerr.c index 3e5cd835..7520c56a 100644 --- a/src/logerr.c +++ b/src/logerr.c @@ -427,6 +427,8 @@ logsetopts(unsigned int opts) ctx->log_opts = opts; setlogmask(LOG_UPTO(opts & LOGERR_DEBUG ? LOG_DEBUG : LOG_INFO)); + if (!(ctx->log_opts & LOGERR_LOG)) + closelog(); } #ifdef LOGERR_TAG @@ -463,7 +465,8 @@ logopen(const char *path) if (ctx->log_opts & LOGERR_LOG_PID) opts |= LOG_PID; - openlog(getprogname(), opts, LOGERR_SYSLOG_FACILITY); + if (ctx->log_opts & LOGERR_LOG) + openlog(getprogname(), opts, LOGERR_SYSLOG_FACILITY); if (path == NULL) return 1; diff --git a/src/script.c b/src/script.c index 3ee2eaa4..b06e2141 100644 --- a/src/script.c +++ b/src/script.c @@ -471,7 +471,7 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp, if (efprintf(fp, "af_waiting=%d", af) == -1) goto eexit; } - if (ifo->options & DHCPCD_DEBUG) { + if (loggetopts() & LOGERR_DEBUG) { if (efprintf(fp, "syslog_debug=true") == -1) goto eexit; } -- 2.47.3