Commit ea3fb054 authored by Dave Hart's avatar Dave Hart

[Bug 47] Debugging and logging do not work after a fork.

[Bug 1010] getaddrinfo() could block and thus should not be called by
the main thread/process.

#include <config.h> from all .c files and do not include it  from any .h files.

Previously config.h appeared a dozen times in preprocessed output of
some .c files.

handle relative path to logfile correctly despite
re-opening after fork() with a different curdir.

eliminate hand-crafted byte-swapping code from refclock_palisade.c in
preference to using htonl(), htons().  Tested by Fernando
Hauscarriaga.
parent 40c072dd
......@@ -14,8 +14,10 @@
# Simulated bk default ignores end here
*/autom4te.cache -prune
*~
./A.*
.buildkey
*.vcproj.*.user
./A.* -prune
./.buildkey-*
./.flockbuild-*
COPYRIGHT
CommitLog
ElectricFence/Makefile.in
......
* [Bug 47] Debugging and logging do not work after a fork.
* [Bug 1010] getaddrinfo() could block and thus should not be called by
the main thread/process.
(4.2.7p10) 2010/01/24 Released by Harlan Stenn <stenn@ntp.org>
* [Bug 1140] Clean up debug.html, decode.html, and ntpq.html.
* Include (4.2.6p1-RC3) - Use TZ=UTC instead of TZ= when calling date in
......
......@@ -128,6 +128,7 @@ esac
LIBOPTS_CHECK(libopts)
AC_FUNC_FORK
AC_FUNC_ALLOCA
AC_CACHE_CHECK(
[if $CC can handle @%:@warning],
......@@ -1168,7 +1169,7 @@ case "$host" in
AC_CHECK_FUNCS([clock_gettime clock_settime])
;;
esac
AC_CHECK_FUNCS(daemon)
AC_CHECK_FUNCS(closefrom daemon)
AC_CHECK_FUNCS(finite, ,
[AC_CHECK_FUNCS(isfinite, ,
[AC_MSG_CHECKING([for isfinite with <math.h>])
......@@ -1366,9 +1367,24 @@ case "$host" in
*-*-openbsd*)
# Just stubs. Idiots.
;;
*) AC_CHECK_FUNCS(timer_create timer_settime)
*) AC_CHECK_FUNCS(timer_create)
;;
esac
# some OSes prefer _exit() in forked children to exit()
AC_CHECK_FUNCS(_exit)
ntp_worker_child_exit=exit
case "$ac_cv_func__exit::$host_os" in
yes::netbsd*)
ntp_worker_child_exit=_exit
;;
yes::openbsd*)
ntp_worker_child_exit=_exit
;;
esac
AC_DEFINE_UNQUOTED([WORKER_CHILD_EXIT], [$ntp_worker_child_exit],
[routine worker child proc uses to exit.])
case "$host" in
*-pc-cygwin*)
# I have no idea...
......@@ -2114,22 +2130,6 @@ case "$ans" in
esac
AC_MSG_RESULT([$ans])
AC_MSG_CHECKING([if ntpd will use the deferred DNS lookup path])
AC_ARG_ENABLE(
[force-defer-DNS],
AS_HELP_STRING(
[--enable-force-defer-DNS],
[- force all DNS lookups to take the deferred path]
),
[ans=$enableval],
[ans=no]
)
case "$ans" in
yes)
AC_DEFINE(FORCE_DEFER_DNS, 1, [Force deferred DNS lookups?])
esac
AC_MSG_RESULT([$ans])
AC_CACHE_CHECK([if we have the tty_clk line discipline/streams module],
ac_cv_var_tty_clk,
[case "$ac_cv_header_sys_clkdefs_h$ac_cv_hdr_def_tiocdcdtimestamp" in
......
......@@ -56,6 +56,8 @@ noinst_HEADERS = \
ntp_tty.h \
ntp_types.h \
ntp_unixtime.h \
ntp_worker.h \
ntp_workimpl.h \
ntpd.h \
ntpsim.h \
parse.h \
......
#if !defined _ntp_iosignaled_h
#define _ntp_iosignaled_h
#ifndef IOSIGNAL_H
#define IOSIGNAL_H
#include "ntp_refclock.h"
/*
* Some systems (MOST) define SIGPOLL == SIGIO, others SIGIO == SIGPOLL, and
* a few have separate SIGIO and SIGPOLL signals. This code checks for the
* SIGIO == SIGPOLL case at compile time.
* Do not define USE_SIGPOLL or USE_SIGIO.
* these are interal only to iosignal.c and ntpd/work_fork.c!
*/
#if defined(USE_SIGPOLL)
# undef USE_SIGPOLL
#endif
#if defined(USE_SIGIO)
# undef USE_SIGIO
#endif
#if defined(HAVE_SIGNALED_IO)
# if defined(USE_TTY_SIGPOLL) || defined(USE_UDP_SIGPOLL)
# define USE_SIGPOLL
# endif
# if !defined(USE_TTY_SIGPOLL) || !defined(USE_UDP_SIGPOLL)
# define USE_SIGIO
# endif
# if defined(USE_SIGIO) && defined(USE_SIGPOLL)
# if SIGIO == SIGPOLL
# define USE_SIGIO
# undef USE_SIGPOLL
# endif /* SIGIO == SIGPOLL */
# endif /* USE_SIGIO && USE_SIGPOLL */
extern void block_sigio (void);
extern void unblock_sigio (void);
extern int init_clock_sig (struct refclockio *);
......@@ -14,10 +43,9 @@ RETSIGTYPE sigio_handler (int);
# define BLOCKIO() block_sigio()
# define UNBLOCKIO() unblock_sigio()
#else
# define BLOCKIO()
# define UNBLOCKIO()
#endif /* HAVE_SIGNALED_IO */
#else /* !HAVE_SIGNALED_IO follows */
# define BLOCKIO() do {} while (0)
# define UNBLOCKIO() do {} while (0)
#endif
#endif /* IOSIGNAL_H */
......@@ -3,12 +3,8 @@
* This is optional
*/
#ifndef _l_stdlib_h
#define _l_stdlib_h
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef L_STDLIB_H
#define L_STDLIB_H
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
......@@ -111,7 +107,7 @@ extern int rename (const char *, const char *);
#endif
#ifdef DECL_SELECT_0
#ifdef _ntp_select_h
#ifdef NTP_SELECT_H
extern int select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
#endif
#endif
......@@ -235,4 +231,4 @@ extern int errno;
extern int h_errno;
#endif
#endif /* l_stdlib_h */
#endif /* L_STDLIB_H */
......@@ -4,14 +4,14 @@
* structures used by the ntp configuration code and the discrete event
* simulator.
*
* Written By: Sachin Kamboj
* University of Delaware
* Newark, DE 19711
* Written By: Sachin Kamboj
* University of Delaware
* Newark, DE 19711
* Copyright (c) 2006
*/
#ifndef __NTP_DATA_STRUCTURES_H__
#define __NTP_DATA_STRUCTURES_H__
#ifndef NTP_DATA_STRUCTURES_H
#define NTP_DATA_STRUCTURES_H
/* Structures for storing a priority queue
......@@ -25,29 +25,55 @@ typedef struct node {
} nodeu;
} node;
#define node_next nodeu.next
typedef struct Queue {
int (*get_order)(void *, void *);
node *front;
int no_of_elements;
int (*get_order)(void *, void *);
node *front;
int no_of_elements;
} queue;
/* FUNCTION PROTOTYPES
* -------------------
*/
queue *create_priority_queue(int (*get_order)(void *, void *));
/* Define a function to create a FIFO queue */
#define create_queue() create_priority_queue(&get_fifo_order)
void destroy_queue(queue *my_queue);
void *get_node(size_t size);
void free_node(void *my_node);
void *next_node(void *my_node);
int empty(queue *my_queue);
void *queue_head(queue *my_queue);
queue *enqueue(queue *my_queue, void *my_node);
void append_queue(queue *q1, queue *q2);
void *dequeue(queue *my_queue);
int get_no_of_elements(queue *my_queue);
void append_queue(queue *q1, queue *q2);
int get_fifo_order(void *el1, void *el2);
queue *create_queue(void);
/*
* Preserve original callsite __FILE__ and __LINE__ for these
* malloc-like funcs when using MS C runtime debug heap.
*/
#ifdef _CRTDBG_MAP_ALLOC
# define create_priority_queue(order) debug_create_priority_queue(order, __FILE__, __LINE__)
# define get_node(size) debug_get_node(size, __FILE__, __LINE__)
#else
# define create_priority_queue(order) debug_create_priority_queue(order)
# define get_node(size) debug_get_node(size)
#endif
queue *debug_create_priority_queue(
int (*get_order)(void *, void *)
#ifdef _CRTDBG_MAP_ALLOC
, const char *, int /* __FILE__, __LINE__ */
#endif
);
void *debug_get_node(
size_t
#ifdef _CRTDBG_MAP_ALLOC
, const char *, int /* __FILE__, __LINE__ */
#endif
);
#endif /* NTP_DATA_STRUCTURES_H */
......@@ -342,12 +342,12 @@ extern int buftvtots (const char *, l_fp *);
extern char * fptoa (s_fp, short);
extern char * fptoms (s_fp, short);
extern int hextolfp (const char *, l_fp *);
extern void gpstolfp (int, int, unsigned long, l_fp *);
extern void gpstolfp (int, int, unsigned long, l_fp *);
extern int mstolfp (const char *, l_fp *);
extern char * prettydate (l_fp *);
extern char * gmprettydate (l_fp *);
extern char * uglydate (l_fp *);
extern void mfp_mul (int32 *, u_int32 *, int32, u_int32, int32, u_int32);
extern void mfp_mul (int32 *, u_int32 *, int32, u_int32, int32, u_int32);
extern void get_systime (l_fp *);
extern int step_systime (double);
......
#ifndef NTP_INTRES_H
#define NTP_INTRES_H
/*
* Some systems do not support fork() and don't have an alternate
* threads implementation of ntp_intres. Such systems are limited
* to using numeric IP addresses.
*/
#if defined(VMS) || defined (SYS_VXWORKS) || \
(!defined(HAVE_WORKING_FORK) && !defined(SYS_WINNT))
#define NO_INTRES
#endif
#endif /* !defined(NTP_INTRES_H) */
#include "ntp_worker.h"
#ifdef WORKER
extern int blocking_getaddrinfo(blocking_pipe_header *);
extern int blocking_getnameinfo(blocking_pipe_header *);
#ifdef TEST_BLOCKING_WORKER
extern void gai_test_callback(int rescode, int gai_errno,
void *context, const char *name,
const char *service,
const struct addrinfo *hints,
const struct addrinfo *ai_res);
extern void gni_test_callback(int rescode, int gni_errno,
sockaddr_u *psau, int flags,
const char *host,
const char *service, void *context);
#endif /* TEST_BLOCKING_WORKER */
#endif /* WORKER */
#endif /* !NTP_INTRES_H */
#ifndef NTP_IO_H
#define NTP_IO_H
#include "ntp_workimpl.h"
/*
* POSIX says use <fnct.h> to get O_* symbols and
* SEEK_SET symbol form <unistd.h>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
......@@ -69,7 +68,6 @@ typedef enum {
MATCH_IFADDR
} nic_rule_match;
/*
* NIC rule actions
*/
......@@ -80,10 +78,18 @@ typedef enum {
} nic_rule_action;
SOCKET move_fd(SOCKET fd);
isc_boolean_t get_broadcastclient_flag(void);
isc_boolean_t is_ip_address(const char *, isc_netaddr_t *);
extern void sau_from_netaddr(sockaddr_u *, const isc_netaddr_t *);
extern void add_nic_rule(nic_rule_match match_type, const char *if_name,
int prefixlen, nic_rule_action action);
extern void add_nic_rule(nic_rule_match match_type,
const char *if_name, int prefixlen,
nic_rule_action action);
#ifndef HAVE_IO_COMPLETION_PORT
extern void close_all_beyond(int);
#endif
#ifdef WORK_FORK
extern void update_resp_pipe_fd(int, int);
#endif
#endif /* NTP_IO_H */
......@@ -38,10 +38,6 @@
#ifndef NTP_LISTS_H
#define NTP_LISTS_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <isc/list.h>
......
/*
* ntp_machine.h
*
* Collect all machine dependent idiosyncrasies in one place.
*
* The functionality formerly in this file is mostly handled by
* Autoconf these days.
*/
#ifndef NTP_MACHINE_H
#define NTP_MACHINE_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
......@@ -26,9 +27,6 @@
HEY! CHECK THIS OUT!
The first half of this file is obsolete, and is only there to help
reconcile "what went before" with "current behavior".
The per-system SYS_* #defins ARE NO LONGER USED, with the temporary
exception of SYS_WINNT.
......@@ -84,141 +82,6 @@ MISC
# define ntp_adjtime __adjtimex
#endif
#if 0
/*
* IRIX 4.X and IRIX 5.x
*/
#if defined(SYS_IRIX4)||defined(SYS_IRIX5)
# define ADJTIME_IS_ACCURATE
# define LOCK_PROCESS
#endif
/*
* Ultrix
* Note: posix version has NTP_POSIX_SOURCE and HAVE_SIGNALED_IO
*/
#if defined(SYS_ULTRIX)
# define S_CHAR_DEFINED
# define NTP_SYSCALLS_STD
# define HAVE_MODEM_CONTROL
#endif
/*
* AUX
*/
#if defined(SYS_AUX2) || defined(SYS_AUX3)
# define NO_SIGNED_CHAR_DECL
# define LOCK_PROCESS
# define NTP_POSIX_SOURCE
/*
* This requires that _POSIX_SOURCE be forced on the
* compiler command flag. We can't do it here since this
* file is included _after_ the system header files and we
* need to let _them_ know we're POSIX. We do this in
* compilers/aux3.gcc...
*/
# define LOG_NTP LOG_LOCAL1
#endif
/*
* HPUX
*/
#if defined(SYS_HPUX)
# define getdtablesize() sysconf(_SC_OPEN_MAX)
# define setlinebuf(f) setvbuf(f, NULL, _IOLBF, 0)
# define NO_SIGNED_CHAR_DECL
# define LOCK_PROCESS
#endif
/*
* BSD/OS 2.0 and above
*/
#if defined(SYS_BSDI)
# define USE_FSETOWNCTTY /* this funny system demands a CTTY for FSETOWN */
#endif
/*
* FreeBSD 2.0 and above
*/
#ifdef SYS_FREEBSD
# define KERNEL_PLL
#endif
/*
* Linux
*/
#if defined(SYS_LINUX)
# define ntp_adjtime __adjtimex
#endif
/*
* PTX
*/
#if defined(SYS_PTX)
# define LOCK_PROCESS
struct timezone { int __0; }; /* unused placebo */
/*
* no comment !@!
*/
typedef unsigned int u_int;
# ifndef _NETINET_IN_SYSTM_INCLUDED /* i am about to comment... */
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned long u_long;
# endif
#endif
/*
* UNIX V.4 on and NCR 3000
*/
#if defined(SYS_SVR4)
# define STREAM
# define LOCK_PROCESS
# define SIZE_RETURNED_IN_BUFFER
#endif
/*
* (Univel/Novell) Unixware1 SVR4 on intel x86 processor
*/
#if defined(SYS_UNIXWARE1)
/* #define _POSIX_SOURCE */
# define STREAM
# define STREAMS
# undef STEP_SLEW /* TWO step */
# define LOCK_PROCESS
# define SIZE_RETURNED_IN_BUFFER
# include <sys/sockio.h>
# include <sys/types.h>
# include <netinet/in_systm.h>
#endif
/*
* DomainOS
*/
#if defined(SYS_DOMAINOS)
# define NTP_SYSCALLS_STD
/* older versions of domain/os don't have class D */
# ifndef IN_CLASSD
# define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
# define IN_CLASSD_NET 0xf0000000
# define IN_CLASSD_NSHIFT 28
# define IN_CLASSD_HOST 0xfffffff
# define IN_MULTICAST(i) IN_CLASSD(i)
# endif
#endif
/*
* Fujitsu UXP/V
*/
#if defined(SYS_UXPV)
# define LOCK_PROCESS
# define SIZE_RETURNED_IN_BUFFER
#endif
#endif /* 0 */
/*
* Define these here for non-Windows NT systems
* SOCKET and INVALID_SOCKET are native macros
......@@ -502,34 +365,7 @@ extern time_t timegm (struct tm *);
&& !defined(HAVE_TERMIOS)
#include "ERROR: no tty type defined!"
# endif
#endif /* SYS_WINNT || VMS || SYS_VXWORKS*/
#endif /* !SYS_WINNT && !VMS && !SYS_VXWORKS*/
#ifdef WORDS_BIGENDIAN
# define XNTP_BIG_ENDIAN 1
#else
# define XNTP_LITTLE_ENDIAN 1
#endif
/*
* Byte order woes.
* This used to be resolved by calling ntohl() and htonl() to swap things
* around, but this turned out to be quite costly on Vaxes where those
* things are actual functions. The code now straightens out byte
* order troubles on its own, with no performance penalty for little
* end first machines, but at great expense to cleanliness.
*/
#if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN)
/*
* Pick one or the other.
*/
BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
#endif
#if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN)
/*
* Pick one or the other.
*/
BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
#endif
#endif /* NTP_MACHINE_H */
......@@ -4,10 +4,6 @@
#ifndef NTP_MALLOC_H
#define NTP_MALLOC_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
......@@ -16,4 +12,33 @@
# endif
#endif
/*
* Deal with platform differences declaring alloca()
* This comes nearly verbatim from:
*
* http://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Functions
*
* The only modifications were to remove C++ support and guard against
* redefining alloca.
*/
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif defined __GNUC__
# ifndef alloca
# define alloca __builtin_alloca
# endif
#elif defined _AIX
# ifndef alloca
# define alloca __alloca
# endif
#elif defined _MSC_VER
# include <malloc.h>
# ifndef alloca
# define alloca _alloca
# endif
#else
# include <stddef.h>
void * alloca(size_t);
#endif
#endif /* NTP_MALLOC_H */
#ifndef __ntp_proto_h
#define __ntp_proto_h
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef NTP_PROTO_H
#define NTP_PROTO_H
#define NTP_MAXFREQ 500e-6
#endif /* __ntp_proto_h */
#endif /* NTP_PROTO_H */
......@@ -68,11 +68,6 @@
#ifndef NTP_RFC2553_H
#define NTP_RFC2553_H
/*
* Ensure that we include the configuration file before we check
* for IPV6
*/
#include <config.h>
#include <netdb.h>
#include <isc/net.h>
......
......@@ -2,39 +2,34 @@
* Not all machines define FD_SET in sys/types.h
*/
#ifndef NTP_SELECT_H
#define NTP_SELECT_H
#define NTP_SELECT_H /* note: tested by include/l_stdlib.h */
/* Was: (defined(RS6000)||defined(SYS_PTX))&&!defined(_BSD) */
/* Could say: !defined(FD_SET) && defined(HAVE_SYS_SELECT_H) */
/* except FD_SET can legitimately be a typedef... */
#if defined(HAVE_SYS_SELECT_H) && !defined(_BSD)
#ifndef SYS_VXWORKS
#include <sys/select.h>
#else
#include <sockLib.h>
extern int select (int width, fd_set *pReadFds, fd_set *pWriteFds,
fd_set *pExceptFds, struct timeval *pTimeOut);
#endif
# ifndef SYS_VXWORKS
# include <sys/select.h>
# else
# include <sockLib.h>
extern int select(int width, fd_set *pReadFds, fd_set *pWriteFds,
fd_set *pExceptFds, struct timeval *pTimeOut);
# endif
#endif
#if !defined(FD_SET)
#define NFDBITS 32
#define FD_SETSIZE 32
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
#define FD_ZERO(p) memset((char *)(p), 0, sizeof(*(p)))
# define NFDBITS 32
# define FD_SETSIZE 32
# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
# define FD_ZERO(p) memset((p), 0, sizeof(*(p)))
#endif
#if defined(VMS)
typedef struct {
unsigned int fds_bits[1];
unsigned int fds_bits[1];
} fd_set;
#endif
#ifdef SYS_WINNT
/* ports/winnt/libntp/setpriority.c */
extern void InitSockets(void);
#endif
#endif /* NTP_SELECT_H */
......@@ -10,7 +10,6 @@
#endif
#include "l_stdlib.h"
#include "ntp_rfc2553.h"
#include "ntp_types.h"
#include "ntp_string.h"
#include "ntp_net.h"
......@@ -88,6 +87,7 @@ extern int atoint (const char *, long *);
extern int atouint (const char *, u_long *);
extern int hextoint (const char *, u_long *);
extern char * humanlogtime (void);
extern char * humantime (time_t);
extern char * inttoa (long);
extern char * mfptoa (u_long, u_long, short);