From: Dave Hart Date: Sat, 5 Mar 2011 22:35:37 +0000 (+0000) Subject: Use TRACE() instead of DPRINTF() for libntp and utilities, which X-Git-Tag: NTP_4_2_7P137~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81a6a394f92b3a2c089b5e7c5ba24046fb365601;p=thirdparty%2Fntp.git Use TRACE() instead of DPRINTF() for libntp and utilities, which use the "debug" variable regardless of #ifdef DEBUG. Declare debug in libntp instead of each program. Expose extern declaration to utilities, libntp, and DEBUG ntpd. bk: 4d72bab91NmUO24GvCJNOIHx44Kp_Q --- diff --git a/ChangeLog b/ChangeLog index 7a095558a..f169a32b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +* Use TRACE() instead of DPRINTF() for libntp and utilities, which + use the "debug" variable regardless of #ifdef DEBUG. (4.2.7p136) 2011/03/02 Released by Harlan Stenn * [Bug 1839] 4.2.7p135 still installs libevent ev*.h headers. (4.2.7p135) 2011/03/02 Released by Harlan Stenn diff --git a/clockstuff/chutest.c b/clockstuff/chutest.c index e5ec554f9..488a0d16e 100644 --- a/clockstuff/chutest.c +++ b/clockstuff/chutest.c @@ -57,7 +57,6 @@ struct chucode { #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) char *progname; -int debug; int dofilter = 0; /* set to 1 when we should run filter algorithm */ int showtimes = 0; /* set to 1 when we should show char arrival times */ diff --git a/clockstuff/propdelay.c b/clockstuff/propdelay.c index 3a73fb58d..f9303f35f 100644 --- a/clockstuff/propdelay.c +++ b/clockstuff/propdelay.c @@ -118,7 +118,6 @@ int Gflag = 0; int height; char *progname; -volatile int debug; static void doit (double, double, double, double, double, char *); static double latlong (char *, int); diff --git a/include/Makefile.am b/include/Makefile.am index 9294f3f44..a9070b0ea 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -8,6 +8,7 @@ noinst_HEADERS = \ ascii.h \ audio.h \ binio.h \ + declcond.h \ gps.h \ hopf6039.h \ icom.h \ diff --git a/include/declcond.h b/include/declcond.h new file mode 100644 index 000000000..e1c72ac42 --- /dev/null +++ b/include/declcond.h @@ -0,0 +1,17 @@ +/* + * declcond.h - declarations conditionalized for ntpd + * + * The NTP reference implementation distribution includes two distinct + * declcond.h files, one in ntpd/ used only by ntpd, and another in + * include/ used by libntp and utilities. This relies on the source + * file's directory being ahead of include/ in the include search. + * + * The ntpd variant of declcond.h declares "debug" only #ifdef DEBUG, + * as the --disable-debugging version of ntpd should not reference + * "debug". The libntp and utilities variant always declares debug, + * as it is used in those codebases even without DEBUG defined. + */ + +/* #ifdef DEBUG */ /* uncommented in ntpd/declcond.h */ +extern int debug; +/* #endif */ /* uncommented in ntpd/declcond.h */ diff --git a/include/ntp_debug.h b/include/ntp_debug.h index e9e3f0364..b0e846e0b 100644 --- a/include/ntp_debug.h +++ b/include/ntp_debug.h @@ -8,24 +8,20 @@ #ifndef NTP_DEBUG_H #define NTP_DEBUG_H -#include "ntp_assert.h" -#include "ntp_stdlib.h" - /* - * macros for debugging output - cut down on #ifdef pollution in the code + * macro for debugging output - cut down on #ifdef pollution. + * + * TRACE() is similar to ntpd's DPRINTF() for utilities and libntp. + * Uses mprintf() and so supports %m, replaced by strerror(errno). + * + * The calling convention is not attractive: + * TRACE(debuglevel, (fmt, ...)); + * TRACE(2, ("this will appear on stdout if debug >= %d\n", 2)); */ - -#ifdef DEBUG -#define DPRINTF(_lvl_, _arg_) \ +#define TRACE(lvl, arg) \ do { \ - if (debug >= (_lvl_)) \ - mprintf _arg_; \ + if (debug >= (lvl)) \ + mprintf arg; \ } while (0) -#else -#define DPRINTF(_lvl_, _arg_) do {} while (0) -#endif -#endif -/* - * $Log$ - */ +#endif /* NTP_DEBUG_H */ diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index 9c560d49a..c6c6e9593 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -9,10 +9,12 @@ #include #endif +#include "declcond.h" /* ntpd uses ntpd/declcond.h, others include/ */ #include "l_stdlib.h" +#include "ntp_net.h" +#include "ntp_debug.h" #include "ntp_malloc.h" #include "ntp_string.h" -#include "ntp_net.h" #include "ntp_syslog.h" @@ -181,11 +183,6 @@ extern void rereadkeys (void); * Variable declarations for libntp. */ -/* - * Defined by any program. - */ -extern volatile int debug; /* debugging flag */ - /* authkeys.c */ extern u_long authkeynotfound; /* keys not found */ extern u_long authkeylookups; /* calls to lookup keys */ diff --git a/include/ntpd.h b/include/ntpd.h index 7c27c3a52..84930809b 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -23,6 +23,29 @@ * ----------------------------------------- */ +/* + * macro for debugging output - cut down on #ifdef pollution. + * + * DPRINTF() is for use by ntpd only, and compiles away to nothing + * without DEBUG (configure --disable-debugging). + * + * TRACE() is similar for libntp and utilities, which retain full + * debug capability even when compiled without DEBUG. + * + * The calling convention is not attractive: + * DPRINTF(debuglevel, (fmt, ...)); + * DPRINTF(2, ("shows #ifdef DEBUG and if debug >= %d\n", 2)); + */ +#ifdef DEBUG +# define DPRINTF(lvl, arg) \ + do { \ + if (debug >= (lvl)) \ + mprintf arg; \ + } while (0) +#else +# define DPRINTF(lvl, arg) do {} while (0) +#endif + /* nt_clockstuff.c */ #ifdef SYS_WINNT @@ -509,7 +532,6 @@ extern double stats_write_tolerance; extern double wander_threshold; /* ntpd.c */ -extern volatile int debug; /* debugging flag */ extern int nofork; /* no-fork flag */ extern int initializing; /* initializing flag */ #ifdef HAVE_DROPROOT diff --git a/libntp/lib_strbuf.c b/libntp/lib_strbuf.c index 1551b9f69..9ddf5cf50 100644 --- a/libntp/lib_strbuf.c +++ b/libntp/lib_strbuf.c @@ -13,11 +13,12 @@ /* * Storage declarations */ -libbufstr lib_stringbuf[LIB_NUMBUF]; -int lib_nextbuf; -int ipv4_works; -int ipv6_works; -int lib_inited; +int debug; +libbufstr lib_stringbuf[LIB_NUMBUF]; +int lib_nextbuf; +int ipv4_works; +int ipv6_works; +int lib_inited; /* * initialization routine. Might be needed if the code is ROMized. diff --git a/libntp/machines.c b/libntp/machines.c index 9ff8d61e7..96ffaffa1 100644 --- a/libntp/machines.c +++ b/libntp/machines.c @@ -436,7 +436,7 @@ ntp_set_tod( int rc; int saved_errno; - DPRINTF(1, ("In ntp_set_tod\n")); + TRACE(1, ("In ntp_set_tod\n")); rc = -1; saved_errno = 0; @@ -451,7 +451,7 @@ ntp_set_tod( errno = 0; rc = clock_settime(CLOCK_REALTIME, &ts); saved_errno = errno; - DPRINTF(1, ("ntp_set_tod: clock_settime: %d %m\n", rc)); + TRACE(1, ("ntp_set_tod: clock_settime: %d %m\n", rc)); if (!tod && !rc) tod = SET_TOD_CLOCK_SETTIME; @@ -470,7 +470,7 @@ ntp_set_tod( errno = 0; rc = SETTIMEOFDAY(tvp, tzp); saved_errno = errno; - DPRINTF(1, ("ntp_set_tod: settimeofday: %d %m\n", rc)); + TRACE(1, ("ntp_set_tod: settimeofday: %d %m\n", rc)); if (!tod && !rc) tod = SET_TOD_SETTIMEOFDAY; } @@ -482,15 +482,15 @@ ntp_set_tod( errno = 0; rc = stime(&tp); /* lie as bad as SysVR4 */ saved_errno = errno; - DPRINTF(1, ("ntp_set_tod: stime: %d %m\n", rc)); + TRACE(1, ("ntp_set_tod: stime: %d %m\n", rc)); if (!tod && !rc) tod = SET_TOD_STIME; } #endif /* HAVE_STIME */ errno = saved_errno; /* for %m below */ - DPRINTF(1, ("ntp_set_tod: Final result: %s: %d %m\n", - set_tod_used[tod], rc)); + TRACE(1, ("ntp_set_tod: Final result: %s: %d %m\n", + set_tod_used[tod], rc)); /* * Say how we're setting the time of day */ diff --git a/libntp/msyslog.c b/libntp/msyslog.c index 67f7acd20..c0114fb1d 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -471,7 +471,7 @@ change_logfile( } else #endif abs_fname = estrdup(log_fname); - DPRINTF(1, ("attempting to open log %s\n", abs_fname)); + TRACE(1, ("attempting to open log %s\n", abs_fname)); new_file = fopen(abs_fname, "a"); } diff --git a/libntp/ntp_intres.c b/libntp/ntp_intres.c index 1c7cf5562..1cedfe450 100644 --- a/libntp/ntp_intres.c +++ b/libntp/ntp_intres.c @@ -341,9 +341,9 @@ blocking_getaddrinfo( resp = emalloc_zero(resp_octets); gai_resp = (void *)(resp + 1); - DPRINTF(2, ("blocking_getaddrinfo given node %s serv %s fam %d flags %x\n", - node, service, gai_req->hints.ai_family, - gai_req->hints.ai_flags)); + TRACE(2, ("blocking_getaddrinfo given node %s serv %s fam %d flags %x\n", + node, service, gai_req->hints.ai_family, + gai_req->hints.ai_flags)); #ifdef DEBUG if (debug >= 2) fflush(stdout); @@ -376,12 +376,8 @@ blocking_getaddrinfo( if (gai_resp->retry > INITIAL_DNS_RETRY) { time_now = time(NULL); worker_ctx->ignore_scheduled_before = time_now; - DPRINTF(1, ("DNS success after retry, ignoring sleeps scheduled before now (%s)", - humantime(time_now))); -#ifdef DEBUG - if (debug >= 1) - fflush(stdout); -#endif + TRACE(1, ("DNS success after retry, ignoring sleeps scheduled before now (%s)\n", + humantime(time_now))); } } @@ -500,8 +496,8 @@ getaddrinfo_sometime_complete( if (gai_resp->retry > INITIAL_DNS_RETRY) { time_now = time(NULL); child_ctx->next_dns_timeslot = time_now; - DPRINTF(1, ("DNS success after retry, %u next_dns_timeslot reset (%s)", - gai_req->dns_idx, humantime(time_now))); + TRACE(1, ("DNS success after retry, %u next_dns_timeslot reset (%s)\n", + gai_req->dns_idx, humantime(time_now))); } } else { again = should_retry_dns(gai_resp->retcode, @@ -592,28 +588,28 @@ void gai_test_callback(int rescode, int gai_errno, void *context, const char *na sockaddr_u addr; if (rescode) { - DPRINTF(1, ("gai_test_callback context %p error rescode %d %s serv %s\n", - context, rescode, name, service)); + TRACE(1, ("gai_test_callback context %p error rescode %d %s serv %s\n", + context, rescode, name, service)); return; } while (!rescode && NULL != ai_res) { ZERO_SOCK(&addr); memcpy(&addr, ai_res->ai_addr, ai_res->ai_addrlen); - DPRINTF(1, ("ctx %p fam %d addr %s canon '%s' type %s at %p ai_addr %p ai_next %p\n", - context, - AF(&addr), - stoa(&addr), - (ai_res->ai_canonname) - ? ai_res->ai_canonname - : "", - (SOCK_DGRAM == ai_res->ai_socktype) - ? "DGRAM" - : (SOCK_STREAM == ai_res->ai_socktype) - ? "STREAM" - : "(other)", - ai_res, - ai_res->ai_addr, - ai_res->ai_next)); + TRACE(1, ("ctx %p fam %d addr %s canon '%s' type %s at %p ai_addr %p ai_next %p\n", + context, + AF(&addr), + stoa(&addr), + (ai_res->ai_canonname) + ? ai_res->ai_canonname + : "", + (SOCK_DGRAM == ai_res->ai_socktype) + ? "DGRAM" + : (SOCK_STREAM == ai_res->ai_socktype) + ? "STREAM" + : "(other)", + ai_res, + ai_res->ai_addr, + ai_res->ai_next)); getnameinfo_sometime((sockaddr_u *)ai_res->ai_addr, 128, 32, 0, gni_test_callback, context); @@ -732,9 +728,9 @@ blocking_getnameinfo( resp = emalloc_zero(resp_octets); gni_resp = (void *)((char *)resp + sizeof(*resp)); - DPRINTF(2, ("blocking_getnameinfo given addr %s flags 0x%x hostlen %lu servlen %lu\n", - stoa(&gni_req->socku), gni_req->flags, - (u_long)gni_req->hostoctets, (u_long)gni_req->servoctets)); + TRACE(2, ("blocking_getnameinfo given addr %s flags 0x%x hostlen %lu servlen %lu\n", + stoa(&gni_req->socku), gni_req->flags, + (u_long)gni_req->hostoctets, (u_long)gni_req->servoctets)); gni_resp->retcode = getnameinfo(&gni_req->socku.sa, SOCKLEN(&gni_req->socku), @@ -765,7 +761,7 @@ blocking_getnameinfo( if (gni_req->retry > INITIAL_DNS_RETRY) { time_now = time(NULL); worker_ctx->ignore_scheduled_before = time_now; - DPRINTF(1, ("DNS success after retrying, ignoring sleeps scheduled before now (%s)", + TRACE(1, ("DNS success after retrying, ignoring sleeps scheduled before now (%s)\n", humantime(time_now))); } } @@ -836,8 +832,8 @@ getnameinfo_sometime_complete( if (gni_resp->retry > INITIAL_DNS_RETRY) { time_now = time(NULL); child_ctx->next_dns_timeslot = time_now; - DPRINTF(1, ("DNS success after retry, %u next_dns_timeslot reset (%s)", - gni_req->dns_idx, humantime(time_now))); + TRACE(1, ("DNS success after retry, %u next_dns_timeslot reset (%s)\n", + gni_req->dns_idx, humantime(time_now))); } } else { again = should_retry_dns(gni_resp->retcode, gni_resp->gni_errno); @@ -885,11 +881,11 @@ getnameinfo_sometime_complete( void gni_test_callback(int rescode, int gni_errno, sockaddr_u *psau, int flags, const char *host, const char *service, void *context) { if (!rescode) - DPRINTF(1, ("gni_test_callback got host '%s' serv '%s' for addr %s context %p\n", - host, service, stoa(psau), context)); + TRACE(1, ("gni_test_callback got host '%s' serv '%s' for addr %s context %p\n", + host, service, stoa(psau), context)); else - DPRINTF(1, ("gni_test_callback context %p rescode %d gni_errno %d flags 0x%x addr %s\n", - context, rescode, gni_errno, flags, stoa(psau))); + TRACE(1, ("gni_test_callback context %p rescode %d gni_errno %d flags 0x%x addr %s\n", + context, rescode, gni_errno, flags, stoa(psau))); } #endif /* TEST_BLOCKING_WORKER */ @@ -1022,18 +1018,18 @@ scheduled_sleep( time_t now; if (scheduled < worker_ctx->ignore_scheduled_before) { - DPRINTF(1, ("ignoring sleep until %s scheduled at %s (before %s)\n", - humantime(earliest), humantime(scheduled), - humantime(worker_ctx->ignore_scheduled_before))); + TRACE(1, ("ignoring sleep until %s scheduled at %s (before %s)\n", + humantime(earliest), humantime(scheduled), + humantime(worker_ctx->ignore_scheduled_before))); return; } now = time(NULL); if (now < earliest) { - DPRINTF(1, ("sleep until %s scheduled at %s (>= %s)\n", - humantime(earliest), humantime(scheduled), - humantime(worker_ctx->ignore_scheduled_before))); + TRACE(1, ("sleep until %s scheduled at %s (>= %s)\n", + humantime(earliest), humantime(scheduled), + humantime(worker_ctx->ignore_scheduled_before))); if (-1 == worker_sleep(worker_ctx->c, earliest - now)) { /* our sleep was interrupted */ now = time(NULL); @@ -1043,8 +1039,8 @@ scheduled_sleep( next_res_init = worker_ctx->next_res_init; res_init(); #endif - DPRINTF(1, ("sleep interrupted by daemon, ignoring sleeps scheduled before now (%s)\n", - humantime(worker_ctx->ignore_scheduled_before))); + TRACE(1, ("sleep interrupted by daemon, ignoring sleeps scheduled before now (%s)\n", + humantime(worker_ctx->ignore_scheduled_before))); } } } @@ -1129,15 +1125,15 @@ should_retry_dns( again = 1; # ifdef DEBUG errno_to_str(res_errno, msg, sizeof(msg)); - DPRINTF(1, ("intres: EAI_SYSTEM errno %d (%s) means try again, right?\n", - res_errno, msg)); + TRACE(1, ("intres: EAI_SYSTEM errno %d (%s) means try again, right?\n", + res_errno, msg)); # endif break; #endif } - DPRINTF(2, ("intres: resolver returned: %s (%d), %sretrying\n", - gai_strerror(rescode), rescode, again ? "" : "not ")); + TRACE(2, ("intres: resolver returned: %s (%d), %sretrying\n", + gai_strerror(rescode), rescode, again ? "" : "not ")); return again; } diff --git a/libntp/socket.c b/libntp/socket.c index ccea6f0fd..1a490ae19 100644 --- a/libntp/socket.c +++ b/libntp/socket.c @@ -100,9 +100,9 @@ move_fd( if (socket_boundary == -1) { socket_boundary = max(0, min(GETDTABLESIZE() - FD_CHUNK, min(FOPEN_MAX, FD_PREFERRED_SOCKBOUNDARY))); - DPRINTF(1,("move_fd: estimated max descriptors: %d, " - "initial socket boundary: %d\n", - GETDTABLESIZE(), socket_boundary)); + TRACE(1, ("move_fd: estimated max descriptors: %d, " + "initial socket boundary: %d\n", + GETDTABLESIZE(), socket_boundary)); } /* @@ -124,8 +124,8 @@ move_fd( return fd; } socket_boundary = max(0, socket_boundary - FD_CHUNK); - DPRINTF(1, ("move_fd: selecting new socket boundary: %d\n", - socket_boundary)); + TRACE(1, ("move_fd: selecting new socket boundary: %d\n", + socket_boundary)); } while (socket_boundary > 0); #else NTP_REQUIRE((int)fd >= 0); @@ -375,13 +375,13 @@ open_socket( "setsockopt SO_TIMESTAMP on fails on address %s: %m", stoa(addr)); else - DPRINTF(4, ("setsockopt SO_TIMESTAMP enabled on fd %d address %s\n", - fd, stoa(addr))); + TRACE(4, ("setsockopt SO_TIMESTAMP enabled on fd %d address %s\n", + fd, stoa(addr))); } #endif - DPRINTF(4, ("bind(%d) AF_INET%s, addr %s%%%d#%d, flags 0x%x\n", - fd, IS_IPV6(addr) ? "6" : "", stoa(addr), - SCOPE(addr), SRCPORT(addr), interf->flags)); + TRACE(4, ("bind(%d) AF_INET%s, addr %s%%%d#%d, flags 0x%x\n", + fd, IS_IPV6(addr) ? "6" : "", stoa(addr), + SCOPE(addr), SRCPORT(addr), interf->flags)); init_nonblocking_io(fd); @@ -392,8 +392,8 @@ open_socket( add_fd_to_list(fd, FD_TYPE_SOCKET); #if !defined(SYS_WINNT) && !defined(VMS) - DPRINTF(4, ("flags for fd %d: 0x%x\n", fd, - fcntl(fd, F_GETFL, 0))); + TRACE(4, ("flags for fd %d: 0x%x\n", fd, + fcntl(fd, F_GETFL, 0))); #endif /* SYS_WINNT || VMS */ #if defined (HAVE_IO_COMPLETION_PORT) @@ -448,16 +448,16 @@ sendpkt( * unbound peer - drop request and wait for better * network conditions */ - DPRINTF(2, ("%ssendpkt(dst=%s, ttl=%d, len=%d): no interface - IGNORED\n", - ismcast ? "\tMCAST\t***** " : "", - stoa(dest), ttl, len)); + TRACE(2, ("%ssendpkt(dst=%s, ttl=%d, len=%d): no interface - IGNORED\n", + ismcast ? "\tMCAST\t***** " : "", + stoa(dest), ttl, len)); return; } do { - DPRINTF(2, ("%ssendpkt(%d, dst=%s, src=%s, ttl=%d, len=%d)\n", - ismcast ? "\tMCAST\t***** " : "", src->fd, - stoa(dest), stoa(&src->sin), ttl, len)); + TRACE(2, ("%ssendpkt(%d, dst=%s, src=%s, ttl=%d, len=%d)\n", + ismcast ? "\tMCAST\t***** " : "", src->fd, + stoa(dest), stoa(&src->sin), ttl, len)); #ifdef MCAST /* * for the moment we use the bcast option to set multicast ttl @@ -626,11 +626,11 @@ read_network_packet( fromlen = sizeof(from); buflen = recvfrom(fd, buf, sizeof(buf), 0, &from.sa, &fromlen); - DPRINTF(4, ("%s on (%lu) fd=%d from %s\n", - (itf->ignore_packets) - ? "ignore" - : "drop", - free_recvbuffs(), fd, stoa(&from))); + TRACE(4, ("%s on (%lu) fd=%d from %s\n", + (itf->ignore_packets) + ? "ignore" + : "drop", + free_recvbuffs(), fd, stoa(&from))); if (itf->ignore_packets) packets_ignored++; else @@ -670,13 +670,13 @@ read_network_packet( } else if (buflen < 0) { msyslog(LOG_ERR, "recvfrom(%s) fd=%d: %m", stoa(&rb->recv_srcadr), fd); - DPRINTF(5, ("read_network_packet: fd=%d dropped (bad recvfrom)\n", - fd)); + TRACE(5, ("read_network_packet: fd=%d dropped (bad recvfrom)\n", + fd)); freerecvbuf(rb); return (buflen); } - DPRINTF(3, ("read_network_packet: fd=%d length %d from %s\n", + TRACE(3, ("read_network_packet: fd=%d length %d from %s\n", fd, buflen, stoa(&rb->recv_srcadr))); /* diff --git a/libntp/socktohost.c b/libntp/socktohost.c index 71cc8efe8..c61e57148 100644 --- a/libntp/socktohost.c +++ b/libntp/socktohost.c @@ -44,7 +44,7 @@ socktohost( NULL, 0, gni_flags)) return stoa(sock); /* use address */ - DPRINTF(1, ("%s reversed to %s\n", stoa(sock), pbuf)); + TRACE(1, ("%s reversed to %s\n", stoa(sock), pbuf)); /* * Resolve the reversed name and make sure the reversed address @@ -101,7 +101,8 @@ socktohost( return pbuf; /* forward check passed */ forward_fail: - DPRINTF(1, ("forward check lookup fail: %s\n", pbuf)); + TRACE(1, ("%s forward check lookup fail: %s\n", pbuf, + gai_strerror(a_info))); LIB_GETBUF(pliar); snprintf(pliar, LIB_BUFLENGTH, "%s (%s)", stoa(sock), pbuf); diff --git a/libntp/work_fork.c b/libntp/work_fork.c index f09a87dd2..44ef043a5 100644 --- a/libntp/work_fork.c +++ b/libntp/work_fork.c @@ -78,8 +78,8 @@ worker_sleep( if (!worker_sighup_received) sleep_remain = sleep(sleep_remain); if (worker_sighup_received) { - DPRINTF(1, ("worker SIGHUP with %us left to sleep", - sleep_remain)); + TRACE(1, ("worker SIGHUP with %us left to sleep", + sleep_remain)); worker_sighup_received = 0; return -1; } @@ -233,8 +233,8 @@ receive_blocking_req_internal( msyslog(LOG_ERR, "receive_blocking_req_internal: pipe read %m\n"); } else if (0 == rc) { - DPRINTF(4, ("parent closed request pipe, child %d terminating\n", - c->pid)); + TRACE(4, ("parent closed request pipe, child %d terminating\n", + c->pid)); } else if (rc != sizeof(hdr)) { msyslog(LOG_ERR, "receive_blocking_req_internal: short header read %d of %lu\n", @@ -288,10 +288,10 @@ send_blocking_resp_internal( return 0; if (rc < 0) - DPRINTF(1, ("send_blocking_resp_internal: pipe write %m\n")); + TRACE(1, ("send_blocking_resp_internal: pipe write %m\n")); else - DPRINTF(1, ("send_blocking_resp_internal: short write %d of %ld\n", - rc, octets)); + TRACE(1, ("send_blocking_resp_internal: short write %d of %ld\n", + rc, octets)); return -1; } @@ -313,15 +313,15 @@ receive_blocking_resp_internal( rc = read(c->resp_read_pipe, &hdr, sizeof(hdr)); if (rc < 0) { - DPRINTF(1, ("receive_blocking_resp_internal: pipe read %m\n")); + TRACE(1, ("receive_blocking_resp_internal: pipe read %m\n")); } else if (0 == rc) { /* this is the normal child exited indication */ } else if (rc != sizeof(hdr)) { - DPRINTF(1, ("receive_blocking_resp_internal: short header read %d of %lu\n", - rc, (u_long)sizeof(hdr))); + TRACE(1, ("receive_blocking_resp_internal: short header read %d of %lu\n", + rc, (u_long)sizeof(hdr))); } else if (BLOCKING_RESP_MAGIC != hdr.magic_sig) { - DPRINTF(1, ("receive_blocking_resp_internal: header mismatch (0x%x)\n", - hdr.magic_sig)); + TRACE(1, ("receive_blocking_resp_internal: header mismatch (0x%x)\n", + hdr.magic_sig)); } else { INSIST(sizeof(hdr) < hdr.octets && hdr.octets < 16 * 1024); @@ -333,10 +333,10 @@ receive_blocking_resp_internal( octets); if (rc < 0) - DPRINTF(1, ("receive_blocking_resp_internal: pipe data read %m\n")); + TRACE(1, ("receive_blocking_resp_internal: pipe data read %m\n")); else if (rc < octets) - DPRINTF(1, ("receive_blocking_resp_internal: short read %d of %ld\n", - rc, octets)); + TRACE(1, ("receive_blocking_resp_internal: short read %d of %ld\n", + rc, octets)); else return resp; } @@ -450,7 +450,7 @@ fork_blocking_child( if (childpid) { /* this is the parent */ - DPRINTF(1, ("forked worker child (pid %d)\n", childpid)); + TRACE(1, ("forked worker child (pid %d)\n", childpid)); c->pid = childpid; c->ispipe = is_pipe; diff --git a/libntp/work_thread.c b/libntp/work_thread.c index b4050b8d8..622a0ab49 100644 --- a/libntp/work_thread.c +++ b/libntp/work_thread.c @@ -379,7 +379,7 @@ start_blocking_thread_internal( &blocking_thread_id); if (NULL == blocking_child_thread) { - DPRINTF(1, ("fatal can not start blocking thread\n")); + msyslog(LOG_ERR, "start blocking thread failed: %m\n"); exit(-1); } c->thread_id = blocking_thread_id; @@ -387,7 +387,7 @@ start_blocking_thread_internal( /* remember the thread priority is only within the process class */ if (!SetThreadPriority(blocking_child_thread, THREAD_PRIORITY_BELOW_NORMAL)) - DPRINTF(1, ("Error lowering blocking thread priority\n")); + msyslog(LOG_ERR, "Error lowering blocking thread priority: %m\n"); resumed = ResumeThread(blocking_child_thread); DEBUG_INSIST(resumed); diff --git a/ntpd/Makefile.am b/ntpd/Makefile.am index 51f6b8698..881fc6c9f 100644 --- a/ntpd/Makefile.am +++ b/ntpd/Makefile.am @@ -123,6 +123,7 @@ EXTRA_DIST = \ check_PROGRAMS = @MAKE_CHECK_Y2K@ EXTRA_PROGRAMS = check_y2k ntpdsim keyword-gen noinst_DATA = $(srcdir)/ntpd-opts.texi $(srcdir)/ntpd-opts.menu +noinst_HEADERS = declcond.h run_ag= cd $(srcdir) && env PATH="$(abs_builddir):$(PATH)" \ autogen -L ../sntp/include --writable std_def_list = \ diff --git a/ntpd/check_y2k.c b/ntpd/check_y2k.c index 6b8311502..12d1a592b 100644 --- a/ntpd/check_y2k.c +++ b/ntpd/check_y2k.c @@ -104,7 +104,6 @@ #define GoodLeap(Year) (((Year)%4 || (!((Year)%100) && (Year)%400)) ? 0 : 13 ) -volatile int debug = 0; /* debugging requests for parse stuff */ char const *progname = "check_y2k"; long diff --git a/ntpd/declcond.h b/ntpd/declcond.h new file mode 100644 index 000000000..d712948ba --- /dev/null +++ b/ntpd/declcond.h @@ -0,0 +1,17 @@ +/* + * declcond.h - declarations conditionalized for ntpd + * + * The NTP reference implementation distribution includes two distinct + * declcond.h files, one in ntpd/ used only by ntpd, and another in + * include/ used by libntp and utilities. This relies on the source + * file's directory being ahead of include/ in the include search. + * + * The ntpd variant of declcond.h declares "debug" only #ifdef DEBUG, + * as the --disable-debugging version of ntpd should not reference + * "debug". The libntp and utilities variant always declares debug, + * as it is used in those codebases even without DEBUG defined. + */ + +#ifdef DEBUG /* uncommented in ntpd/declcond.h */ +extern int debug; +#endif /* uncommented in ntpd/declcond.h */ diff --git a/ntpd/keyword-gen.c b/ntpd/keyword-gen.c index 03cb32189..cf6aaf687 100644 --- a/ntpd/keyword-gen.c +++ b/ntpd/keyword-gen.c @@ -248,7 +248,6 @@ char * symb[1024]; /* map token ID to symbolic name */ /* for libntp */ const char * progname = "keyword-gen"; -volatile int debug = 1; int main (int, char **); static void generate_preamble (void); @@ -268,6 +267,8 @@ int main(int argc, char **argv) fprintf(stderr, "Usage:\n%s t_header.h\n", argv[0]); exit(1); } + debug = 1; + populate_symb(argv[1]); generate_preamble(); diff --git a/ntpd/ntp_scanner.c b/ntpd/ntp_scanner.c index c49e055fd..8fcbb4e23 100644 --- a/ntpd/ntp_scanner.c +++ b/ntpd/ntp_scanner.c @@ -19,11 +19,11 @@ #include #include +#include "ntpd.h" #include "ntp_config.h" #include "ntpsim.h" #include "ntp_scanner.h" #include "ntp_parser.h" -#include "ntp_debug.h" /* ntp_keyword.h declares finite state machine and token text */ #include "ntp_keyword.h" diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 2c9bb477e..c26cc41f8 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -150,13 +150,6 @@ int priority_done = 2; /* 0 - Set priority */ /* 2 - Don't set priority */ /* 1 and 2 are pretty much the same */ -#ifdef DEBUG -/* - * Debugging flag - */ -volatile int debug = 0; /* No debugging by default */ -#endif - int listen_to_virtual_ips = 1; /* diff --git a/ntpd/refclock_bancomm.c b/ntpd/refclock_bancomm.c index e72337f92..1bbea7b9f 100644 --- a/ntpd/refclock_bancomm.c +++ b/ntpd/refclock_bancomm.c @@ -145,11 +145,6 @@ typedef void *SYMMT_PCI_HANDLE; */ extern u_long current_time; /* current time(s) */ -/* - * Imported from ntpd module - */ -extern volatile int debug; /* global debug flag */ - /* * VME unit control structure. * Changes made to vmeunit structure. Most members are now available in the diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index 933b5d16a..b8eb39c28 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -109,19 +109,14 @@ static timer_t ntpdate_timerid; */ s_char sys_precision; /* local clock precision (log2 s) */ -/* - * Debugging flag - */ -volatile int debug = 0; - /* * File descriptor masks etc. for call to select */ int ai_fam_templ; -int nbsock; /* the number of sockets used */ +int nbsock; /* the number of sockets used */ SOCKET fd[MAX_AF]; -int fd_family[MAX_AF]; /* to remember the socket family */ +int fd_family[MAX_AF]; /* to remember the socket family */ #ifdef HAVE_POLL_H struct pollfd fdmask[MAX_AF]; #else diff --git a/ntpdate/ntptimeset.c b/ntpdate/ntptimeset.c index 2485aadb6..46c2f8f1d 100644 --- a/ntpdate/ntptimeset.c +++ b/ntpdate/ntptimeset.c @@ -191,11 +191,6 @@ static timer_t ntpdate_timerid; #define NTP_MAXLIST 5 /* maximum select list size */ #define PEER_SHIFT 8 /* 8 suitable for crystal time base */ -/* - * Debugging flag - */ -volatile int debug = 0; - /* * File descriptor masks etc. for call to select */ diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index 27fe70a7a..36e850f79 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -239,7 +239,6 @@ static FILE *current_output; extern struct xcmd opcmds[]; char *progname; -volatile int debug; #ifdef NO_MAIN_ALLOWED CALL(ntpdc,"ntpdc",ntpdcmain); diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 79c29fdcf..a6f9b4fc2 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -381,7 +381,6 @@ FILE *current_output; extern struct xcmd opcmds[]; char *progname; -volatile int debug; #ifdef NO_MAIN_ALLOWED #ifndef BUILD_AS_LIB @@ -733,6 +732,7 @@ getresponse( int len; int first; char *data; + int errcode; /* * This is pretty tricky. We may get between 1 and MAXFRAG packets @@ -874,15 +874,12 @@ getresponse( * Check the error code. If non-zero, return it. */ if (CTL_ISERROR(rpkt.r_m_e_op)) { - int errcode; - errcode = (ntohs(rpkt.status) >> 8) & 0xff; - if (debug && CTL_ISMORE(rpkt.r_m_e_op)) { - printf("Error code %d received on not-final packet\n", - errcode); - } + if (CTL_ISMORE(rpkt.r_m_e_op)) + TRACE(1, ("Error code %d received on not-final packet\n", + errcode)); if (errcode == CERR_UNSPEC) - return ERR_UNSPEC; + return ERR_UNSPEC; return errcode; } @@ -891,9 +888,8 @@ getresponse( * we sent. */ if (ntohs(rpkt.associd) != associd) { - if (debug) - printf("Association ID %d doesn't match expected %d\n", - ntohs(rpkt.associd), associd); + TRACE(1, ("Association ID %d doesn't match expected %d\n", + ntohs(rpkt.associd), associd)); /* * Hack for silly fuzzballs which, at the time of writing, * return an assID of sys.peer when queried for system variables. @@ -914,16 +910,16 @@ getresponse( * boundary and no smaller than claimed by rpkt.count */ if (n & 0x3) { - DPRINTF(1, ("Response packet not padded, size = %d\n", - n)); + TRACE(1, ("Response packet not padded, size = %d\n", + n)); continue; } shouldbesize = (CTL_HEADER_LEN + count + 3) & ~3; if (n < shouldbesize) { - printf("Response packet claims %u octets payload, above %ld received\n", - count, (long)(n - CTL_HEADER_LEN)); + printf("Response packet claims %u octets payload, above %d received\n", + count, n - CTL_HEADER_LEN); return ERR_INCOMPLETE; } @@ -967,29 +963,23 @@ getresponse( } } - if (debug >= 2) - printf("Got packet, size = %d\n", n); + TRACE(2, ("Got packet, size = %d\n", n)); if ((int)count > (n - CTL_HEADER_LEN)) { - if (debug) - printf("Received count of %d octets, data in packet is %ld\n", - count, - (long)(n - CTL_HEADER_LEN)); + TRACE(1, ("Received count of %d octets, data in packet is %d\n", + count, (n - CTL_HEADER_LEN))); continue; } if (count == 0 && CTL_ISMORE(rpkt.r_m_e_op)) { - if (debug) - printf("Received count of 0 in non-final fragment\n"); + TRACE(1, ("Received count of 0 in non-final fragment\n")); continue; } if (offset + count > sizeof(pktdata)) { - if (debug) - printf("Offset %d, count %d, too big for buffer\n", - offset, count); + TRACE(1, ("Offset %d, count %d, too big for buffer\n", + offset, count)); return ERR_TOOMUCH; } if (seenlastfrag && !CTL_ISMORE(rpkt.r_m_e_op)) { - if (debug) - printf("Received second last fragment packet\n"); + TRACE(1, ("Received second last fragment packet\n")); continue; } @@ -997,13 +987,11 @@ getresponse( * So far, so good. Record this fragment, making sure it doesn't * overlap anything. */ - if (debug >= 2) - printf("Packet okay\n");; + TRACE(2, ("Packet okay\n")); if (numfrags > (MAXFRAGS - 1)) { - if (debug) - printf("Number of fragments exceeds maximum %d\n", - MAXFRAGS - 1); + TRACE(2, ("Number of fragments exceeds maximum %d\n", + MAXFRAGS - 1)); return ERR_TOOMUCH; } @@ -1018,25 +1006,20 @@ getresponse( } if (f < numfrags && offset == offsets[f]) { - if (debug) - printf("duplicate %u octets at %u ignored, prior %u at %u\n", - count, offset, counts[f], - offsets[f]); + TRACE(1, ("duplicate %u octets at %u ignored, prior %u at %u\n", + count, offset, counts[f], offsets[f])); continue; } if (f > 0 && (offsets[f-1] + counts[f-1]) > offset) { - if (debug) - printf("received frag at %u overlaps with %u octet frag at %u\n", - offset, counts[f-1], - offsets[f-1]); + TRACE(1, ("received frag at %u overlaps with %u octet frag at %u\n", + offset, counts[f-1], offsets[f-1])); continue; } if (f < numfrags && (offset + count) > offsets[f]) { - if (debug) - printf("received %u octet frag at %u overlaps with frag at %u\n", - count, offset, offsets[f]); + TRACE(1, ("received %u octet frag at %u overlaps with frag at %u\n", + count, offset, offsets[f])); continue; } @@ -1074,10 +1057,8 @@ getresponse( break; if (f == numfrags) { *rsize = offsets[f-1] + counts[f-1]; - if (debug) - fprintf(stderr, - "%lu packets reassembled into response\n", - (u_long)numfrags); + TRACE(1, ("%lu packets reassembled into response\n", + (u_long)numfrags)); return 0; } } diff --git a/ports/winnt/include/gaa_compat.h b/ports/winnt/include/gaa_compat.h index 13cc9e164..fdacaf0e8 100644 --- a/ports/winnt/include/gaa_compat.h +++ b/ports/winnt/include/gaa_compat.h @@ -766,6 +766,6 @@ GetAdaptersAddresses( #endif /* +++++++++++++++++++++++ from iphlpapi.h */ -#endif /* !_W64 */ #pragma warning(pop) +#endif /* !_W64 */ #endif /* GAA_COMPAT_H */ diff --git a/ports/winnt/libntp/dnslookup.c b/ports/winnt/libntp/dnslookup.c deleted file mode 100644 index 6d72edc99..000000000 --- a/ports/winnt/libntp/dnslookup.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2006 Internet Systems Consortium, Inc. ("ISC") - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * This module uses Windows lookup facilities to get the address information - * wherever it resides. This avoids calling the Internet standard funcction - * gethostbyname and gives us more control over the results since the - * Microsoft implementation seems to return the wrong error code for some - * conditions. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Set this Macro to force retries even if it fails - * the lookup - */ -#ifdef FORCE_DNSRETRY - -#undef EAI_NONAME -#define EAI_NONAME EAI_AGAIN - -#endif - -typedef struct hostent hostent_t; - -int ReturnCode(int errcode) -{ - int retcode; - - switch (errcode) - { - case 0: - return (0); - case WSAEINVAL: - return (EAI_BADFLAGS); - case WSANO_DATA: - return (EAI_NONAME); - case WSANOTINITIALISED: - case WSASERVICE_NOT_FOUND: - return (EAI_FAIL); - case WSA_NOT_ENOUGH_MEMORY: - return (EAI_MEMORY); - default: - return (EAI_FAIL); - } -} - -int -AddToAddresses(char **Addresses, int *cnt, CSADDR_INFO *csaddr) -{ - - int csize; - struct in_addr *sinaddr; - char *addr; - struct in_addr *addr_list; - struct sockaddr_in *sin; - sin = (struct sockaddr_in *) csaddr->RemoteAddr.lpSockaddr; - if (*Addresses != NULL) - { - csize = _msize(*Addresses); - addr_list = realloc(*Addresses, csize + sizeof(struct in_addr)); - } - else - { - csize = 0; - addr_list = malloc(sizeof(struct in_addr)); - } - addr = (char *) addr_list; - sinaddr = &((struct in_addr*) addr)[(*cnt)]; - memset(sinaddr, 0, sizeof(sinaddr)); - memcpy(sinaddr, &sin->sin_addr, sizeof(struct in_addr)); - - (*cnt)++; - *Addresses = (char *) addr_list; - return 0; -} - -int -DNSlookup_name( - const char *name, - int ai_family, - struct hostent **Addresses -) -{ - char buffer[sizeof(WSAQUERYSET) + 2048]; - WSAQUERYSET query; - struct hostent *addr = NULL; - char *bufaddr = NULL; - char ** addrlist = &bufaddr; - int addrcnt = 0; - WSAQUERYSET *results = (WSAQUERYSET *) buffer; - GUID HostnameGUID = SVCID_INET_HOSTADDRBYNAME; - HANDLE handle; - DWORD dwLength; - int err = 0; - int retcode = 0; - int errcode = 0; - DWORD i; - - /* - * First we must create a query set - */ - memset(&query, 0, sizeof(query)); - query.dwSize = sizeof(query); - query.lpszServiceInstanceName = (char *)name; - query.dwNameSpace = NS_DNS; - query.lpServiceClassId = &HostnameGUID; - - err = WSALookupServiceBegin(&query, - LUP_RETURN_NAME | LUP_RETURN_BLOB | LUP_RETURN_ADDR, - &handle); - - if(err == SOCKET_ERROR) - { - /* - * Convert the error code and return - */ - return (ReturnCode(WSAGetLastError())); - } - - /* - * Initially none - * Change if we get something - */ - retcode = EAI_NONAME; - dwLength = sizeof(buffer); - - while(err == 0) /* Drop out when error */ - { - memset(&buffer, 0, dwLength); - err = WSALookupServiceNext( - handle, - 0, - &dwLength, - results); - errcode = WSAGetLastError(); - if (results->dwNumberOfCsAddrs > 0) - { - if (addr == NULL) - { - addr = (struct hostent *) malloc(sizeof(struct hostent)); - memset(addr, 0, sizeof(struct hostent)); - addr->h_addrtype = (short) results->lpcsaBuffer->iSocketType; - addr->h_length = sizeof(struct in_addr); /* Only passing back the address */ - addrlist = malloc(sizeof(char *)); - *addrlist = NULL; - } - for (i = 0; i < results->dwNumberOfCsAddrs; i++) - { - AddToAddresses(addrlist, &addrcnt, &results->lpcsaBuffer[i]); - } - } - - } - if (addr != NULL) - { - addr->h_name = (char *) name; - addr->h_addr_list = addrlist; - retcode = 0; - *Addresses = addr; - } - else - { -#ifdef FORCE_DNSRETRY - /* - * We do this or the error would never be logged - */ - if (errcode == WSANO_DATA) - msyslog(LOG_ERR, "Address not found for %s", name); -#endif - retcode = ReturnCode(errcode); - } - WSALookupServiceEnd(handle); - return (retcode); -} - diff --git a/ports/winnt/libntp/mexit.c b/ports/winnt/libntp/mexit.c deleted file mode 100644 index e6b4469e8..000000000 --- a/ports/winnt/libntp/mexit.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * mexit - Used to exit the NTPD daemon - * - */ - -#include -#include - -HANDLE hServDoneEvent = NULL; - -void -service_exit( - int status - ) -{ - extern int debug; - - if (debug) /* did not become a service, simply exit */ - ExitThread((DWORD)status); - else { - /* service mode, need to have the service_main routine - * register with the service control manager that the - * service has stopped running, before exiting - */ - if ((status > 0) && (hServDoneEvent != NULL)) - SetEvent(hServDoneEvent); - ExitThread((DWORD)status); - } -} - diff --git a/ports/winnt/libntp/setpriority.c b/ports/winnt/libntp/setpriority.c index c57269ad3..52ab78529 100644 --- a/ports/winnt/libntp/setpriority.c +++ b/ports/winnt/libntp/setpriority.c @@ -43,9 +43,8 @@ int setpriority( BOOL success; DWORD prio_class; - if (PRIO_PROCESS != which || who || NTP_PRIO != prio) { - DPRINTF(1,("windows setpriority() clone needs work.\n")); - } + if (PRIO_PROCESS != which || who || NTP_PRIO != prio) + TRACE(1, ("windows setpriority() clone needs work.\n")); prio_class = GetPriorityClass(GetCurrentProcess()); diff --git a/ports/winnt/libntp/termios.c b/ports/winnt/libntp/termios.c index c13ea4170..db9895bed 100644 --- a/ports/winnt/libntp/termios.c +++ b/ports/winnt/libntp/termios.c @@ -4,15 +4,11 @@ #include #include #include -#include "ntp_machine.h" -#include "ntp_stdlib.h" + +#include "ntp.h" +#include "ntp_tty.h" #include "lib_strbuf.h" -#include "ntp_syslog.h" #include "ntp_assert.h" -#include "ntp_debug.h" -#include "ntp_fp.h" -#include "ntp.h" -#include "ntp_refclock.h" #include "win32_io.h" #define MAX_SERIAL 255 /* COM1: - COM255: */ @@ -55,7 +51,7 @@ HANDLE common_serial_open( * equanimously. */ - DPRINTF(1, ("common_serial_open given %s\n", dev)); + TRACE(1, ("common_serial_open given %s\n", dev)); pch = NULL; if ('/' == dev[0]) { @@ -67,23 +63,23 @@ HANDLE common_serial_open( } pch++; } - DPRINTF(1, ("common_serial_open skipped to ending digits leaving %s\n", pch)); + TRACE(1, ("common_serial_open skipped to ending digits leaving %s\n", pch)); } else if ('c' == tolower(dev[0]) && 'o' == tolower(dev[1]) && 'm' == tolower(dev[2])) { pch = dev + 3; - DPRINTF(1, ("common_serial_open skipped COM leaving %s\n", pch)); + TRACE(1, ("common_serial_open skipped COM leaving %s\n", pch)); } if (!pch || !isdigit(pch[0])) { - DPRINTF(1, ("not a digit: %s\n", pch ? pch : "[NULL]")); + TRACE(1, ("not a digit: %s\n", pch ? pch : "[NULL]")); return INVALID_HANDLE_VALUE; } if (1 != sscanf(pch, "%d", &unit) || unit > MAX_SERIAL || unit < 0) { - DPRINTF(1, ("sscanf failure of %s\n", pch)); + TRACE(1, ("sscanf failure of %s\n", pch)); return INVALID_HANDLE_VALUE; } @@ -101,7 +97,7 @@ HANDLE common_serial_open( NTP_ENSURE(0 == hnds[unit].opens); LIB_GETBUF(windev); snprintf(windev, LIB_BUFLENGTH, "\\\\.\\COM%d", unit); - DPRINTF(1, ("windows device %s\n", windev)); + TRACE(1, ("windows device %s\n", windev)); *pwindev = windev; hnds[unit].h = CreateFile( diff --git a/ports/winnt/ntpd/ntservice.c b/ports/winnt/ntpd/ntservice.c index af76201e3..fb6b1c169 100644 --- a/ports/winnt/ntpd/ntservice.c +++ b/ports/winnt/ntpd/ntservice.c @@ -41,7 +41,6 @@ static BOOL computer_shutting_down = FALSE; static int glb_argc; static char **glb_argv; HANDLE hServDoneEvent = NULL; -extern volatile int debug; extern int accept_wildcard_if_for_winnt; /* diff --git a/ports/winnt/vs2008/libntp/libntp.vcproj b/ports/winnt/vs2008/libntp/libntp.vcproj index 78b5eb036..f689558b7 100644 --- a/ports/winnt/vs2008/libntp/libntp.vcproj +++ b/ports/winnt/vs2008/libntp/libntp.vcproj @@ -632,6 +632,10 @@ RelativePath="..\..\include\config.h" > + + @@ -893,11 +897,11 @@ > + + diff --git a/sntp/kod_management.c b/sntp/kod_management.c index 0a26854e1..3d691adcd 100644 --- a/sntp/kod_management.c +++ b/sntp/kod_management.c @@ -189,7 +189,7 @@ kod_init_kod_db( char *str_ptr; char error = 0; - DPRINTF(2, ("Initializing KOD DB...\n")); + TRACE(2, ("Initializing KOD DB...\n")); kod_db_file = estrdup(db_file); @@ -235,11 +235,11 @@ kod_init_kod_db( } if (0 == kod_db_cnt) { - DPRINTF(2, ("KoD DB %s empty.\n", db_file)); + TRACE(2, ("KoD DB %s empty.\n", db_file)); goto wrapup; } - DPRINTF(2, ("KoD DB %s contains %d entries, reading...\n", db_file, kod_db_cnt)); + TRACE(2, ("KoD DB %s contains %d entries, reading...\n", db_file, kod_db_cnt)); rewind(db_s); @@ -288,10 +288,10 @@ kod_init_kod_db( wrapup: fclose(db_s); for (a = 0; a < kod_db_cnt; a++) - DPRINTF(2, ("KoD entry %d: %s at %llx type %s\n", a, - kod_db[a]->hostname, - (unsigned long long)kod_db[a]->timestamp, - kod_db[a]->type)); + TRACE(2, ("KoD entry %d: %s at %llx type %s\n", a, + kod_db[a]->hostname, + (unsigned long long)kod_db[a]->timestamp, + kod_db[a]->type)); if (!readonly && write_kod_db()) atexit(&atexit_write_kod_db); diff --git a/sntp/main.c b/sntp/main.c index 12499c636..f191476b2 100644 --- a/sntp/main.c +++ b/sntp/main.c @@ -140,21 +140,21 @@ sntp_main ( exit(EX_SOFTWARE); init_lib(); - DPRINTF(2, ("init_lib() done, %s%s\n", - (ipv4_works) - ? "ipv4_works " - : "", - (ipv6_works) - ? "ipv6_works " - : "")); optct = ntpOptionProcess(&sntpOptions, argc, argv); argc -= optct; argv += optct; debug = DESC(DEBUG_LEVEL).optOccCt; - DPRINTF(1, ("%s\n", Version)); - + TRACE(1, ("%s\n", Version)); + + TRACE(2, ("init_lib() done, %s%s\n", + (ipv4_works) + ? "ipv4_works " + : "", + (ipv6_works) + ? "ipv6_works " + : "")); ntpver = OPT_VALUE_NTPVERSION; steplimit = OPT_VALUE_STEPLIMIT / 1e3; headspace.tv_usec = max(0, OPT_VALUE_HEADSPACE * 1000); @@ -183,7 +183,7 @@ sntp_main ( /* IPv6 available? */ if (isc_net_probeipv6() != ISC_R_SUCCESS) { ai_fam_pref = AF_INET; - DPRINTF(1, ("No ipv6 support available, forcing ipv4\n")); + TRACE(1, ("No ipv6 support available, forcing ipv4\n")); } else { /* Check for options -4 and -6 */ if (HAVE_OPT(IPV4)) @@ -381,7 +381,7 @@ handle_lookup( size_t name_sz; size_t octets; - DPRINTF(1, ("handle_lookup(%s,%#x)\n", name, flags)); + TRACE(1, ("handle_lookup(%s,%#x)\n", name, flags)); ZERO(hints); hints.ai_family = ai_fam_pref; @@ -464,10 +464,10 @@ sntp_name_resolved( fprintf(stderr, "%s lookup error %s\n", dctx->name, gai_strerror(rescode)); } else { - DPRINTF(3, ("%s [%s]\n", dctx->name, - (addr->ai_canonname != NULL) - ? addr->ai_canonname - : "")); + TRACE(3, ("%s [%s]\n", dctx->name, + (addr->ai_canonname != NULL) + ? addr->ai_canonname + : "")); for (ai = addr; ai != NULL; ai = ai->ai_next) { @@ -592,8 +592,8 @@ queue_xmt( if (xctx->sched > start_cb.tv_sec) delay.tv_sec = xctx->sched - start_cb.tv_sec; event_add(ev_xmt_timer, &delay); - DPRINTF(2, ("queue_xmt: xmt timer for %u usec\n", - (u_int)delay.tv_usec)); + TRACE(2, ("queue_xmt: xmt timer for %u usec\n", + (u_int)delay.tv_usec)); } } @@ -621,8 +621,8 @@ xmt_timer_cb( gettimeofday_cached(base, &start_cb); if (xmt_q->sched <= start_cb.tv_sec) { UNLINK_HEAD_SLIST(x, xmt_q, link); - DPRINTF(2, ("xmt_timer_cb: at .%6.6u -> %s\n", - (u_int)start_cb.tv_usec, stoa(&x->spkt->addr))); + TRACE(2, ("xmt_timer_cb: at .%6.6u -> %s\n", + (u_int)start_cb.tv_usec, stoa(&x->spkt->addr))); xmt(x); free(x); if (NULL == xmt_q) @@ -630,16 +630,16 @@ xmt_timer_cb( } if (xmt_q->sched <= start_cb.tv_sec) { event_add(ev_xmt_timer, &headspace); - DPRINTF(2, ("xmt_timer_cb: at .%6.6u headspace %6.6u\n", - (u_int)start_cb.tv_usec, - (u_int)headspace.tv_usec)); + TRACE(2, ("xmt_timer_cb: at .%6.6u headspace %6.6u\n", + (u_int)start_cb.tv_usec, + (u_int)headspace.tv_usec)); } else { delay.tv_sec = xmt_q->sched - start_cb.tv_sec; delay.tv_usec = 0; event_add(ev_xmt_timer, &delay); - DPRINTF(2, ("xmt_timer_cb: at .%6.6u next %ld seconds\n", - (u_int)start_cb.tv_usec, - (long)delay.tv_sec)); + TRACE(2, ("xmt_timer_cb: at .%6.6u next %ld seconds\n", + (u_int)start_cb.tv_usec, + (long)delay.tv_sec)); } } @@ -676,8 +676,8 @@ xmt( memcpy(&spkt->x_pkt, &x_pkt, min(sizeof(spkt->x_pkt), pkt_len)); spkt->stime = tv_xmt.tv_sec - JAN_1970; - DPRINTF(2, ("xmt: %lx.%6.6u %s %s\n", (u_long)tv_xmt.tv_sec, - (u_int)tv_xmt.tv_usec, dctx->name, stoa(dst))); + TRACE(2, ("xmt: %lx.%6.6u %s %s\n", (u_long)tv_xmt.tv_sec, + (u_int)tv_xmt.tv_usec, dctx->name, stoa(dst))); /* ** If the send fails: @@ -710,8 +710,8 @@ timeout_queries(void) if (0 == spkt->stime || spkt->done) continue; age = start_cb.tv_sec - spkt->stime; - DPRINTF(3, ("%s %s age %ld\n", stoa(&spkt->addr), - spkt->dctx->name, age)); + TRACE(3, ("%s %s age %ld\n", stoa(&spkt->addr), + spkt->dctx->name, age)); if (age > ucst_timeout) timeout_query(spkt); } @@ -729,8 +729,8 @@ void dec_pending_ntp( check_exit_conditions(); } else { INSIST(0 == n_pending_ntp); - DPRINTF(1, ("n_pending_ntp reached zero before dec for %s %s\n", - name, stoa(server))); + TRACE(1, ("n_pending_ntp reached zero before dec for %s %s\n", + name, stoa(server))); } } @@ -762,7 +762,7 @@ check_kod( /* Is there a KoD on file for this address? */ hostname = addrinfo_to_str(ai); - DPRINTF(2, ("check_kod: checking <%s>\n", hostname)); + TRACE(2, ("check_kod: checking <%s>\n", hostname)); if (search_entry(hostname, &reason)) { printf("prior KoD for %s, skipping.\n", hostname); @@ -802,14 +802,14 @@ sock_cb( int rc; INSIST(sock4 == fd || sock6 == fd); - DPRINTF(3, ("sock_cb: event on sock%s:%s%s%s%s [UCST]\n", - (fd == sock6) - ? "6" - : "4", - (what & EV_TIMEOUT) ? " timeout" : "", - (what & EV_READ) ? " read" : "", - (what & EV_WRITE) ? " write" : "", - (what & EV_SIGNAL) ? " signal" : "")); + TRACE(3, ("sock_cb: event on sock%s:%s%s%s%s [UCST]\n", + (fd == sock6) + ? "6" + : "4", + (what & EV_TIMEOUT) ? " timeout" : "", + (what & EV_READ) ? " read" : "", + (what & EV_WRITE) ? " write" : "", + (what & EV_SIGNAL) ? " signal" : "")); if (!(EV_READ & what)) { if (EV_TIMEOUT & what) @@ -842,13 +842,13 @@ sock_cb( return; } - DPRINTF(1, ("sock_cb: %s %s\n", spkt->dctx->name, - sptoa(&sender))); + TRACE(1, ("sock_cb: %s %s\n", spkt->dctx->name, + sptoa(&sender))); rpktl = process_pkt(&r_pkt, &sender, rpktl, MODE_SERVER, &spkt->x_pkt, "sock_cb"); - DPRINTF(2, ("sock_cb: process_pkt returned %d\n", rpktl)); + TRACE(2, ("sock_cb: process_pkt returned %d\n", rpktl)); /* If this is a Unicast packet, one down ... */ if (!spkt->done && (CTX_UCST & spkt->dctx->flags)) { @@ -860,7 +860,7 @@ sock_cb( /* If the packet is good, set the time and we're all done */ rc = handle_pkt(rpktl, &r_pkt, &spkt->addr, spkt->dctx->name); if (0 != rc) - DPRINTF(1, ("sock_cb: handle_pkt() returned %d\n", rc)); + TRACE(1, ("sock_cb: handle_pkt() returned %d\n", rc)); check_exit_conditions(); } @@ -879,8 +879,8 @@ check_exit_conditions(void) event_base_loopexit(base, NULL); shutting_down = TRUE; } else { - DPRINTF(2, ("%d NTP and %d name queries pending\n", - n_pending_ntp, n_pending_dns)); + TRACE(2, ("%d NTP and %d name queries pending\n", + n_pending_ntp, n_pending_dns)); } } @@ -1159,8 +1159,8 @@ handle_pkt( break; case 1: - DPRINTF(3, ("handle_pkt: %d bytes from %s %s\n", - rpktl, stoa(host), hostname)); + TRACE(3, ("handle_pkt: %d bytes from %s %s\n", + rpktl, stoa(host), hostname)); gettimeofday_cached(base, &tv_dst); @@ -1236,7 +1236,7 @@ offset_calculation( NTOHL_FP(&rpkt->xmt, &p_xmt); *precision = LOGTOD(rpkt->precision); - DPRINTF(3, ("offset_calculation: precision: %f\n", *precision)); + TRACE(3, ("offset_calculation: precision: %f\n", *precision)); *root_dispersion = FPTOD(p_rdsp); @@ -1270,9 +1270,9 @@ offset_calculation( *offset = (t21 + t34) / 2.; delta = t21 - t34; - DPRINTF(3, ("sntp offset_calculation:\trec - org t21: %.6f\n" - "\txmt - dst t34: %.6f\tdelta: %.6f\toffset: %.6f\n", - t21, t34, delta, *offset)); + TRACE(3, ("sntp offset_calculation:\trec - org t21: %.6f\n" + "\txmt - dst t34: %.6f\tdelta: %.6f\toffset: %.6f\n", + t21, t34, delta, *offset)); } diff --git a/sntp/networking.c b/sntp/networking.c index f3f966705..7fea4df00 100644 --- a/sntp/networking.c +++ b/sntp/networking.c @@ -34,7 +34,7 @@ sendpkt ( /* oh well */ } } else { - DPRINTF(3, ("Packet sent.\n")); + TRACE(3, ("Packet sent.\n")); } } @@ -164,8 +164,8 @@ unusable: } /* Yay! Things worked out! */ is_authentic = TRUE; - DPRINTF(1, ("sntp %s: packet from %s authenticated using key id %d.\n", - func_name, stoa(sender), key_id)); + TRACE(1, ("sntp %s: packet from %s authenticated using key id %d.\n", + func_name, stoa(sender), key_id)); break; default: @@ -209,11 +209,11 @@ unusable: if (STRATUM_PKT_UNSPEC == rpkt->stratum) { char *ref_char; - DPRINTF(1, ("%s: Stratum unspecified, going to check for KOD (stratum: %d)\n", - func_name, rpkt->stratum)); + TRACE(1, ("%s: Stratum unspecified, going to check for KOD (stratum: %d)\n", + func_name, rpkt->stratum)); ref_char = (char *) &rpkt->refid; - DPRINTF(1, ("%s: Packet refid: %c%c%c%c\n", func_name, - ref_char[0], ref_char[1], ref_char[2], ref_char[3])); + TRACE(1, ("%s: Packet refid: %c%c%c%c\n", func_name, + ref_char[0], ref_char[1], ref_char[2], ref_char[3])); /* If it's a KOD packet we'll just use the KOD information */ if (ref_char[0] != 'X') { if (strncmp(ref_char, "DENY", 4) == 0) diff --git a/sntp/sntp.c b/sntp/sntp.c index bdc8e4e7f..3e6255728 100644 --- a/sntp/sntp.c +++ b/sntp/sntp.c @@ -2,12 +2,10 @@ #include "main.h" -volatile int debug; - int main ( - int argc, - char **argv + int argc, + char ** argv ) { return sntp_main(argc, argv); diff --git a/sntp/tests/Makefile.am b/sntp/tests/Makefile.am index 93f84c833..8a26ad751 100644 --- a/sntp/tests/Makefile.am +++ b/sntp/tests/Makefile.am @@ -21,7 +21,6 @@ sntp_SOURCES_USED = \ base_SOURCES = \ $(srcdir)/../tests_main.cpp \ - sntptest.cpp \ $(NULL) tests_SOURCES = \ diff --git a/sntp/tests/sntptest.cpp b/sntp/tests/sntptest.cpp deleted file mode 100644 index 8cc89857e..000000000 --- a/sntp/tests/sntptest.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "sntptest.h" - -/* - * This file contains various constants that libntp needs to be set - * and that is normally defined in ntpd/ntpq/... - */ - -volatile int debug = 0; diff --git a/tests/libntp/libntptest.cpp b/tests/libntp/libntptest.cpp index 7d3afdf3d..c3363b008 100644 --- a/tests/libntp/libntptest.cpp +++ b/tests/libntp/libntptest.cpp @@ -5,7 +5,6 @@ */ u_long current_time = 4; // needed by authkeys. Used only in to calculate lifetime. -volatile int debug = 0; const char *progname = "libntptest"; time_t libntptest::nowtime = 0; diff --git a/util/jitter.c b/util/jitter.c index 20c63ad7d..62a84ade3 100644 --- a/util/jitter.c +++ b/util/jitter.c @@ -21,7 +21,6 @@ #define JAN_1970 2208988800UL /* Unix base epoch */ #define CLOCK_GETTIME /* Solaris hires clock */ -int debug; char progname[10]; double sys_residual; double average; diff --git a/util/ntp-keygen.c b/util/ntp-keygen.c index b0ed88c7a..0b78728b6 100644 --- a/util/ntp-keygen.c +++ b/util/ntp-keygen.c @@ -156,7 +156,6 @@ u_long asn2ntp (ASN1_TIME *); */ extern char *optarg; /* command line argument */ char *progname; -volatile int debug = 0; /* debug, not de bug */ u_int lifetime = YEAR; /* certificate lifetime (days) */ int nkeys; /* MV keys */ time_t epoch; /* Unix epoch (seconds) since 1970 */ diff --git a/util/ntptime.c b/util/ntptime.c index 7202dfb58..4ca823492 100644 --- a/util/ntptime.c +++ b/util/ntptime.c @@ -67,7 +67,6 @@ static volatile int pll_control; /* (0) daemon, (1) kernel loop */ static volatile int status; /* most recent status bits */ static volatile int flash; /* most recent ntp_adjtime() bits */ char* progname; -volatile int debug; /* for libntp */ static char optargs[] = "MNT:cde:f:hm:o:rs:t:"; int diff --git a/util/tickadj.c b/util/tickadj.c index 7bfde4d28..05b6191c5 100644 --- a/util/tickadj.c +++ b/util/tickadj.c @@ -213,7 +213,6 @@ main( #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) char *progname; -volatile int debug; int dokmem = 1; int writetickadj = 0;