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
+* 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 <stenn@ntp.org>
* [Bug 1839] 4.2.7p135 still installs libevent ev*.h headers.
(4.2.7p135) 2011/03/02 Released by Harlan Stenn <stenn@ntp.org>
#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 */
int height;
char *progname;
-volatile int debug;
static void doit (double, double, double, double, double, char *);
static double latlong (char *, int);
ascii.h \
audio.h \
binio.h \
+ declcond.h \
gps.h \
hopf6039.h \
icom.h \
--- /dev/null
+/*
+ * 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 */
#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 */
#include <sys/socket.h>
#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"
* 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 */
* -----------------------------------------
*/
+/*
+ * 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
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
/*
* 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.
int rc;
int saved_errno;
- DPRINTF(1, ("In ntp_set_tod\n"));
+ TRACE(1, ("In ntp_set_tod\n"));
rc = -1;
saved_errno = 0;
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;
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;
}
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
*/
} 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");
}
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);
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)));
}
}
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,
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);
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),
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)));
}
}
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);
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 */
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);
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)));
}
}
}
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;
}
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));
}
/*
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);
"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);
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)
* 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
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
} 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)));
/*
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
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);
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;
}
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",
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;
}
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);
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;
}
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;
&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;
/* 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);
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 = \
#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
--- /dev/null
+/*
+ * 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 */
/* for libntp */
const char * progname = "keyword-gen";
-volatile int debug = 1;
int main (int, char **);
static void generate_preamble (void);
fprintf(stderr, "Usage:\n%s t_header.h\n", argv[0]);
exit(1);
}
+ debug = 1;
+
populate_symb(argv[1]);
generate_preamble();
#include <errno.h>
#include <string.h>
+#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"
/* 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;
/*
*/
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
*/
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
#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
*/
extern struct xcmd opcmds[];
char *progname;
-volatile int debug;
#ifdef NO_MAIN_ALLOWED
CALL(ntpdc,"ntpdc",ntpdcmain);
extern struct xcmd opcmds[];
char *progname;
-volatile int debug;
#ifdef NO_MAIN_ALLOWED
#ifndef BUILD_AS_LIB
int len;
int first;
char *data;
+ int errcode;
/*
* This is pretty tricky. We may get between 1 and MAXFRAG packets
* 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;
}
* 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.
* 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;
}
}
}
- 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;
}
* 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;
}
}
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;
}
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;
}
}
#endif
/* +++++++++++++++++++++++ from iphlpapi.h */
-#endif /* !_W64 */
#pragma warning(pop)
+#endif /* !_W64 */
#endif /* GAA_COMPAT_H */
+++ /dev/null
-/*
- * 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 <config.h>
-#include <ws2tcpip.h>
-#include <nspapi.h>
-#include <svcguid.h>
-#include <ntp_rfc2553.h>
-#include <malloc.h>
-#include <ntp_stdlib.h>
-#include <syslog.h>
-
-/*
- * 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);
-}
-
+++ /dev/null
-/*
- * mexit - Used to exit the NTPD daemon
- *
- */
-
-#include <windows.h>
-#include <stdio.h>
-
-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);
- }
-}
-
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());
#include <config.h>
#include <io.h>
#include <stdio.h>
-#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: */
* equanimously.
*/
- DPRINTF(1, ("common_serial_open given %s\n", dev));
+ TRACE(1, ("common_serial_open given %s\n", dev));
pch = NULL;
if ('/' == dev[0]) {
}
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;
}
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(
static int glb_argc;
static char **glb_argv;
HANDLE hServDoneEvent = NULL;
-extern volatile int debug;
extern int accept_wildcard_if_for_winnt;
/*
RelativePath="..\..\include\config.h"
>
</File>
+ <File
+ RelativePath="..\..\..\..\include\declcond.h"
+ >
+ </File>
<File
RelativePath="..\..\..\..\lib\isc\include\isc\event.h"
>
>
</File>
<File
- RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
+ RelativePath="..\..\include\sys\time.h"
>
</File>
<File
- RelativePath="..\..\include\sys\time.h"
+ RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
>
</File>
<File
RelativePath="..\..\include\config.h"
>
</File>
+ <File
+ RelativePath="..\..\..\..\ntpd\declcond.h"
+ >
+ </File>
<File
RelativePath="..\..\include\hopf_PCI_io.h"
>
char *str_ptr;
char error = 0;
- DPRINTF(2, ("Initializing KOD DB...\n"));
+ TRACE(2, ("Initializing KOD DB...\n"));
kod_db_file = estrdup(db_file);
}
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);
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);
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);
/* 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))
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;
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) {
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));
}
}
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)
}
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));
}
}
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:
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);
}
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)));
}
}
/* 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);
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)
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)) {
/* 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();
}
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));
}
}
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);
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);
*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));
}
/* oh well */
}
} else {
- DPRINTF(3, ("Packet sent.\n"));
+ TRACE(3, ("Packet sent.\n"));
}
}
}
/* 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:
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)
#include "main.h"
-volatile int debug;
-
int
main (
- int argc,
- char **argv
+ int argc,
+ char ** argv
)
{
return sntp_main(argc, argv);
base_SOURCES = \
$(srcdir)/../tests_main.cpp \
- sntptest.cpp \
$(NULL)
tests_SOURCES = \
+++ /dev/null
-#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;
*/
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;
#define JAN_1970 2208988800UL /* Unix base epoch */
#define CLOCK_GETTIME /* Solaris hires clock */
-int debug;
char progname[10];
double sys_residual;
double average;
*/
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 */
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
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
char *progname;
-volatile int debug;
int dokmem = 1;
int writetickadj = 0;