Browse Source

update ntpd log initialization to work like relayd, fix debug log levels

ok reyk@
OPENBSD_5_9
bcook 8 years ago
parent
commit
fade868be3
2 changed files with 13 additions and 8 deletions
  1. +10
    -6
      src/usr.sbin/ntpd/ntpd.c
  2. +3
    -2
      src/usr.sbin/ntpd/ntpd.h

+ 10
- 6
src/usr.sbin/ntpd/ntpd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.c,v 1.103 2016/01/11 15:30:56 deraadt Exp $ */
/* $OpenBSD: ntpd.c,v 1.104 2016/01/27 21:36:25 bcook Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -132,18 +132,16 @@ main(int argc, char *argv[])
memset(&lconf, 0, sizeof(lconf)); memset(&lconf, 0, sizeof(lconf));
log_init(1, LOG_DAEMON); /* log to stderr until daemonized */
while ((ch = getopt(argc, argv, "df:nsSv")) != -1) { while ((ch = getopt(argc, argv, "df:nsSv")) != -1) {
switch (ch) { switch (ch) {
case 'd': case 'd':
lconf.debug = 1;
log_verbose(1);
lconf.debug = 2;
break; break;
case 'f': case 'f':
conffile = optarg; conffile = optarg;
break; break;
case 'n': case 'n':
lconf.debug = 2;
lconf.noaction = 1; lconf.noaction = 1;
break; break;
case 's': case 's':
@ -153,7 +151,7 @@ main(int argc, char *argv[])
lconf.settime = 0; lconf.settime = 0;
break; break;
case 'v': case 'v':
log_verbose(1);
lconf.verbose++;
break; break;
default: default:
usage(); 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; argc -= optind;
argv += optind; argv += optind;
if (argc > 0) if (argc > 0)
@ -190,6 +191,7 @@ main(int argc, char *argv[])
reset_adjtime(); reset_adjtime();
if (!lconf.settime) { if (!lconf.settime) {
log_init(lconf.debug, LOG_DAEMON); log_init(lconf.debug, LOG_DAEMON);
log_verbose(lconf.verbose);
if (!lconf.debug) if (!lconf.debug)
if (daemon(1, 0)) if (daemon(1, 0))
fatal("daemon"); fatal("daemon");
@ -269,6 +271,7 @@ main(int argc, char *argv[])
lconf.settime = 0; lconf.settime = 0;
timeout = INFTIM; timeout = INFTIM;
log_init(lconf.debug, LOG_DAEMON); log_init(lconf.debug, LOG_DAEMON);
log_verbose(lconf.verbose);
log_warnx("no reply received in time, skipping initial " log_warnx("no reply received in time, skipping initial "
"time setting"); "time setting");
if (!lconf.debug) if (!lconf.debug)
@ -395,6 +398,7 @@ dispatch_imsg(struct ntpd_conf *lconf, const char *pw_dir,
if (!lconf->settime) if (!lconf->settime)
break; break;
log_init(lconf->debug, LOG_DAEMON); log_init(lconf->debug, LOG_DAEMON);
log_verbose(lconf->verbose);
memcpy(&d, imsg.data, sizeof(d)); memcpy(&d, imsg.data, sizeof(d));
ntpd_settime(d); ntpd_settime(d);
/* daemonize now */ /* daemonize now */


+ 3
- 2
src/usr.sbin/ntpd/ntpd.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.127 2015/12/19 20:44:35 reyk Exp $ */
/* $OpenBSD: ntpd.h,v 1.128 2016/01/27 21:36:25 bcook Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -213,9 +213,10 @@ struct ntpd_conf {
struct ntp_status status; struct ntp_status status;
struct ntp_freq freq; struct ntp_freq freq;
u_int32_t scale; u_int32_t scale;
int debug;
int verbose;
u_int8_t listen_all; u_int8_t listen_all;
u_int8_t settime; u_int8_t settime;
u_int8_t debug;
u_int8_t noaction; u_int8_t noaction;
u_int8_t filters; u_int8_t filters;
time_t constraint_last; time_t constraint_last;


Loading…
Cancel
Save