Skip to content

Commit

Permalink
Add nosyslog
Browse files Browse the repository at this point in the history
Fixes #472.
  • Loading branch information
rsmarples committed Feb 23, 2025
1 parent 3425b8f commit 572c3e1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/dhcpcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/dhcpcd.conf.5.in
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/if-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2548,6 +2549,14 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
}
break;
#endif
case O_NOSYSLOG:
{
unsigned int logopts = loggetopts();

logopts &= ~LOGERR_LOG;
logsetopts(logopts);
}
break;
default:
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/if-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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[];

Expand Down
5 changes: 4 additions & 1 deletion src/logerr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 572c3e1

Please sign in to comment.