On Sat, Jan 23, 2016 at 08:48:22PM +0100, Reyk Floeter wrote:
> On Sat, Jan 23, 2016 at 12:39:19PM -0600, Brent Cook wrote:
> > I'm going with this instead. That way it works like the manual
> > specifies already (-v enables logging debug messages)
> >
>
> Yes, the -v flag is better, but see below.
>
> > cvs server: Diffing .
> > Index: ntpd.c
> > ===================================================================
> > RCS file: /cvs/src/usr.sbin/ntpd/ntpd.c,v
> > retrieving revision 1.103
> > diff -u -p -r1.103 ntpd.c
> > --- ntpd.c 11 Jan 2016 15:30:56 -0000 1.103
> > +++ ntpd.c 23 Jan 2016 18:36:52 -0000
> > @@ -138,7 +138,7 @@ main(int argc, char *argv[])
> > switch (ch) {
> > case 'd':
> > lconf.debug = 1;
> > - log_verbose(1);
> > + log_verbose(2);
>
> This will get overridden by the various log_init() calls later.
>
> You should better set a "verbose" variable in the switch statements
> and call log_verbose() after the various log_init() calls later
> (ntpd's puristic privsep has to call it in various places).
>
> log_init(..)
> log_verbose(verbose)
>
> Splitting log_init() and log_verbose() allowed us to change the
> verbose flag during runtime; for example "relayctl verbose" allows to
> toggle the flag and calls log_verbose() internally. Maybe ntpctl is
> too minimalistic for it, but I would prefer if ntpd could follow the
> same/similar semantics in its main().
>
How's this? It makes the logic look just like relayd. This was a good
exercise, because I found a nice bug while trying to exercise the
log_debug messages. ok?
Index: ntpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/ntpd.h,v
retrieving revision 1.127
diff -u -p -r1.127 ntpd.h
--- ntpd.h 19 Dec 2015 20:44:35 -0000 1.127
+++ ntpd.h 24 Jan 2016 19:07:25 -0000
@@ -213,9 +213,10 @@ struct ntpd_conf {
struct ntp_status status;
struct ntp_freq freq;
u_int32_t scale;
+ int debug;
+ int verbose;
u_int8_t listen_all;
u_int8_t settime;
- u_int8_t debug;
u_int8_t noaction;
u_int8_t filters;
time_t constraint_last;
Index: ntpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/ntpd.c,v
retrieving revision 1.103
diff -u -p -r1.103 ntpd.c
--- ntpd.c 11 Jan 2016 15:30:56 -0000 1.103
+++ ntpd.c 24 Jan 2016 19:07:25 -0000
@@ -132,18 +132,16 @@ main(int argc, char *argv[])
memset(&lconf, 0, sizeof(lconf));
- log_init(1, LOG_DAEMON); /* log to stderr until daemonized */
-
while ((ch = getopt(argc, argv, "df:nsSv")) != -1) {
switch (ch) {
case 'd':
- lconf.debug = 1;
- log_verbose(1);
+ lconf.debug = 2;
break;
case 'f':
conffile = optarg;
break;
case 'n':
+ lconf.debug = 2;
lconf.noaction = 1;
break;
case 's':
@@ -153,7 +151,7 @@ main(int argc, char *argv[])
lconf.settime = 0;
break;
case 'v':
- log_verbose(1);
+ lconf.verbose++;
break;
default:
usage();
@@ -161,6 +159,9 @@ main(int argc, char *argv[])
}
}
+ /* log to stderr until daemonized */
+ log_init(lconf.debug ? lconf.debug : 1, LOG_DAEMON);
+
argc -= optind;
argv += optind;
if (argc > 0)
@@ -190,6 +191,7 @@ main(int argc, char *argv[])
reset_adjtime();
if (!lconf.settime) {
log_init(lconf.debug, LOG_DAEMON);
+ log_verbose(lconf.verbose);
if (!lconf.debug)
if (daemon(1, 0))
fatal("daemon");
@@ -269,6 +271,7 @@ main(int argc, char *argv[])
lconf.settime = 0;
timeout = INFTIM;
log_init(lconf.debug, LOG_DAEMON);
+ log_verbose(lconf.verbose);
log_warnx("no reply received in time, skipping initial "
"time setting");
if (!lconf.debug)
@@ -395,6 +398,7 @@ dispatch_imsg(struct ntpd_conf *lconf, c
if (!lconf->settime)
break;
log_init(lconf->debug, LOG_DAEMON);
+ log_verbose(lconf->verbose);
memcpy(&d, imsg.data, sizeof(d));
ntpd_settime(d);
/* daemonize now */