diff options
Diffstat (limited to 'usr.sbin/snmpd')
-rw-r--r-- | usr.sbin/snmpd/control.c | 4 | ||||
-rw-r--r-- | usr.sbin/snmpd/log.c | 17 | ||||
-rw-r--r-- | usr.sbin/snmpd/proc.c | 4 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpd.c | 5 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpd.h | 8 | ||||
-rw-r--r-- | usr.sbin/snmpd/traphandler.c | 12 | ||||
-rw-r--r-- | usr.sbin/snmpd/util.c | 10 |
7 files changed, 35 insertions, 25 deletions
diff --git a/usr.sbin/snmpd/control.c b/usr.sbin/snmpd/control.c index 833d2be7725..a4d04dc835e 100644 --- a/usr.sbin/snmpd/control.c +++ b/usr.sbin/snmpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.40 2016/11/18 16:16:39 jca Exp $ */ +/* $OpenBSD: control.c,v 1.41 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> @@ -331,7 +331,7 @@ control_dispatch_imsg(int fd, short event, void *arg) return control_close(c, "invalid size", &imsg); memcpy(&v, imsg.data, sizeof(v)); - log_verbose(v); + log_setverbose(v); for (i = 0; i < PROC_MAX; i++) { if (privsep_process == PROC_CONTROL) diff --git a/usr.sbin/snmpd/log.c b/usr.sbin/snmpd/log.c index 5c105f81686..92e2c876e1f 100644 --- a/usr.sbin/snmpd/log.c +++ b/usr.sbin/snmpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.14 2017/01/08 20:31:03 reyk Exp $ */ +/* $OpenBSD: log.c,v 1.15 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -24,13 +24,14 @@ #include <errno.h> #include <time.h> -int debug; -int verbose; +static int debug; +static int verbose; const char *log_procname; void log_init(int, int); void log_procinit(const char *); -void log_verbose(int); +void log_setverbose(int); +int log_getverbose(void); void log_warn(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_warnx(const char *, ...) @@ -71,11 +72,17 @@ log_procinit(const char *procname) } void -log_verbose(int v) +log_setverbose(int v) { verbose = v; } +int +log_getverbose(void) +{ + return (verbose); +} + void logit(int pri, const char *fmt, ...) { diff --git a/usr.sbin/snmpd/proc.c b/usr.sbin/snmpd/proc.c index b2f3a65044d..cd5b7606163 100644 --- a/usr.sbin/snmpd/proc.c +++ b/usr.sbin/snmpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.21 2016/10/28 09:07:08 rzalamena Exp $ */ +/* $OpenBSD: proc.c,v 1.22 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org> @@ -662,7 +662,7 @@ proc_dispatch(int fd, short event, void *arg) case IMSG_CTL_VERBOSE: IMSG_SIZE_CHECK(&imsg, &verbose); memcpy(&verbose, imsg.data, sizeof(verbose)); - log_verbose(verbose); + log_setverbose(verbose); break; case IMSG_CTL_PROCFD: IMSG_SIZE_CHECK(&imsg, &pf); diff --git a/usr.sbin/snmpd/snmpd.c b/usr.sbin/snmpd/snmpd.c index d80338698ee..96caeeacf67 100644 --- a/usr.sbin/snmpd/snmpd.c +++ b/usr.sbin/snmpd/snmpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.c,v 1.34 2016/10/28 09:07:08 rzalamena Exp $ */ +/* $OpenBSD: snmpd.c,v 1.35 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -158,6 +158,7 @@ main(int argc, char *argv[]) switch (c) { case 'd': debug++; + flags |= SNMPD_F_DEBUG; break; case 'D': if (cmdline_symset(optarg) < 0) @@ -221,7 +222,7 @@ main(int argc, char *argv[]) errx(1, "unknown user %s", SNMPD_USER); log_init(debug, LOG_DAEMON); - log_verbose(verbose); + log_setverbose(verbose); gettimeofday(&env->sc_starttime, NULL); env->sc_engine_boots = 0; diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h index 46782c3f46d..471f1f1bc44 100644 --- a/usr.sbin/snmpd/snmpd.h +++ b/usr.sbin/snmpd/snmpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.h,v 1.73 2016/11/18 16:16:39 jca Exp $ */ +/* $OpenBSD: snmpd.h,v 1.74 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -560,7 +560,8 @@ struct usmuser { struct snmpd { u_int8_t sc_flags; #define SNMPD_F_VERBOSE 0x01 -#define SNMPD_F_NONAMES 0x02 +#define SNMPD_F_DEBUG 0x02 +#define SNMPD_F_NONAMES 0x04 const char *sc_confpath; struct addresslist sc_addresses; @@ -617,7 +618,8 @@ int cmdline_symset(char *); /* log.c */ void log_init(int, int); void log_procinit(const char *); -void log_verbose(int); +void log_setverbose(int); +int log_getverbose(void); void log_warn(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_warnx(const char *, ...) diff --git a/usr.sbin/snmpd/traphandler.c b/usr.sbin/snmpd/traphandler.c index 76f48bfa031..e76ceb1ceac 100644 --- a/usr.sbin/snmpd/traphandler.c +++ b/usr.sbin/snmpd/traphandler.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traphandler.c,v 1.7 2016/11/18 16:16:39 jca Exp $ */ +/* $OpenBSD: traphandler.c,v 1.8 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2014 Bret Stephen Lambert <blambert@openbsd.org> @@ -294,6 +294,8 @@ traphandler_priv_recvmsg(struct privsep_proc *p, struct imsg *imsg) int traphandler_fork_handler(struct privsep_proc *p, struct imsg *imsg) { + struct privsep *ps = p->p_ps; + struct snmpd *env = ps->ps_env; char oidbuf[SNMP_MAX_OID_STRLEN]; struct sockaddr *sa; char *buf; @@ -303,9 +305,10 @@ traphandler_fork_handler(struct privsep_proc *p, struct imsg *imsg) struct ber_oid trapoid; u_int uptime; struct passwd *pw; - extern int debug; + int verbose; - pw = p->p_ps->ps_pw; + pw = ps->ps_pw; + verbose = log_getverbose(); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || @@ -314,7 +317,8 @@ traphandler_fork_handler(struct privsep_proc *p, struct imsg *imsg) closefrom(STDERR_FILENO + 1); - log_init(debug, LOG_DAEMON); + log_init((env->sc_flags & SNMPD_F_DEBUG) ? 1 : 0, LOG_DAEMON); + log_setverbose(verbose); log_procinit(p->p_title); n = IMSG_DATA_SIZE(imsg); diff --git a/usr.sbin/snmpd/util.c b/usr.sbin/snmpd/util.c index 288cac3a840..d6965b11d39 100644 --- a/usr.sbin/snmpd/util.c +++ b/usr.sbin/snmpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.6 2016/11/09 20:31:56 jca Exp $ */ +/* $OpenBSD: util.c,v 1.7 2017/01/09 14:49:22 reyk Exp $ */ /* * Copyright (c) 2014 Bret Stephen Lambert <blambert@openbsd.org> * @@ -30,10 +30,6 @@ #include "snmp.h" #include "snmpd.h" -/* log.c */ -extern int debug; -extern int verbose; - /* * Convert variable bindings from AgentX to SNMP dialect. */ @@ -283,7 +279,7 @@ print_debug(const char *emsg, ...) { va_list ap; - if (debug && verbose > 2) { + if (log_getverbose() > 2) { va_start(ap, emsg); vfprintf(stderr, emsg, ap); va_end(ap); @@ -295,7 +291,7 @@ print_verbose(const char *emsg, ...) { va_list ap; - if (verbose) { + if (log_getverbose()) { va_start(ap, emsg); vfprintf(stderr, emsg, ap); va_end(ap); |