diff options
Diffstat (limited to 'libntp')
75 files changed, 11042 insertions, 2605 deletions
diff --git a/libntp/Makefile.am b/libntp/Makefile.am index 3e7373ae3f3c8..c12658f5a18e8 100644 --- a/libntp/Makefile.am +++ b/libntp/Makefile.am @@ -1,10 +1,47 @@ NULL= -#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies -AUTOMAKE_OPTIONS = BUILT_SOURCES = CLEANFILES = noinst_LIBRARIES = libntp.a @MAKE_LIBNTPSIM@ EXTRA_LIBRARIES = libntpsim.a + +libisc_SRCS = \ + $(srcdir)/../lib/isc/assertions.c \ + $(srcdir)/../lib/isc/buffer.c \ + $(srcdir)/../lib/isc/backtrace-emptytbl.c \ + $(srcdir)/../lib/isc/backtrace.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c \ + $(srcdir)/../lib/isc/unix/dir.c \ + $(srcdir)/../lib/isc/error.c \ + $(srcdir)/../lib/isc/unix/errno2result.c \ + $(srcdir)/../lib/isc/event.c \ + $(srcdir)/../lib/isc/unix/file.c \ + $(srcdir)/../lib/isc/inet_ntop.c \ + $(srcdir)/../lib/isc/inet_pton.c \ + $(srcdir)/../lib/isc/unix/interfaceiter.c \ + $(srcdir)/../lib/isc/lib.c \ + $(srcdir)/../lib/isc/log.c \ + $(srcdir)/../lib/isc/md5.c \ + $(srcdir)/../lib/isc/nls/msgcat.c \ + $(srcdir)/../lib/isc/unix/net.c \ + $(srcdir)/../lib/isc/netaddr.c \ + $(srcdir)/../lib/isc/netscope.c \ + $(srcdir)/../lib/isc/ondestroy.c \ + $(srcdir)/../lib/isc/random.c \ + $(srcdir)/../lib/isc/result.c \ + $(srcdir)/../lib/isc/unix/stdio.c \ + $(srcdir)/../lib/isc/unix/stdtime.c \ + $(srcdir)/../lib/isc/unix/strerror.c \ + $(srcdir)/../lib/isc/task.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c \ + $(srcdir)/../lib/isc/unix/time.c \ + $(srcdir)/../lib/isc/sha1.c \ + $(srcdir)/../lib/isc/sockaddr.c \ + $(NULL) + +if PTHREADS +libisc_SRCS += $(srcdir)/../lib/isc/pthreads/mutex.c +endif + libntp_a_SRCS = \ a_md5encrypt.c \ adjtime.c \ @@ -27,87 +64,63 @@ libntp_a_SRCS = \ dolfptoa.c \ emalloc.c \ findconfig.c \ - fptoa.c \ - fptoms.c \ getopt.c \ hextoint.c \ hextolfp.c \ humandate.c \ icom.c \ - inttoa.c \ iosignal.c \ lib_strbuf.c \ machines.c \ - memmove.c \ - mfptoa.c \ - ntp_lineedit.c \ - mfptoms.c \ mktime.c \ modetoa.c \ mstolfp.c \ - msutotsf.c \ msyslog.c \ netof.c \ + ntp_calendar.c \ + ntp_crypto_rnd.c \ + ntp_intres.c \ ntp_libopts.c \ + ntp_lineedit.c \ + ntp_random.c \ ntp_rfc2553.c \ + ntp_worker.c \ numtoa.c \ numtohost.c \ octtoint.c \ prettydate.c \ - ntp_random.c \ recvbuff.c \ refnumtoa.c \ snprintf.c \ + socket.c \ socktoa.c \ socktohost.c \ ssl_init.c \ statestr.c \ strdup.c \ - strstr.c \ + strl_obsd.c \ syssignal.c \ - tsftomsu.c \ - tstotv.c \ - tvtots.c \ + timetoa.c \ + timevalops.c \ uglydate.c \ - uinttoa.c \ + vint64ops.c \ + work_fork.c \ + work_thread.c \ ymd2yd.c \ - $(srcdir)/../lib/isc/assertions.c \ - $(srcdir)/../lib/isc/buffer.c \ - $(srcdir)/../lib/isc/nothreads/condition.c \ - $(srcdir)/../lib/isc/unix/dir.c \ - $(srcdir)/../lib/isc/error.c \ - $(srcdir)/../lib/isc/unix/errno2result.c \ - $(srcdir)/../lib/isc/event.c \ - $(srcdir)/../lib/isc/unix/file.c \ - $(srcdir)/../lib/isc/inet_ntop.c \ - $(srcdir)/../lib/isc/inet_pton.c \ - $(srcdir)/../lib/isc/unix/interfaceiter.c \ - $(srcdir)/../lib/isc/lib.c \ - $(srcdir)/../lib/isc/log.c \ - $(srcdir)/../lib/isc/md5.c \ - $(srcdir)/../lib/isc/nls/msgcat.c \ - $(srcdir)/../lib/isc/unix/net.c \ - $(srcdir)/../lib/isc/netaddr.c \ - $(srcdir)/../lib/isc/netscope.c \ - $(srcdir)/../lib/isc/ondestroy.c \ - $(srcdir)/../lib/isc/random.c \ - $(srcdir)/../lib/isc/result.c \ - $(srcdir)/../lib/isc/unix/stdio.c \ - $(srcdir)/../lib/isc/unix/stdtime.c \ - $(srcdir)/../lib/isc/unix/strerror.c \ - $(srcdir)/../lib/isc/task.c \ - $(srcdir)/../lib/isc/nothreads/thread.c \ - $(srcdir)/../lib/isc/unix/time.c \ - $(srcdir)/../lib/isc/sockaddr.c \ + $(libisc_SRCS) \ $(NULL) + libntp_a_SOURCES = systime.c $(libntp_a_SRCS) libntpsim_a_SOURCES = systime_s.c $(libntp_a_SRCS) EXTRA_libntp_a_SOURCES = adjtimex.c -ETAGS_ARGS = Makefile.am -INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \ - -I$(top_srcdir)/lib/isc/nothreads/include \ - -I$(top_srcdir)/lib/isc/unix/include $(LIBOPTS_CFLAGS) + +AM_CFLAGS = $(CFLAGS_NTP) + +AM_CPPFLAGS = $(NTP_INCS) +AM_CPPFLAGS += $(LIBOPTS_CFLAGS) +AM_CPPFLAGS += $(CPPFLAGS_NTP) EXTRA_DIST = README include $(top_srcdir)/depsver.mf +include $(top_srcdir)/includes.mf diff --git a/libntp/Makefile.in b/libntp/Makefile.in index 62d53f9053529..39f287521e15b 100644 --- a/libntp/Makefile.in +++ b/libntp/Makefile.in @@ -34,21 +34,46 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ +@PTHREADS_TRUE@am__append_1 = $(srcdir)/../lib/isc/pthreads/mutex.c DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ - $(top_srcdir)/depsver.mf + $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf subdir = libntp ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \ - $(top_srcdir)/m4/define_dir.m4 $(top_srcdir)/m4/libtool.m4 \ - $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ - $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ - $(top_srcdir)/m4/ntp_cacheversion.m4 \ - $(top_srcdir)/m4/ntp_dir_sep.m4 \ - $(top_srcdir)/m4/ntp_lineeditlibs.m4 \ - $(top_srcdir)/m4/ntp_openssl.m4 \ - $(top_srcdir)/m4/ntp_vpathhack.m4 \ - $(top_srcdir)/m4/os_cflags.m4 $(top_srcdir)/version.m4 \ - $(top_srcdir)/configure.ac + $(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \ + $(top_srcdir)/sntp/libevent/m4/openldap-thread-check.m4 \ + $(top_srcdir)/sntp/libevent/m4/openldap.m4 \ + $(top_srcdir)/sntp/m4/define_dir.m4 \ + $(top_srcdir)/sntp/m4/hms_search_lib.m4 \ + $(top_srcdir)/sntp/m4/libtool.m4 \ + $(top_srcdir)/sntp/m4/ltoptions.m4 \ + $(top_srcdir)/sntp/m4/ltsugar.m4 \ + $(top_srcdir)/sntp/m4/ltversion.m4 \ + $(top_srcdir)/sntp/m4/lt~obsolete.m4 \ + $(top_srcdir)/sntp/m4/ntp_cacheversion.m4 \ + $(top_srcdir)/sntp/m4/ntp_compiler.m4 \ + $(top_srcdir)/sntp/m4/ntp_crosscompile.m4 \ + $(top_srcdir)/sntp/m4/ntp_crypto_rand.m4 \ + $(top_srcdir)/sntp/m4/ntp_debug.m4 \ + $(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \ + $(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \ + $(top_srcdir)/sntp/m4/ntp_googletest.m4 \ + $(top_srcdir)/sntp/m4/ntp_ipv6.m4 \ + $(top_srcdir)/sntp/m4/ntp_lib_m.m4 \ + $(top_srcdir)/sntp/m4/ntp_libevent.m4 \ + $(top_srcdir)/sntp/m4/ntp_libntp.m4 \ + $(top_srcdir)/sntp/m4/ntp_lineeditlibs.m4 \ + $(top_srcdir)/sntp/m4/ntp_locinfo.m4 \ + $(top_srcdir)/sntp/m4/ntp_openssl.m4 \ + $(top_srcdir)/sntp/m4/ntp_pkg_config.m4 \ + $(top_srcdir)/sntp/m4/ntp_prog_cc.m4 \ + $(top_srcdir)/sntp/m4/ntp_rlimit.m4 \ + $(top_srcdir)/sntp/m4/ntp_sntp.m4 \ + $(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \ + $(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \ + $(top_srcdir)/sntp/m4/os_cflags.m4 \ + $(top_srcdir)/sntp/m4/snprintf.m4 \ + $(top_srcdir)/sntp/m4/version.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -57,10 +82,68 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LIBRARIES = $(noinst_LIBRARIES) ARFLAGS = cru +AM_V_AR = $(am__v_AR_$(V)) +am__v_AR_ = $(am__v_AR_$(AM_DEFAULT_VERBOSITY)) +am__v_AR_0 = @echo " AR " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ libntp_a_AR = $(AR) $(ARFLAGS) libntp_a_LIBADD = +am__libntp_a_SOURCES_DIST = systime.c a_md5encrypt.c adjtime.c \ + atoint.c atolfp.c atouint.c audio.c authkeys.c authreadkeys.c \ + authusekey.c bsd_strerror.c buftvtots.c caljulian.c caltontp.c \ + calyearstart.c clocktime.c clocktypes.c decodenetnum.c \ + dofptoa.c dolfptoa.c emalloc.c findconfig.c getopt.c \ + hextoint.c hextolfp.c humandate.c icom.c iosignal.c \ + lib_strbuf.c machines.c mktime.c modetoa.c mstolfp.c msyslog.c \ + netof.c ntp_calendar.c ntp_crypto_rnd.c ntp_intres.c \ + ntp_libopts.c ntp_lineedit.c ntp_random.c ntp_rfc2553.c \ + ntp_worker.c numtoa.c numtohost.c octtoint.c prettydate.c \ + recvbuff.c refnumtoa.c snprintf.c socket.c socktoa.c \ + socktohost.c ssl_init.c statestr.c strdup.c strl_obsd.c \ + syssignal.c timetoa.c timevalops.c uglydate.c vint64ops.c \ + work_fork.c work_thread.c ymd2yd.c \ + $(srcdir)/../lib/isc/assertions.c \ + $(srcdir)/../lib/isc/buffer.c \ + $(srcdir)/../lib/isc/backtrace-emptytbl.c \ + $(srcdir)/../lib/isc/backtrace.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c \ + $(srcdir)/../lib/isc/unix/dir.c $(srcdir)/../lib/isc/error.c \ + $(srcdir)/../lib/isc/unix/errno2result.c \ + $(srcdir)/../lib/isc/event.c $(srcdir)/../lib/isc/unix/file.c \ + $(srcdir)/../lib/isc/inet_ntop.c \ + $(srcdir)/../lib/isc/inet_pton.c \ + $(srcdir)/../lib/isc/unix/interfaceiter.c \ + $(srcdir)/../lib/isc/lib.c $(srcdir)/../lib/isc/log.c \ + $(srcdir)/../lib/isc/md5.c $(srcdir)/../lib/isc/nls/msgcat.c \ + $(srcdir)/../lib/isc/unix/net.c $(srcdir)/../lib/isc/netaddr.c \ + $(srcdir)/../lib/isc/netscope.c \ + $(srcdir)/../lib/isc/ondestroy.c $(srcdir)/../lib/isc/random.c \ + $(srcdir)/../lib/isc/result.c \ + $(srcdir)/../lib/isc/unix/stdio.c \ + $(srcdir)/../lib/isc/unix/stdtime.c \ + $(srcdir)/../lib/isc/unix/strerror.c \ + $(srcdir)/../lib/isc/task.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c \ + $(srcdir)/../lib/isc/unix/time.c $(srcdir)/../lib/isc/sha1.c \ + $(srcdir)/../lib/isc/sockaddr.c \ + $(srcdir)/../lib/isc/pthreads/mutex.c am__objects_1 = -am__objects_2 = a_md5encrypt.$(OBJEXT) adjtime.$(OBJEXT) \ +@PTHREADS_TRUE@am__objects_2 = mutex.$(OBJEXT) +am__objects_3 = assertions.$(OBJEXT) buffer.$(OBJEXT) \ + backtrace-emptytbl.$(OBJEXT) backtrace.$(OBJEXT) \ + condition.$(OBJEXT) dir.$(OBJEXT) error.$(OBJEXT) \ + errno2result.$(OBJEXT) event.$(OBJEXT) file.$(OBJEXT) \ + inet_ntop.$(OBJEXT) inet_pton.$(OBJEXT) \ + interfaceiter.$(OBJEXT) lib.$(OBJEXT) log.$(OBJEXT) \ + md5.$(OBJEXT) msgcat.$(OBJEXT) net.$(OBJEXT) netaddr.$(OBJEXT) \ + netscope.$(OBJEXT) ondestroy.$(OBJEXT) random.$(OBJEXT) \ + result.$(OBJEXT) stdio.$(OBJEXT) stdtime.$(OBJEXT) \ + strerror.$(OBJEXT) task.$(OBJEXT) thread.$(OBJEXT) \ + time.$(OBJEXT) sha1.$(OBJEXT) sockaddr.$(OBJEXT) \ + $(am__objects_1) $(am__objects_2) +am__objects_4 = a_md5encrypt.$(OBJEXT) adjtime.$(OBJEXT) \ atoint.$(OBJEXT) atolfp.$(OBJEXT) atouint.$(OBJEXT) \ audio.$(OBJEXT) authkeys.$(OBJEXT) authreadkeys.$(OBJEXT) \ authusekey.$(OBJEXT) bsd_strerror.$(OBJEXT) \ @@ -68,71 +151,128 @@ am__objects_2 = a_md5encrypt.$(OBJEXT) adjtime.$(OBJEXT) \ calyearstart.$(OBJEXT) clocktime.$(OBJEXT) \ clocktypes.$(OBJEXT) decodenetnum.$(OBJEXT) dofptoa.$(OBJEXT) \ dolfptoa.$(OBJEXT) emalloc.$(OBJEXT) findconfig.$(OBJEXT) \ - fptoa.$(OBJEXT) fptoms.$(OBJEXT) getopt.$(OBJEXT) \ - hextoint.$(OBJEXT) hextolfp.$(OBJEXT) humandate.$(OBJEXT) \ - icom.$(OBJEXT) inttoa.$(OBJEXT) iosignal.$(OBJEXT) \ - lib_strbuf.$(OBJEXT) machines.$(OBJEXT) memmove.$(OBJEXT) \ - mfptoa.$(OBJEXT) ntp_lineedit.$(OBJEXT) mfptoms.$(OBJEXT) \ - mktime.$(OBJEXT) modetoa.$(OBJEXT) mstolfp.$(OBJEXT) \ - msutotsf.$(OBJEXT) msyslog.$(OBJEXT) netof.$(OBJEXT) \ - ntp_libopts.$(OBJEXT) ntp_rfc2553.$(OBJEXT) numtoa.$(OBJEXT) \ - numtohost.$(OBJEXT) octtoint.$(OBJEXT) prettydate.$(OBJEXT) \ - ntp_random.$(OBJEXT) recvbuff.$(OBJEXT) refnumtoa.$(OBJEXT) \ - snprintf.$(OBJEXT) socktoa.$(OBJEXT) socktohost.$(OBJEXT) \ - ssl_init.$(OBJEXT) statestr.$(OBJEXT) strdup.$(OBJEXT) \ - strstr.$(OBJEXT) syssignal.$(OBJEXT) tsftomsu.$(OBJEXT) \ - tstotv.$(OBJEXT) tvtots.$(OBJEXT) uglydate.$(OBJEXT) \ - uinttoa.$(OBJEXT) ymd2yd.$(OBJEXT) assertions.$(OBJEXT) \ - buffer.$(OBJEXT) condition.$(OBJEXT) dir.$(OBJEXT) \ - error.$(OBJEXT) errno2result.$(OBJEXT) event.$(OBJEXT) \ - file.$(OBJEXT) inet_ntop.$(OBJEXT) inet_pton.$(OBJEXT) \ - interfaceiter.$(OBJEXT) lib.$(OBJEXT) log.$(OBJEXT) \ - md5.$(OBJEXT) msgcat.$(OBJEXT) net.$(OBJEXT) netaddr.$(OBJEXT) \ - netscope.$(OBJEXT) ondestroy.$(OBJEXT) random.$(OBJEXT) \ - result.$(OBJEXT) stdio.$(OBJEXT) stdtime.$(OBJEXT) \ - strerror.$(OBJEXT) task.$(OBJEXT) thread.$(OBJEXT) \ - time.$(OBJEXT) sockaddr.$(OBJEXT) $(am__objects_1) -am_libntp_a_OBJECTS = systime.$(OBJEXT) $(am__objects_2) + getopt.$(OBJEXT) hextoint.$(OBJEXT) hextolfp.$(OBJEXT) \ + humandate.$(OBJEXT) icom.$(OBJEXT) iosignal.$(OBJEXT) \ + lib_strbuf.$(OBJEXT) machines.$(OBJEXT) mktime.$(OBJEXT) \ + modetoa.$(OBJEXT) mstolfp.$(OBJEXT) msyslog.$(OBJEXT) \ + netof.$(OBJEXT) ntp_calendar.$(OBJEXT) \ + ntp_crypto_rnd.$(OBJEXT) ntp_intres.$(OBJEXT) \ + ntp_libopts.$(OBJEXT) ntp_lineedit.$(OBJEXT) \ + ntp_random.$(OBJEXT) ntp_rfc2553.$(OBJEXT) \ + ntp_worker.$(OBJEXT) numtoa.$(OBJEXT) numtohost.$(OBJEXT) \ + octtoint.$(OBJEXT) prettydate.$(OBJEXT) recvbuff.$(OBJEXT) \ + refnumtoa.$(OBJEXT) snprintf.$(OBJEXT) socket.$(OBJEXT) \ + socktoa.$(OBJEXT) socktohost.$(OBJEXT) ssl_init.$(OBJEXT) \ + statestr.$(OBJEXT) strdup.$(OBJEXT) strl_obsd.$(OBJEXT) \ + syssignal.$(OBJEXT) timetoa.$(OBJEXT) timevalops.$(OBJEXT) \ + uglydate.$(OBJEXT) vint64ops.$(OBJEXT) work_fork.$(OBJEXT) \ + work_thread.$(OBJEXT) ymd2yd.$(OBJEXT) $(am__objects_3) \ + $(am__objects_1) +am_libntp_a_OBJECTS = systime.$(OBJEXT) $(am__objects_4) libntp_a_OBJECTS = $(am_libntp_a_OBJECTS) libntpsim_a_AR = $(AR) $(ARFLAGS) libntpsim_a_LIBADD = -am_libntpsim_a_OBJECTS = systime_s.$(OBJEXT) $(am__objects_2) +am__libntpsim_a_SOURCES_DIST = systime_s.c a_md5encrypt.c adjtime.c \ + atoint.c atolfp.c atouint.c audio.c authkeys.c authreadkeys.c \ + authusekey.c bsd_strerror.c buftvtots.c caljulian.c caltontp.c \ + calyearstart.c clocktime.c clocktypes.c decodenetnum.c \ + dofptoa.c dolfptoa.c emalloc.c findconfig.c getopt.c \ + hextoint.c hextolfp.c humandate.c icom.c iosignal.c \ + lib_strbuf.c machines.c mktime.c modetoa.c mstolfp.c msyslog.c \ + netof.c ntp_calendar.c ntp_crypto_rnd.c ntp_intres.c \ + ntp_libopts.c ntp_lineedit.c ntp_random.c ntp_rfc2553.c \ + ntp_worker.c numtoa.c numtohost.c octtoint.c prettydate.c \ + recvbuff.c refnumtoa.c snprintf.c socket.c socktoa.c \ + socktohost.c ssl_init.c statestr.c strdup.c strl_obsd.c \ + syssignal.c timetoa.c timevalops.c uglydate.c vint64ops.c \ + work_fork.c work_thread.c ymd2yd.c \ + $(srcdir)/../lib/isc/assertions.c \ + $(srcdir)/../lib/isc/buffer.c \ + $(srcdir)/../lib/isc/backtrace-emptytbl.c \ + $(srcdir)/../lib/isc/backtrace.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c \ + $(srcdir)/../lib/isc/unix/dir.c $(srcdir)/../lib/isc/error.c \ + $(srcdir)/../lib/isc/unix/errno2result.c \ + $(srcdir)/../lib/isc/event.c $(srcdir)/../lib/isc/unix/file.c \ + $(srcdir)/../lib/isc/inet_ntop.c \ + $(srcdir)/../lib/isc/inet_pton.c \ + $(srcdir)/../lib/isc/unix/interfaceiter.c \ + $(srcdir)/../lib/isc/lib.c $(srcdir)/../lib/isc/log.c \ + $(srcdir)/../lib/isc/md5.c $(srcdir)/../lib/isc/nls/msgcat.c \ + $(srcdir)/../lib/isc/unix/net.c $(srcdir)/../lib/isc/netaddr.c \ + $(srcdir)/../lib/isc/netscope.c \ + $(srcdir)/../lib/isc/ondestroy.c $(srcdir)/../lib/isc/random.c \ + $(srcdir)/../lib/isc/result.c \ + $(srcdir)/../lib/isc/unix/stdio.c \ + $(srcdir)/../lib/isc/unix/stdtime.c \ + $(srcdir)/../lib/isc/unix/strerror.c \ + $(srcdir)/../lib/isc/task.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c \ + $(srcdir)/../lib/isc/unix/time.c $(srcdir)/../lib/isc/sha1.c \ + $(srcdir)/../lib/isc/sockaddr.c \ + $(srcdir)/../lib/isc/pthreads/mutex.c +am_libntpsim_a_OBJECTS = systime_s.$(OBJEXT) $(am__objects_4) libntpsim_a_OBJECTS = $(am_libntpsim_a_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp +depcomp = $(SHELL) $(top_srcdir)/sntp/libevent/build-aux/depcomp am__depfiles_maybe = depfiles am__mv = mv -f +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; CCLD = $(CC) -LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ - $(LDFLAGS) -o $@ +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(libntp_a_SOURCES) $(EXTRA_libntp_a_SOURCES) \ $(libntpsim_a_SOURCES) -DIST_SOURCES = $(libntp_a_SOURCES) $(EXTRA_libntp_a_SOURCES) \ - $(libntpsim_a_SOURCES) +DIST_SOURCES = $(am__libntp_a_SOURCES_DIST) $(EXTRA_libntp_a_SOURCES) \ + $(am__libntpsim_a_SOURCES_DIST) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ +ALLOCA = @ALLOCA@ AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ -BINSUBDIR = @BINSUBDIR@ +CALC_TICKADJ_DB = @CALC_TICKADJ_DB@ +CALC_TICKADJ_DL = @CALC_TICKADJ_DL@ +CALC_TICKADJ_DS = @CALC_TICKADJ_DS@ +CALC_TICKADJ_MS = @CALC_TICKADJ_MS@ +CALC_TICKADJ_NI = @CALC_TICKADJ_NI@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ +CFLAGS_NTP = @CFLAGS_NTP@ CHUTEST = @CHUTEST@ -CLKTEST = @CLKTEST@ +CONFIG_SHELL = @CONFIG_SHELL@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ +CPPFLAGS_NTP = @CPPFLAGS_NTP@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DCFD = @DCFD@ DEFS = @DEFS@ @@ -144,21 +284,31 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EDITLINE_LIBS = @EDITLINE_LIBS@ -EF_LIBS = @EF_LIBS@ -EF_PROGS = @EF_PROGS@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GTEST_CONFIG = @GTEST_CONFIG@ +GTEST_CPPFLAGS = @GTEST_CPPFLAGS@ +GTEST_CXXFLAGS = @GTEST_CXXFLAGS@ +GTEST_LDFLAGS = @GTEST_LDFLAGS@ +GTEST_LIBS = @GTEST_LIBS@ HAVE_INLINE = @HAVE_INLINE@ +HAVE_RLIMIT_MEMLOCK = @HAVE_RLIMIT_MEMLOCK@ +HAVE_RLIMIT_STACK = @HAVE_RLIMIT_STACK@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LCRYPTO = @LCRYPTO@ LD = @LD@ +LDADD_LIBNTP = @LDADD_LIBNTP@ +LDADD_NLIST = @LDADD_NLIST@ +LDADD_NTP = @LDADD_NTP@ LDFLAGS = @LDFLAGS@ +LDFLAGS_NTP = @LDFLAGS_NTP@ +LIBISC_PTHREADS_NOTHREADS = @LIBISC_PTHREADS_NOTHREADS@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@ LIBOPTS_DIR = @LIBOPTS_DIR@ @@ -166,6 +316,7 @@ LIBOPTS_LDADD = @LIBOPTS_LDADD@ LIBPARSE = @LIBPARSE@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIPO = @LIPO@ LN_S = @LN_S@ LSCF = @LSCF@ @@ -184,14 +335,68 @@ MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ MAKE_TICKADJ = @MAKE_TICKADJ@ MAKE_TIMETRIM = @MAKE_TIMETRIM@ MANIFEST_TOOL = @MANIFEST_TOOL@ +MANTAGFMT = @MANTAGFMT@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ +NTPDATE_DB = @NTPDATE_DB@ +NTPDATE_DL = @NTPDATE_DL@ +NTPDATE_DS = @NTPDATE_DS@ +NTPDATE_MS = @NTPDATE_MS@ +NTPDATE_NI = @NTPDATE_NI@ +NTPDC_DB = @NTPDC_DB@ +NTPDC_DL = @NTPDC_DL@ +NTPDC_DS = @NTPDC_DS@ +NTPDC_MS = @NTPDC_MS@ +NTPDC_NI = @NTPDC_NI@ +NTPDSIM_DB = @NTPDSIM_DB@ +NTPDSIM_DL = @NTPDSIM_DL@ +NTPDSIM_DS = @NTPDSIM_DS@ +NTPDSIM_MS = @NTPDSIM_MS@ +NTPDSIM_NI = @NTPDSIM_NI@ +NTPD_DB = @NTPD_DB@ +NTPD_DL = @NTPD_DL@ +NTPD_DS = @NTPD_DS@ +NTPD_MS = @NTPD_MS@ +NTPD_NI = @NTPD_NI@ +NTPQ_DB = @NTPQ_DB@ +NTPQ_DL = @NTPQ_DL@ +NTPQ_DS = @NTPQ_DS@ +NTPQ_MS = @NTPQ_MS@ +NTPQ_NI = @NTPQ_NI@ +NTPSNMPD_DB = @NTPSNMPD_DB@ +NTPSNMPD_DL = @NTPSNMPD_DL@ +NTPSNMPD_DS = @NTPSNMPD_DS@ +NTPSNMPD_MS = @NTPSNMPD_MS@ +NTPSNMPD_NI = @NTPSNMPD_NI@ +NTPSWEEP_DB = @NTPSWEEP_DB@ +NTPSWEEP_DL = @NTPSWEEP_DL@ +NTPSWEEP_DS = @NTPSWEEP_DS@ +NTPSWEEP_MS = @NTPSWEEP_MS@ +NTPSWEEP_NI = @NTPSWEEP_NI@ +NTPTIME_DB = @NTPTIME_DB@ +NTPTIME_DL = @NTPTIME_DL@ +NTPTIME_DS = @NTPTIME_DS@ +NTPTIME_MS = @NTPTIME_MS@ +NTPTIME_NI = @NTPTIME_NI@ +NTPTRACE_DB = @NTPTRACE_DB@ +NTPTRACE_DL = @NTPTRACE_DL@ +NTPTRACE_DS = @NTPTRACE_DS@ +NTPTRACE_MS = @NTPTRACE_MS@ +NTPTRACE_NI = @NTPTRACE_NI@ +NTP_KEYGEN_DB = @NTP_KEYGEN_DB@ +NTP_KEYGEN_DL = @NTP_KEYGEN_DL@ +NTP_KEYGEN_DS = @NTP_KEYGEN_DS@ +NTP_KEYGEN_MS = @NTP_KEYGEN_MS@ +NTP_KEYGEN_NI = @NTP_KEYGEN_NI@ +NTP_KEYSDIR = @NTP_KEYSDIR@ +NTP_WAIT_DB = @NTP_WAIT_DB@ +NTP_WAIT_DL = @NTP_WAIT_DL@ +NTP_WAIT_DS = @NTP_WAIT_DS@ +NTP_WAIT_MS = @NTP_WAIT_MS@ +NTP_WAIT_NI = @NTP_WAIT_NI@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ -OPENSSL = @OPENSSL@ -OPENSSL_INC = @OPENSSL_INC@ -OPENSSL_LIB = @OPENSSL_LIB@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ @@ -204,10 +409,12 @@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_NET_SNMP_CONFIG = @PATH_NET_SNMP_CONFIG@ PATH_PERL = @PATH_PERL@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PATH_SH = @PATH_SH@ PATH_TEST = @PATH_TEST@ +PERLLIBDIR = @PERLLIBDIR@ +PKG_CONFIG = @PKG_CONFIG@ POSIX_SHELL = @POSIX_SHELL@ PROPDELAY = @PROPDELAY@ +PTHREAD_LIBS = @PTHREAD_LIBS@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ @@ -215,9 +422,27 @@ SHELL = @SHELL@ SNMP_CFLAGS = @SNMP_CFLAGS@ SNMP_CPPFLAGS = @SNMP_CPPFLAGS@ SNMP_LIBS = @SNMP_LIBS@ +SNTP = @SNTP@ +SNTP_DB = @SNTP_DB@ +SNTP_DL = @SNTP_DL@ +SNTP_DS = @SNTP_DS@ +SNTP_MS = @SNTP_MS@ +SNTP_NI = @SNTP_NI@ +STDNORETURN_H = @STDNORETURN_H@ STRIP = @STRIP@ TESTDCF = @TESTDCF@ +TICKADJ_DB = @TICKADJ_DB@ +TICKADJ_DL = @TICKADJ_DL@ +TICKADJ_DS = @TICKADJ_DS@ +TICKADJ_MS = @TICKADJ_MS@ +TICKADJ_NI = @TICKADJ_NI@ +TIMETRIM_DB = @TIMETRIM_DB@ +TIMETRIM_DL = @TIMETRIM_DL@ +TIMETRIM_DS = @TIMETRIM_DS@ +TIMETRIM_MS = @TIMETRIM_MS@ +TIMETRIM_NI = @TIMETRIM_NI@ VERSION = @VERSION@ +VER_SUFFIX = @VER_SUFFIX@ YACC = @YACC@ YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ @@ -226,6 +451,7 @@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ @@ -274,12 +500,34 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ NULL = -#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies -AUTOMAKE_OPTIONS = BUILT_SOURCES = .deps-ver CLEANFILES = .deps-ver noinst_LIBRARIES = libntp.a @MAKE_LIBNTPSIM@ EXTRA_LIBRARIES = libntpsim.a +libisc_SRCS = $(srcdir)/../lib/isc/assertions.c \ + $(srcdir)/../lib/isc/buffer.c \ + $(srcdir)/../lib/isc/backtrace-emptytbl.c \ + $(srcdir)/../lib/isc/backtrace.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c \ + $(srcdir)/../lib/isc/unix/dir.c $(srcdir)/../lib/isc/error.c \ + $(srcdir)/../lib/isc/unix/errno2result.c \ + $(srcdir)/../lib/isc/event.c $(srcdir)/../lib/isc/unix/file.c \ + $(srcdir)/../lib/isc/inet_ntop.c \ + $(srcdir)/../lib/isc/inet_pton.c \ + $(srcdir)/../lib/isc/unix/interfaceiter.c \ + $(srcdir)/../lib/isc/lib.c $(srcdir)/../lib/isc/log.c \ + $(srcdir)/../lib/isc/md5.c $(srcdir)/../lib/isc/nls/msgcat.c \ + $(srcdir)/../lib/isc/unix/net.c $(srcdir)/../lib/isc/netaddr.c \ + $(srcdir)/../lib/isc/netscope.c \ + $(srcdir)/../lib/isc/ondestroy.c $(srcdir)/../lib/isc/random.c \ + $(srcdir)/../lib/isc/result.c \ + $(srcdir)/../lib/isc/unix/stdio.c \ + $(srcdir)/../lib/isc/unix/stdtime.c \ + $(srcdir)/../lib/isc/unix/strerror.c \ + $(srcdir)/../lib/isc/task.c \ + $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c \ + $(srcdir)/../lib/isc/unix/time.c $(srcdir)/../lib/isc/sha1.c \ + $(srcdir)/../lib/isc/sockaddr.c $(NULL) $(am__append_1) libntp_a_SRCS = \ a_md5encrypt.c \ adjtime.c \ @@ -302,95 +550,67 @@ libntp_a_SRCS = \ dolfptoa.c \ emalloc.c \ findconfig.c \ - fptoa.c \ - fptoms.c \ getopt.c \ hextoint.c \ hextolfp.c \ humandate.c \ icom.c \ - inttoa.c \ iosignal.c \ lib_strbuf.c \ machines.c \ - memmove.c \ - mfptoa.c \ - ntp_lineedit.c \ - mfptoms.c \ mktime.c \ modetoa.c \ mstolfp.c \ - msutotsf.c \ msyslog.c \ netof.c \ + ntp_calendar.c \ + ntp_crypto_rnd.c \ + ntp_intres.c \ ntp_libopts.c \ + ntp_lineedit.c \ + ntp_random.c \ ntp_rfc2553.c \ + ntp_worker.c \ numtoa.c \ numtohost.c \ octtoint.c \ prettydate.c \ - ntp_random.c \ recvbuff.c \ refnumtoa.c \ snprintf.c \ + socket.c \ socktoa.c \ socktohost.c \ ssl_init.c \ statestr.c \ strdup.c \ - strstr.c \ + strl_obsd.c \ syssignal.c \ - tsftomsu.c \ - tstotv.c \ - tvtots.c \ + timetoa.c \ + timevalops.c \ uglydate.c \ - uinttoa.c \ + vint64ops.c \ + work_fork.c \ + work_thread.c \ ymd2yd.c \ - $(srcdir)/../lib/isc/assertions.c \ - $(srcdir)/../lib/isc/buffer.c \ - $(srcdir)/../lib/isc/nothreads/condition.c \ - $(srcdir)/../lib/isc/unix/dir.c \ - $(srcdir)/../lib/isc/error.c \ - $(srcdir)/../lib/isc/unix/errno2result.c \ - $(srcdir)/../lib/isc/event.c \ - $(srcdir)/../lib/isc/unix/file.c \ - $(srcdir)/../lib/isc/inet_ntop.c \ - $(srcdir)/../lib/isc/inet_pton.c \ - $(srcdir)/../lib/isc/unix/interfaceiter.c \ - $(srcdir)/../lib/isc/lib.c \ - $(srcdir)/../lib/isc/log.c \ - $(srcdir)/../lib/isc/md5.c \ - $(srcdir)/../lib/isc/nls/msgcat.c \ - $(srcdir)/../lib/isc/unix/net.c \ - $(srcdir)/../lib/isc/netaddr.c \ - $(srcdir)/../lib/isc/netscope.c \ - $(srcdir)/../lib/isc/ondestroy.c \ - $(srcdir)/../lib/isc/random.c \ - $(srcdir)/../lib/isc/result.c \ - $(srcdir)/../lib/isc/unix/stdio.c \ - $(srcdir)/../lib/isc/unix/stdtime.c \ - $(srcdir)/../lib/isc/unix/strerror.c \ - $(srcdir)/../lib/isc/task.c \ - $(srcdir)/../lib/isc/nothreads/thread.c \ - $(srcdir)/../lib/isc/unix/time.c \ - $(srcdir)/../lib/isc/sockaddr.c \ + $(libisc_SRCS) \ $(NULL) libntp_a_SOURCES = systime.c $(libntp_a_SRCS) libntpsim_a_SOURCES = systime_s.c $(libntp_a_SRCS) EXTRA_libntp_a_SOURCES = adjtimex.c -ETAGS_ARGS = Makefile.am -INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \ - -I$(top_srcdir)/lib/isc/nothreads/include \ - -I$(top_srcdir)/lib/isc/unix/include $(LIBOPTS_CFLAGS) - +AM_CFLAGS = $(CFLAGS_NTP) +AM_CPPFLAGS = $(NTP_INCS) $(LIBOPTS_CFLAGS) $(CPPFLAGS_NTP) EXTRA_DIST = README +NTP_INCS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \ + -I$(top_srcdir)/lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/include \ + -I$(top_srcdir)/lib/isc/unix/include all: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/depsver.mf $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -424,13 +644,13 @@ $(am__aclocal_m4_deps): clean-noinstLIBRARIES: -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) libntp.a: $(libntp_a_OBJECTS) $(libntp_a_DEPENDENCIES) - -rm -f libntp.a - $(libntp_a_AR) libntp.a $(libntp_a_OBJECTS) $(libntp_a_LIBADD) - $(RANLIB) libntp.a + $(AM_V_at)-rm -f libntp.a + $(AM_V_AR)$(libntp_a_AR) libntp.a $(libntp_a_OBJECTS) $(libntp_a_LIBADD) + $(AM_V_at)$(RANLIB) libntp.a libntpsim.a: $(libntpsim_a_OBJECTS) $(libntpsim_a_DEPENDENCIES) - -rm -f libntpsim.a - $(libntpsim_a_AR) libntpsim.a $(libntpsim_a_OBJECTS) $(libntpsim_a_LIBADD) - $(RANLIB) libntpsim.a + $(AM_V_at)-rm -f libntpsim.a + $(AM_V_AR)$(libntpsim_a_AR) libntpsim.a $(libntpsim_a_OBJECTS) $(libntpsim_a_LIBADD) + $(AM_V_at)$(RANLIB) libntpsim.a mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -449,6 +669,8 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/authkeys.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/authreadkeys.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/authusekey.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/backtrace-emptytbl.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/backtrace.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bsd_strerror.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buftvtots.Po@am__quote@ @@ -468,8 +690,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/event.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/findconfig.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fptoa.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fptoms.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hextoint.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hextolfp.Po@am__quote@ @@ -478,30 +698,30 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_ntop.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_pton.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interfaceiter.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inttoa.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iosignal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_strbuf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/machines.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memmove.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mfptoa.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mfptoms.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/modetoa.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msgcat.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mstolfp.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msutotsf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msyslog.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mutex.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netaddr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netof.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netscope.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_calendar.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_crypto_rnd.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_intres.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_libopts.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_lineedit.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_random.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_rfc2553.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_worker.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numtoa.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numtohost.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/octtoint.Po@am__quote@ @@ -511,8 +731,10 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/recvbuff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/refnumtoa.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/result.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snprintf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sockaddr.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socket.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socktoa.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socktohost.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ssl_init.Po@am__quote@ @@ -521,433 +743,557 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdtime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strdup.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strerror.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strstr.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strl_obsd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/syssignal.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/systime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/systime_s.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/task.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thread.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsftomsu.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tstotv.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tvtots.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timetoa.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timevalops.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uglydate.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uinttoa.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vint64ops.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/work_fork.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/work_thread.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ymd2yd.Po@am__quote@ .c.o: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: -@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< assertions.o: $(srcdir)/../lib/isc/assertions.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions.o -MD -MP -MF $(DEPDIR)/assertions.Tpo -c -o assertions.o `test -f '$(srcdir)/../lib/isc/assertions.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/assertions.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/assertions.Tpo $(DEPDIR)/assertions.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions.o -MD -MP -MF $(DEPDIR)/assertions.Tpo -c -o assertions.o `test -f '$(srcdir)/../lib/isc/assertions.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/assertions.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/assertions.Tpo $(DEPDIR)/assertions.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/assertions.c' object='assertions.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assertions.o `test -f '$(srcdir)/../lib/isc/assertions.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/assertions.c assertions.obj: $(srcdir)/../lib/isc/assertions.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions.obj -MD -MP -MF $(DEPDIR)/assertions.Tpo -c -o assertions.obj `if test -f '$(srcdir)/../lib/isc/assertions.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/assertions.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/assertions.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/assertions.Tpo $(DEPDIR)/assertions.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions.obj -MD -MP -MF $(DEPDIR)/assertions.Tpo -c -o assertions.obj `if test -f '$(srcdir)/../lib/isc/assertions.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/assertions.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/assertions.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/assertions.Tpo $(DEPDIR)/assertions.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/assertions.c' object='assertions.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assertions.obj `if test -f '$(srcdir)/../lib/isc/assertions.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/assertions.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/assertions.c'; fi` buffer.o: $(srcdir)/../lib/isc/buffer.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT buffer.o -MD -MP -MF $(DEPDIR)/buffer.Tpo -c -o buffer.o `test -f '$(srcdir)/../lib/isc/buffer.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/buffer.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/buffer.Tpo $(DEPDIR)/buffer.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT buffer.o -MD -MP -MF $(DEPDIR)/buffer.Tpo -c -o buffer.o `test -f '$(srcdir)/../lib/isc/buffer.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/buffer.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer.Tpo $(DEPDIR)/buffer.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/buffer.c' object='buffer.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o buffer.o `test -f '$(srcdir)/../lib/isc/buffer.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/buffer.c buffer.obj: $(srcdir)/../lib/isc/buffer.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT buffer.obj -MD -MP -MF $(DEPDIR)/buffer.Tpo -c -o buffer.obj `if test -f '$(srcdir)/../lib/isc/buffer.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/buffer.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/buffer.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/buffer.Tpo $(DEPDIR)/buffer.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT buffer.obj -MD -MP -MF $(DEPDIR)/buffer.Tpo -c -o buffer.obj `if test -f '$(srcdir)/../lib/isc/buffer.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/buffer.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/buffer.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer.Tpo $(DEPDIR)/buffer.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/buffer.c' object='buffer.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o buffer.obj `if test -f '$(srcdir)/../lib/isc/buffer.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/buffer.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/buffer.c'; fi` -condition.o: $(srcdir)/../lib/isc/nothreads/condition.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT condition.o -MD -MP -MF $(DEPDIR)/condition.Tpo -c -o condition.o `test -f '$(srcdir)/../lib/isc/nothreads/condition.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/nothreads/condition.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/condition.Tpo $(DEPDIR)/condition.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/nothreads/condition.c' object='condition.o' libtool=no @AMDEPBACKSLASH@ +backtrace-emptytbl.o: $(srcdir)/../lib/isc/backtrace-emptytbl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT backtrace-emptytbl.o -MD -MP -MF $(DEPDIR)/backtrace-emptytbl.Tpo -c -o backtrace-emptytbl.o `test -f '$(srcdir)/../lib/isc/backtrace-emptytbl.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/backtrace-emptytbl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/backtrace-emptytbl.Tpo $(DEPDIR)/backtrace-emptytbl.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/backtrace-emptytbl.c' object='backtrace-emptytbl.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o condition.o `test -f '$(srcdir)/../lib/isc/nothreads/condition.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/nothreads/condition.c +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o backtrace-emptytbl.o `test -f '$(srcdir)/../lib/isc/backtrace-emptytbl.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/backtrace-emptytbl.c -condition.obj: $(srcdir)/../lib/isc/nothreads/condition.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT condition.obj -MD -MP -MF $(DEPDIR)/condition.Tpo -c -o condition.obj `if test -f '$(srcdir)/../lib/isc/nothreads/condition.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/nothreads/condition.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/nothreads/condition.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/condition.Tpo $(DEPDIR)/condition.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/nothreads/condition.c' object='condition.obj' libtool=no @AMDEPBACKSLASH@ +backtrace-emptytbl.obj: $(srcdir)/../lib/isc/backtrace-emptytbl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT backtrace-emptytbl.obj -MD -MP -MF $(DEPDIR)/backtrace-emptytbl.Tpo -c -o backtrace-emptytbl.obj `if test -f '$(srcdir)/../lib/isc/backtrace-emptytbl.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/backtrace-emptytbl.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/backtrace-emptytbl.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/backtrace-emptytbl.Tpo $(DEPDIR)/backtrace-emptytbl.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/backtrace-emptytbl.c' object='backtrace-emptytbl.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o condition.obj `if test -f '$(srcdir)/../lib/isc/nothreads/condition.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/nothreads/condition.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/nothreads/condition.c'; fi` +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o backtrace-emptytbl.obj `if test -f '$(srcdir)/../lib/isc/backtrace-emptytbl.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/backtrace-emptytbl.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/backtrace-emptytbl.c'; fi` + +backtrace.o: $(srcdir)/../lib/isc/backtrace.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT backtrace.o -MD -MP -MF $(DEPDIR)/backtrace.Tpo -c -o backtrace.o `test -f '$(srcdir)/../lib/isc/backtrace.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/backtrace.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/backtrace.Tpo $(DEPDIR)/backtrace.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/backtrace.c' object='backtrace.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o backtrace.o `test -f '$(srcdir)/../lib/isc/backtrace.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/backtrace.c + +backtrace.obj: $(srcdir)/../lib/isc/backtrace.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT backtrace.obj -MD -MP -MF $(DEPDIR)/backtrace.Tpo -c -o backtrace.obj `if test -f '$(srcdir)/../lib/isc/backtrace.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/backtrace.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/backtrace.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/backtrace.Tpo $(DEPDIR)/backtrace.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/backtrace.c' object='backtrace.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o backtrace.obj `if test -f '$(srcdir)/../lib/isc/backtrace.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/backtrace.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/backtrace.c'; fi` + +condition.o: $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT condition.o -MD -MP -MF $(DEPDIR)/condition.Tpo -c -o condition.o `test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/condition.Tpo $(DEPDIR)/condition.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c' object='condition.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o condition.o `test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c + +condition.obj: $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT condition.obj -MD -MP -MF $(DEPDIR)/condition.Tpo -c -o condition.obj `if test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/condition.Tpo $(DEPDIR)/condition.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c' object='condition.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o condition.obj `if test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/condition.c'; fi` dir.o: $(srcdir)/../lib/isc/unix/dir.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dir.o -MD -MP -MF $(DEPDIR)/dir.Tpo -c -o dir.o `test -f '$(srcdir)/../lib/isc/unix/dir.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/dir.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/dir.Tpo $(DEPDIR)/dir.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dir.o -MD -MP -MF $(DEPDIR)/dir.Tpo -c -o dir.o `test -f '$(srcdir)/../lib/isc/unix/dir.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/dir.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dir.Tpo $(DEPDIR)/dir.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/dir.c' object='dir.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dir.o `test -f '$(srcdir)/../lib/isc/unix/dir.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/dir.c dir.obj: $(srcdir)/../lib/isc/unix/dir.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dir.obj -MD -MP -MF $(DEPDIR)/dir.Tpo -c -o dir.obj `if test -f '$(srcdir)/../lib/isc/unix/dir.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/dir.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/dir.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/dir.Tpo $(DEPDIR)/dir.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dir.obj -MD -MP -MF $(DEPDIR)/dir.Tpo -c -o dir.obj `if test -f '$(srcdir)/../lib/isc/unix/dir.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/dir.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/dir.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dir.Tpo $(DEPDIR)/dir.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/dir.c' object='dir.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dir.obj `if test -f '$(srcdir)/../lib/isc/unix/dir.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/dir.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/dir.c'; fi` error.o: $(srcdir)/../lib/isc/error.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error.o -MD -MP -MF $(DEPDIR)/error.Tpo -c -o error.o `test -f '$(srcdir)/../lib/isc/error.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/error.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/error.Tpo $(DEPDIR)/error.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error.o -MD -MP -MF $(DEPDIR)/error.Tpo -c -o error.o `test -f '$(srcdir)/../lib/isc/error.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/error.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/error.Tpo $(DEPDIR)/error.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/error.c' object='error.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o error.o `test -f '$(srcdir)/../lib/isc/error.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/error.c error.obj: $(srcdir)/../lib/isc/error.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error.obj -MD -MP -MF $(DEPDIR)/error.Tpo -c -o error.obj `if test -f '$(srcdir)/../lib/isc/error.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/error.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/error.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/error.Tpo $(DEPDIR)/error.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error.obj -MD -MP -MF $(DEPDIR)/error.Tpo -c -o error.obj `if test -f '$(srcdir)/../lib/isc/error.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/error.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/error.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/error.Tpo $(DEPDIR)/error.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/error.c' object='error.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o error.obj `if test -f '$(srcdir)/../lib/isc/error.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/error.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/error.c'; fi` errno2result.o: $(srcdir)/../lib/isc/unix/errno2result.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errno2result.o -MD -MP -MF $(DEPDIR)/errno2result.Tpo -c -o errno2result.o `test -f '$(srcdir)/../lib/isc/unix/errno2result.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/errno2result.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/errno2result.Tpo $(DEPDIR)/errno2result.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errno2result.o -MD -MP -MF $(DEPDIR)/errno2result.Tpo -c -o errno2result.o `test -f '$(srcdir)/../lib/isc/unix/errno2result.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/errno2result.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errno2result.Tpo $(DEPDIR)/errno2result.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/errno2result.c' object='errno2result.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errno2result.o `test -f '$(srcdir)/../lib/isc/unix/errno2result.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/errno2result.c errno2result.obj: $(srcdir)/../lib/isc/unix/errno2result.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errno2result.obj -MD -MP -MF $(DEPDIR)/errno2result.Tpo -c -o errno2result.obj `if test -f '$(srcdir)/../lib/isc/unix/errno2result.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/errno2result.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/errno2result.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/errno2result.Tpo $(DEPDIR)/errno2result.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT errno2result.obj -MD -MP -MF $(DEPDIR)/errno2result.Tpo -c -o errno2result.obj `if test -f '$(srcdir)/../lib/isc/unix/errno2result.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/errno2result.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/errno2result.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/errno2result.Tpo $(DEPDIR)/errno2result.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/errno2result.c' object='errno2result.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o errno2result.obj `if test -f '$(srcdir)/../lib/isc/unix/errno2result.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/errno2result.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/errno2result.c'; fi` event.o: $(srcdir)/../lib/isc/event.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT event.o -MD -MP -MF $(DEPDIR)/event.Tpo -c -o event.o `test -f '$(srcdir)/../lib/isc/event.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/event.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/event.Tpo $(DEPDIR)/event.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT event.o -MD -MP -MF $(DEPDIR)/event.Tpo -c -o event.o `test -f '$(srcdir)/../lib/isc/event.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/event.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/event.Tpo $(DEPDIR)/event.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/event.c' object='event.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o event.o `test -f '$(srcdir)/../lib/isc/event.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/event.c event.obj: $(srcdir)/../lib/isc/event.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT event.obj -MD -MP -MF $(DEPDIR)/event.Tpo -c -o event.obj `if test -f '$(srcdir)/../lib/isc/event.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/event.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/event.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/event.Tpo $(DEPDIR)/event.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT event.obj -MD -MP -MF $(DEPDIR)/event.Tpo -c -o event.obj `if test -f '$(srcdir)/../lib/isc/event.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/event.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/event.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/event.Tpo $(DEPDIR)/event.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/event.c' object='event.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o event.obj `if test -f '$(srcdir)/../lib/isc/event.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/event.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/event.c'; fi` file.o: $(srcdir)/../lib/isc/unix/file.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT file.o -MD -MP -MF $(DEPDIR)/file.Tpo -c -o file.o `test -f '$(srcdir)/../lib/isc/unix/file.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/file.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/file.Tpo $(DEPDIR)/file.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT file.o -MD -MP -MF $(DEPDIR)/file.Tpo -c -o file.o `test -f '$(srcdir)/../lib/isc/unix/file.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/file.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/file.Tpo $(DEPDIR)/file.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/file.c' object='file.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o file.o `test -f '$(srcdir)/../lib/isc/unix/file.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/file.c file.obj: $(srcdir)/../lib/isc/unix/file.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT file.obj -MD -MP -MF $(DEPDIR)/file.Tpo -c -o file.obj `if test -f '$(srcdir)/../lib/isc/unix/file.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/file.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/file.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/file.Tpo $(DEPDIR)/file.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT file.obj -MD -MP -MF $(DEPDIR)/file.Tpo -c -o file.obj `if test -f '$(srcdir)/../lib/isc/unix/file.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/file.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/file.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/file.Tpo $(DEPDIR)/file.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/file.c' object='file.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o file.obj `if test -f '$(srcdir)/../lib/isc/unix/file.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/file.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/file.c'; fi` inet_ntop.o: $(srcdir)/../lib/isc/inet_ntop.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop.o -MD -MP -MF $(DEPDIR)/inet_ntop.Tpo -c -o inet_ntop.o `test -f '$(srcdir)/../lib/isc/inet_ntop.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/inet_ntop.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/inet_ntop.Tpo $(DEPDIR)/inet_ntop.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop.o -MD -MP -MF $(DEPDIR)/inet_ntop.Tpo -c -o inet_ntop.o `test -f '$(srcdir)/../lib/isc/inet_ntop.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/inet_ntop.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/inet_ntop.Tpo $(DEPDIR)/inet_ntop.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/inet_ntop.c' object='inet_ntop.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_ntop.o `test -f '$(srcdir)/../lib/isc/inet_ntop.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/inet_ntop.c inet_ntop.obj: $(srcdir)/../lib/isc/inet_ntop.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop.obj -MD -MP -MF $(DEPDIR)/inet_ntop.Tpo -c -o inet_ntop.obj `if test -f '$(srcdir)/../lib/isc/inet_ntop.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/inet_ntop.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/inet_ntop.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/inet_ntop.Tpo $(DEPDIR)/inet_ntop.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop.obj -MD -MP -MF $(DEPDIR)/inet_ntop.Tpo -c -o inet_ntop.obj `if test -f '$(srcdir)/../lib/isc/inet_ntop.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/inet_ntop.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/inet_ntop.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/inet_ntop.Tpo $(DEPDIR)/inet_ntop.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/inet_ntop.c' object='inet_ntop.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_ntop.obj `if test -f '$(srcdir)/../lib/isc/inet_ntop.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/inet_ntop.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/inet_ntop.c'; fi` inet_pton.o: $(srcdir)/../lib/isc/inet_pton.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_pton.o -MD -MP -MF $(DEPDIR)/inet_pton.Tpo -c -o inet_pton.o `test -f '$(srcdir)/../lib/isc/inet_pton.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/inet_pton.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/inet_pton.Tpo $(DEPDIR)/inet_pton.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_pton.o -MD -MP -MF $(DEPDIR)/inet_pton.Tpo -c -o inet_pton.o `test -f '$(srcdir)/../lib/isc/inet_pton.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/inet_pton.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/inet_pton.Tpo $(DEPDIR)/inet_pton.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/inet_pton.c' object='inet_pton.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_pton.o `test -f '$(srcdir)/../lib/isc/inet_pton.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/inet_pton.c inet_pton.obj: $(srcdir)/../lib/isc/inet_pton.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_pton.obj -MD -MP -MF $(DEPDIR)/inet_pton.Tpo -c -o inet_pton.obj `if test -f '$(srcdir)/../lib/isc/inet_pton.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/inet_pton.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/inet_pton.Tpo $(DEPDIR)/inet_pton.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_pton.obj -MD -MP -MF $(DEPDIR)/inet_pton.Tpo -c -o inet_pton.obj `if test -f '$(srcdir)/../lib/isc/inet_pton.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/inet_pton.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/inet_pton.Tpo $(DEPDIR)/inet_pton.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/inet_pton.c' object='inet_pton.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_pton.obj `if test -f '$(srcdir)/../lib/isc/inet_pton.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/inet_pton.c'; fi` interfaceiter.o: $(srcdir)/../lib/isc/unix/interfaceiter.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter.o -MD -MP -MF $(DEPDIR)/interfaceiter.Tpo -c -o interfaceiter.o `test -f '$(srcdir)/../lib/isc/unix/interfaceiter.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/interfaceiter.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/interfaceiter.Tpo $(DEPDIR)/interfaceiter.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter.o -MD -MP -MF $(DEPDIR)/interfaceiter.Tpo -c -o interfaceiter.o `test -f '$(srcdir)/../lib/isc/unix/interfaceiter.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/interfaceiter.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interfaceiter.Tpo $(DEPDIR)/interfaceiter.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/interfaceiter.c' object='interfaceiter.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interfaceiter.o `test -f '$(srcdir)/../lib/isc/unix/interfaceiter.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/interfaceiter.c interfaceiter.obj: $(srcdir)/../lib/isc/unix/interfaceiter.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter.obj -MD -MP -MF $(DEPDIR)/interfaceiter.Tpo -c -o interfaceiter.obj `if test -f '$(srcdir)/../lib/isc/unix/interfaceiter.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/interfaceiter.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/interfaceiter.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/interfaceiter.Tpo $(DEPDIR)/interfaceiter.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter.obj -MD -MP -MF $(DEPDIR)/interfaceiter.Tpo -c -o interfaceiter.obj `if test -f '$(srcdir)/../lib/isc/unix/interfaceiter.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/interfaceiter.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/interfaceiter.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/interfaceiter.Tpo $(DEPDIR)/interfaceiter.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/interfaceiter.c' object='interfaceiter.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interfaceiter.obj `if test -f '$(srcdir)/../lib/isc/unix/interfaceiter.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/interfaceiter.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/interfaceiter.c'; fi` lib.o: $(srcdir)/../lib/isc/lib.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib.o -MD -MP -MF $(DEPDIR)/lib.Tpo -c -o lib.o `test -f '$(srcdir)/../lib/isc/lib.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/lib.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/lib.Tpo $(DEPDIR)/lib.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib.o -MD -MP -MF $(DEPDIR)/lib.Tpo -c -o lib.o `test -f '$(srcdir)/../lib/isc/lib.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/lib.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/lib.Tpo $(DEPDIR)/lib.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/lib.c' object='lib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib.o `test -f '$(srcdir)/../lib/isc/lib.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/lib.c lib.obj: $(srcdir)/../lib/isc/lib.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib.obj -MD -MP -MF $(DEPDIR)/lib.Tpo -c -o lib.obj `if test -f '$(srcdir)/../lib/isc/lib.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/lib.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/lib.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/lib.Tpo $(DEPDIR)/lib.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib.obj -MD -MP -MF $(DEPDIR)/lib.Tpo -c -o lib.obj `if test -f '$(srcdir)/../lib/isc/lib.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/lib.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/lib.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/lib.Tpo $(DEPDIR)/lib.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/lib.c' object='lib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib.obj `if test -f '$(srcdir)/../lib/isc/lib.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/lib.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/lib.c'; fi` log.o: $(srcdir)/../lib/isc/log.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT log.o -MD -MP -MF $(DEPDIR)/log.Tpo -c -o log.o `test -f '$(srcdir)/../lib/isc/log.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/log.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/log.Tpo $(DEPDIR)/log.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT log.o -MD -MP -MF $(DEPDIR)/log.Tpo -c -o log.o `test -f '$(srcdir)/../lib/isc/log.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/log.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/log.Tpo $(DEPDIR)/log.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/log.c' object='log.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o log.o `test -f '$(srcdir)/../lib/isc/log.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/log.c log.obj: $(srcdir)/../lib/isc/log.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT log.obj -MD -MP -MF $(DEPDIR)/log.Tpo -c -o log.obj `if test -f '$(srcdir)/../lib/isc/log.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/log.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/log.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/log.Tpo $(DEPDIR)/log.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT log.obj -MD -MP -MF $(DEPDIR)/log.Tpo -c -o log.obj `if test -f '$(srcdir)/../lib/isc/log.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/log.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/log.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/log.Tpo $(DEPDIR)/log.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/log.c' object='log.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o log.obj `if test -f '$(srcdir)/../lib/isc/log.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/log.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/log.c'; fi` md5.o: $(srcdir)/../lib/isc/md5.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT md5.o -MD -MP -MF $(DEPDIR)/md5.Tpo -c -o md5.o `test -f '$(srcdir)/../lib/isc/md5.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/md5.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/md5.Tpo $(DEPDIR)/md5.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT md5.o -MD -MP -MF $(DEPDIR)/md5.Tpo -c -o md5.o `test -f '$(srcdir)/../lib/isc/md5.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/md5.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/md5.Tpo $(DEPDIR)/md5.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/md5.c' object='md5.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o md5.o `test -f '$(srcdir)/../lib/isc/md5.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/md5.c md5.obj: $(srcdir)/../lib/isc/md5.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT md5.obj -MD -MP -MF $(DEPDIR)/md5.Tpo -c -o md5.obj `if test -f '$(srcdir)/../lib/isc/md5.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/md5.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/md5.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/md5.Tpo $(DEPDIR)/md5.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT md5.obj -MD -MP -MF $(DEPDIR)/md5.Tpo -c -o md5.obj `if test -f '$(srcdir)/../lib/isc/md5.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/md5.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/md5.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/md5.Tpo $(DEPDIR)/md5.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/md5.c' object='md5.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o md5.obj `if test -f '$(srcdir)/../lib/isc/md5.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/md5.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/md5.c'; fi` msgcat.o: $(srcdir)/../lib/isc/nls/msgcat.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat.o -MD -MP -MF $(DEPDIR)/msgcat.Tpo -c -o msgcat.o `test -f '$(srcdir)/../lib/isc/nls/msgcat.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/nls/msgcat.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/msgcat.Tpo $(DEPDIR)/msgcat.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat.o -MD -MP -MF $(DEPDIR)/msgcat.Tpo -c -o msgcat.o `test -f '$(srcdir)/../lib/isc/nls/msgcat.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/nls/msgcat.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/msgcat.Tpo $(DEPDIR)/msgcat.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/nls/msgcat.c' object='msgcat.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o msgcat.o `test -f '$(srcdir)/../lib/isc/nls/msgcat.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/nls/msgcat.c msgcat.obj: $(srcdir)/../lib/isc/nls/msgcat.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat.obj -MD -MP -MF $(DEPDIR)/msgcat.Tpo -c -o msgcat.obj `if test -f '$(srcdir)/../lib/isc/nls/msgcat.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/nls/msgcat.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/nls/msgcat.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/msgcat.Tpo $(DEPDIR)/msgcat.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat.obj -MD -MP -MF $(DEPDIR)/msgcat.Tpo -c -o msgcat.obj `if test -f '$(srcdir)/../lib/isc/nls/msgcat.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/nls/msgcat.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/nls/msgcat.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/msgcat.Tpo $(DEPDIR)/msgcat.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/nls/msgcat.c' object='msgcat.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o msgcat.obj `if test -f '$(srcdir)/../lib/isc/nls/msgcat.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/nls/msgcat.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/nls/msgcat.c'; fi` net.o: $(srcdir)/../lib/isc/unix/net.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net.o -MD -MP -MF $(DEPDIR)/net.Tpo -c -o net.o `test -f '$(srcdir)/../lib/isc/unix/net.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/net.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/net.Tpo $(DEPDIR)/net.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net.o -MD -MP -MF $(DEPDIR)/net.Tpo -c -o net.o `test -f '$(srcdir)/../lib/isc/unix/net.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/net.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/net.Tpo $(DEPDIR)/net.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/net.c' object='net.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o net.o `test -f '$(srcdir)/../lib/isc/unix/net.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/net.c net.obj: $(srcdir)/../lib/isc/unix/net.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net.obj -MD -MP -MF $(DEPDIR)/net.Tpo -c -o net.obj `if test -f '$(srcdir)/../lib/isc/unix/net.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/net.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/net.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/net.Tpo $(DEPDIR)/net.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net.obj -MD -MP -MF $(DEPDIR)/net.Tpo -c -o net.obj `if test -f '$(srcdir)/../lib/isc/unix/net.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/net.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/net.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/net.Tpo $(DEPDIR)/net.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/net.c' object='net.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o net.obj `if test -f '$(srcdir)/../lib/isc/unix/net.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/net.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/net.c'; fi` netaddr.o: $(srcdir)/../lib/isc/netaddr.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netaddr.o -MD -MP -MF $(DEPDIR)/netaddr.Tpo -c -o netaddr.o `test -f '$(srcdir)/../lib/isc/netaddr.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/netaddr.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/netaddr.Tpo $(DEPDIR)/netaddr.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netaddr.o -MD -MP -MF $(DEPDIR)/netaddr.Tpo -c -o netaddr.o `test -f '$(srcdir)/../lib/isc/netaddr.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/netaddr.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netaddr.Tpo $(DEPDIR)/netaddr.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/netaddr.c' object='netaddr.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o netaddr.o `test -f '$(srcdir)/../lib/isc/netaddr.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/netaddr.c netaddr.obj: $(srcdir)/../lib/isc/netaddr.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netaddr.obj -MD -MP -MF $(DEPDIR)/netaddr.Tpo -c -o netaddr.obj `if test -f '$(srcdir)/../lib/isc/netaddr.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/netaddr.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/netaddr.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/netaddr.Tpo $(DEPDIR)/netaddr.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netaddr.obj -MD -MP -MF $(DEPDIR)/netaddr.Tpo -c -o netaddr.obj `if test -f '$(srcdir)/../lib/isc/netaddr.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/netaddr.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/netaddr.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netaddr.Tpo $(DEPDIR)/netaddr.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/netaddr.c' object='netaddr.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o netaddr.obj `if test -f '$(srcdir)/../lib/isc/netaddr.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/netaddr.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/netaddr.c'; fi` netscope.o: $(srcdir)/../lib/isc/netscope.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netscope.o -MD -MP -MF $(DEPDIR)/netscope.Tpo -c -o netscope.o `test -f '$(srcdir)/../lib/isc/netscope.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/netscope.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/netscope.Tpo $(DEPDIR)/netscope.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netscope.o -MD -MP -MF $(DEPDIR)/netscope.Tpo -c -o netscope.o `test -f '$(srcdir)/../lib/isc/netscope.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/netscope.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netscope.Tpo $(DEPDIR)/netscope.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/netscope.c' object='netscope.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o netscope.o `test -f '$(srcdir)/../lib/isc/netscope.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/netscope.c netscope.obj: $(srcdir)/../lib/isc/netscope.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netscope.obj -MD -MP -MF $(DEPDIR)/netscope.Tpo -c -o netscope.obj `if test -f '$(srcdir)/../lib/isc/netscope.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/netscope.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/netscope.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/netscope.Tpo $(DEPDIR)/netscope.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT netscope.obj -MD -MP -MF $(DEPDIR)/netscope.Tpo -c -o netscope.obj `if test -f '$(srcdir)/../lib/isc/netscope.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/netscope.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/netscope.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netscope.Tpo $(DEPDIR)/netscope.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/netscope.c' object='netscope.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o netscope.obj `if test -f '$(srcdir)/../lib/isc/netscope.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/netscope.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/netscope.c'; fi` ondestroy.o: $(srcdir)/../lib/isc/ondestroy.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ondestroy.o -MD -MP -MF $(DEPDIR)/ondestroy.Tpo -c -o ondestroy.o `test -f '$(srcdir)/../lib/isc/ondestroy.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/ondestroy.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ondestroy.Tpo $(DEPDIR)/ondestroy.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ondestroy.o -MD -MP -MF $(DEPDIR)/ondestroy.Tpo -c -o ondestroy.o `test -f '$(srcdir)/../lib/isc/ondestroy.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/ondestroy.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ondestroy.Tpo $(DEPDIR)/ondestroy.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/ondestroy.c' object='ondestroy.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ondestroy.o `test -f '$(srcdir)/../lib/isc/ondestroy.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/ondestroy.c ondestroy.obj: $(srcdir)/../lib/isc/ondestroy.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ondestroy.obj -MD -MP -MF $(DEPDIR)/ondestroy.Tpo -c -o ondestroy.obj `if test -f '$(srcdir)/../lib/isc/ondestroy.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/ondestroy.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/ondestroy.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/ondestroy.Tpo $(DEPDIR)/ondestroy.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT ondestroy.obj -MD -MP -MF $(DEPDIR)/ondestroy.Tpo -c -o ondestroy.obj `if test -f '$(srcdir)/../lib/isc/ondestroy.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/ondestroy.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/ondestroy.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/ondestroy.Tpo $(DEPDIR)/ondestroy.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/ondestroy.c' object='ondestroy.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o ondestroy.obj `if test -f '$(srcdir)/../lib/isc/ondestroy.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/ondestroy.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/ondestroy.c'; fi` random.o: $(srcdir)/../lib/isc/random.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT random.o -MD -MP -MF $(DEPDIR)/random.Tpo -c -o random.o `test -f '$(srcdir)/../lib/isc/random.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/random.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/random.Tpo $(DEPDIR)/random.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT random.o -MD -MP -MF $(DEPDIR)/random.Tpo -c -o random.o `test -f '$(srcdir)/../lib/isc/random.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/random.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/random.Tpo $(DEPDIR)/random.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/random.c' object='random.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o random.o `test -f '$(srcdir)/../lib/isc/random.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/random.c random.obj: $(srcdir)/../lib/isc/random.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT random.obj -MD -MP -MF $(DEPDIR)/random.Tpo -c -o random.obj `if test -f '$(srcdir)/../lib/isc/random.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/random.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/random.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/random.Tpo $(DEPDIR)/random.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT random.obj -MD -MP -MF $(DEPDIR)/random.Tpo -c -o random.obj `if test -f '$(srcdir)/../lib/isc/random.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/random.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/random.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/random.Tpo $(DEPDIR)/random.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/random.c' object='random.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o random.obj `if test -f '$(srcdir)/../lib/isc/random.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/random.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/random.c'; fi` result.o: $(srcdir)/../lib/isc/result.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT result.o -MD -MP -MF $(DEPDIR)/result.Tpo -c -o result.o `test -f '$(srcdir)/../lib/isc/result.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/result.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/result.Tpo $(DEPDIR)/result.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT result.o -MD -MP -MF $(DEPDIR)/result.Tpo -c -o result.o `test -f '$(srcdir)/../lib/isc/result.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/result.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/result.Tpo $(DEPDIR)/result.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/result.c' object='result.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o result.o `test -f '$(srcdir)/../lib/isc/result.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/result.c result.obj: $(srcdir)/../lib/isc/result.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT result.obj -MD -MP -MF $(DEPDIR)/result.Tpo -c -o result.obj `if test -f '$(srcdir)/../lib/isc/result.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/result.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/result.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/result.Tpo $(DEPDIR)/result.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT result.obj -MD -MP -MF $(DEPDIR)/result.Tpo -c -o result.obj `if test -f '$(srcdir)/../lib/isc/result.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/result.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/result.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/result.Tpo $(DEPDIR)/result.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/result.c' object='result.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o result.obj `if test -f '$(srcdir)/../lib/isc/result.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/result.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/result.c'; fi` stdio.o: $(srcdir)/../lib/isc/unix/stdio.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdio.o -MD -MP -MF $(DEPDIR)/stdio.Tpo -c -o stdio.o `test -f '$(srcdir)/../lib/isc/unix/stdio.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/stdio.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/stdio.Tpo $(DEPDIR)/stdio.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdio.o -MD -MP -MF $(DEPDIR)/stdio.Tpo -c -o stdio.o `test -f '$(srcdir)/../lib/isc/unix/stdio.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/stdio.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stdio.Tpo $(DEPDIR)/stdio.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/stdio.c' object='stdio.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stdio.o `test -f '$(srcdir)/../lib/isc/unix/stdio.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/stdio.c stdio.obj: $(srcdir)/../lib/isc/unix/stdio.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdio.obj -MD -MP -MF $(DEPDIR)/stdio.Tpo -c -o stdio.obj `if test -f '$(srcdir)/../lib/isc/unix/stdio.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/stdio.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/stdio.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/stdio.Tpo $(DEPDIR)/stdio.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdio.obj -MD -MP -MF $(DEPDIR)/stdio.Tpo -c -o stdio.obj `if test -f '$(srcdir)/../lib/isc/unix/stdio.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/stdio.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/stdio.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stdio.Tpo $(DEPDIR)/stdio.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/stdio.c' object='stdio.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stdio.obj `if test -f '$(srcdir)/../lib/isc/unix/stdio.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/stdio.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/stdio.c'; fi` stdtime.o: $(srcdir)/../lib/isc/unix/stdtime.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdtime.o -MD -MP -MF $(DEPDIR)/stdtime.Tpo -c -o stdtime.o `test -f '$(srcdir)/../lib/isc/unix/stdtime.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/stdtime.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/stdtime.Tpo $(DEPDIR)/stdtime.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdtime.o -MD -MP -MF $(DEPDIR)/stdtime.Tpo -c -o stdtime.o `test -f '$(srcdir)/../lib/isc/unix/stdtime.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/stdtime.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stdtime.Tpo $(DEPDIR)/stdtime.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/stdtime.c' object='stdtime.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stdtime.o `test -f '$(srcdir)/../lib/isc/unix/stdtime.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/stdtime.c stdtime.obj: $(srcdir)/../lib/isc/unix/stdtime.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdtime.obj -MD -MP -MF $(DEPDIR)/stdtime.Tpo -c -o stdtime.obj `if test -f '$(srcdir)/../lib/isc/unix/stdtime.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/stdtime.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/stdtime.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/stdtime.Tpo $(DEPDIR)/stdtime.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stdtime.obj -MD -MP -MF $(DEPDIR)/stdtime.Tpo -c -o stdtime.obj `if test -f '$(srcdir)/../lib/isc/unix/stdtime.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/stdtime.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/stdtime.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stdtime.Tpo $(DEPDIR)/stdtime.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/stdtime.c' object='stdtime.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stdtime.obj `if test -f '$(srcdir)/../lib/isc/unix/stdtime.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/stdtime.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/stdtime.c'; fi` strerror.o: $(srcdir)/../lib/isc/unix/strerror.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT strerror.o -MD -MP -MF $(DEPDIR)/strerror.Tpo -c -o strerror.o `test -f '$(srcdir)/../lib/isc/unix/strerror.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/strerror.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/strerror.Tpo $(DEPDIR)/strerror.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT strerror.o -MD -MP -MF $(DEPDIR)/strerror.Tpo -c -o strerror.o `test -f '$(srcdir)/../lib/isc/unix/strerror.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/strerror.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/strerror.Tpo $(DEPDIR)/strerror.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/strerror.c' object='strerror.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o strerror.o `test -f '$(srcdir)/../lib/isc/unix/strerror.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/strerror.c strerror.obj: $(srcdir)/../lib/isc/unix/strerror.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT strerror.obj -MD -MP -MF $(DEPDIR)/strerror.Tpo -c -o strerror.obj `if test -f '$(srcdir)/../lib/isc/unix/strerror.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/strerror.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/strerror.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/strerror.Tpo $(DEPDIR)/strerror.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT strerror.obj -MD -MP -MF $(DEPDIR)/strerror.Tpo -c -o strerror.obj `if test -f '$(srcdir)/../lib/isc/unix/strerror.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/strerror.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/strerror.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/strerror.Tpo $(DEPDIR)/strerror.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/strerror.c' object='strerror.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o strerror.obj `if test -f '$(srcdir)/../lib/isc/unix/strerror.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/strerror.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/strerror.c'; fi` task.o: $(srcdir)/../lib/isc/task.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT task.o -MD -MP -MF $(DEPDIR)/task.Tpo -c -o task.o `test -f '$(srcdir)/../lib/isc/task.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/task.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/task.Tpo $(DEPDIR)/task.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT task.o -MD -MP -MF $(DEPDIR)/task.Tpo -c -o task.o `test -f '$(srcdir)/../lib/isc/task.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/task.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/task.Tpo $(DEPDIR)/task.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/task.c' object='task.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o task.o `test -f '$(srcdir)/../lib/isc/task.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/task.c task.obj: $(srcdir)/../lib/isc/task.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT task.obj -MD -MP -MF $(DEPDIR)/task.Tpo -c -o task.obj `if test -f '$(srcdir)/../lib/isc/task.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/task.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/task.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/task.Tpo $(DEPDIR)/task.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT task.obj -MD -MP -MF $(DEPDIR)/task.Tpo -c -o task.obj `if test -f '$(srcdir)/../lib/isc/task.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/task.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/task.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/task.Tpo $(DEPDIR)/task.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/task.c' object='task.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o task.obj `if test -f '$(srcdir)/../lib/isc/task.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/task.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/task.c'; fi` -thread.o: $(srcdir)/../lib/isc/nothreads/thread.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT thread.o -MD -MP -MF $(DEPDIR)/thread.Tpo -c -o thread.o `test -f '$(srcdir)/../lib/isc/nothreads/thread.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/nothreads/thread.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/thread.Tpo $(DEPDIR)/thread.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/nothreads/thread.c' object='thread.o' libtool=no @AMDEPBACKSLASH@ +thread.o: $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT thread.o -MD -MP -MF $(DEPDIR)/thread.Tpo -c -o thread.o `test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/thread.Tpo $(DEPDIR)/thread.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c' object='thread.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o thread.o `test -f '$(srcdir)/../lib/isc/nothreads/thread.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/nothreads/thread.c +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o thread.o `test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c -thread.obj: $(srcdir)/../lib/isc/nothreads/thread.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT thread.obj -MD -MP -MF $(DEPDIR)/thread.Tpo -c -o thread.obj `if test -f '$(srcdir)/../lib/isc/nothreads/thread.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/nothreads/thread.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/nothreads/thread.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/thread.Tpo $(DEPDIR)/thread.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/nothreads/thread.c' object='thread.obj' libtool=no @AMDEPBACKSLASH@ +thread.obj: $(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT thread.obj -MD -MP -MF $(DEPDIR)/thread.Tpo -c -o thread.obj `if test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/thread.Tpo $(DEPDIR)/thread.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c' object='thread.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o thread.obj `if test -f '$(srcdir)/../lib/isc/nothreads/thread.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/nothreads/thread.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/nothreads/thread.c'; fi` +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o thread.obj `if test -f '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/thread.c'; fi` time.o: $(srcdir)/../lib/isc/unix/time.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT time.o -MD -MP -MF $(DEPDIR)/time.Tpo -c -o time.o `test -f '$(srcdir)/../lib/isc/unix/time.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/time.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/time.Tpo $(DEPDIR)/time.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT time.o -MD -MP -MF $(DEPDIR)/time.Tpo -c -o time.o `test -f '$(srcdir)/../lib/isc/unix/time.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/time.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/time.Tpo $(DEPDIR)/time.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/time.c' object='time.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o time.o `test -f '$(srcdir)/../lib/isc/unix/time.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/unix/time.c time.obj: $(srcdir)/../lib/isc/unix/time.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT time.obj -MD -MP -MF $(DEPDIR)/time.Tpo -c -o time.obj `if test -f '$(srcdir)/../lib/isc/unix/time.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/time.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/time.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/time.Tpo $(DEPDIR)/time.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT time.obj -MD -MP -MF $(DEPDIR)/time.Tpo -c -o time.obj `if test -f '$(srcdir)/../lib/isc/unix/time.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/time.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/time.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/time.Tpo $(DEPDIR)/time.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/unix/time.c' object='time.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o time.obj `if test -f '$(srcdir)/../lib/isc/unix/time.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/unix/time.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/unix/time.c'; fi` +sha1.o: $(srcdir)/../lib/isc/sha1.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sha1.o -MD -MP -MF $(DEPDIR)/sha1.Tpo -c -o sha1.o `test -f '$(srcdir)/../lib/isc/sha1.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/sha1.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/sha1.Tpo $(DEPDIR)/sha1.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/sha1.c' object='sha1.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sha1.o `test -f '$(srcdir)/../lib/isc/sha1.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/sha1.c + +sha1.obj: $(srcdir)/../lib/isc/sha1.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sha1.obj -MD -MP -MF $(DEPDIR)/sha1.Tpo -c -o sha1.obj `if test -f '$(srcdir)/../lib/isc/sha1.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/sha1.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/sha1.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/sha1.Tpo $(DEPDIR)/sha1.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/sha1.c' object='sha1.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sha1.obj `if test -f '$(srcdir)/../lib/isc/sha1.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/sha1.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/sha1.c'; fi` + sockaddr.o: $(srcdir)/../lib/isc/sockaddr.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sockaddr.o -MD -MP -MF $(DEPDIR)/sockaddr.Tpo -c -o sockaddr.o `test -f '$(srcdir)/../lib/isc/sockaddr.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/sockaddr.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/sockaddr.Tpo $(DEPDIR)/sockaddr.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sockaddr.o -MD -MP -MF $(DEPDIR)/sockaddr.Tpo -c -o sockaddr.o `test -f '$(srcdir)/../lib/isc/sockaddr.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/sockaddr.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/sockaddr.Tpo $(DEPDIR)/sockaddr.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/sockaddr.c' object='sockaddr.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sockaddr.o `test -f '$(srcdir)/../lib/isc/sockaddr.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/sockaddr.c sockaddr.obj: $(srcdir)/../lib/isc/sockaddr.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sockaddr.obj -MD -MP -MF $(DEPDIR)/sockaddr.Tpo -c -o sockaddr.obj `if test -f '$(srcdir)/../lib/isc/sockaddr.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/sockaddr.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/sockaddr.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/sockaddr.Tpo $(DEPDIR)/sockaddr.Po +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sockaddr.obj -MD -MP -MF $(DEPDIR)/sockaddr.Tpo -c -o sockaddr.obj `if test -f '$(srcdir)/../lib/isc/sockaddr.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/sockaddr.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/sockaddr.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/sockaddr.Tpo $(DEPDIR)/sockaddr.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/sockaddr.c' object='sockaddr.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sockaddr.obj `if test -f '$(srcdir)/../lib/isc/sockaddr.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/sockaddr.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/sockaddr.c'; fi` +mutex.o: $(srcdir)/../lib/isc/pthreads/mutex.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mutex.o -MD -MP -MF $(DEPDIR)/mutex.Tpo -c -o mutex.o `test -f '$(srcdir)/../lib/isc/pthreads/mutex.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/pthreads/mutex.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mutex.Tpo $(DEPDIR)/mutex.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/pthreads/mutex.c' object='mutex.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mutex.o `test -f '$(srcdir)/../lib/isc/pthreads/mutex.c' || echo '$(srcdir)/'`$(srcdir)/../lib/isc/pthreads/mutex.c + +mutex.obj: $(srcdir)/../lib/isc/pthreads/mutex.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mutex.obj -MD -MP -MF $(DEPDIR)/mutex.Tpo -c -o mutex.obj `if test -f '$(srcdir)/../lib/isc/pthreads/mutex.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/pthreads/mutex.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/pthreads/mutex.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mutex.Tpo $(DEPDIR)/mutex.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../lib/isc/pthreads/mutex.c' object='mutex.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mutex.obj `if test -f '$(srcdir)/../lib/isc/pthreads/mutex.c'; then $(CYGPATH_W) '$(srcdir)/../lib/isc/pthreads/mutex.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../lib/isc/pthreads/mutex.c'; fi` + mostlyclean-libtool: -rm -f *.lo @@ -1161,7 +1507,7 @@ $(DEPDIR)/deps-ver: $(top_srcdir)/deps-ver @[ -w $@ ] || \ chmod ug+w $@ @cmp $(top_srcdir)/deps-ver $@ > /dev/null || ( \ - $(MAKE) clean && \ + $(MAKE) $(AM_MAKEFLAGS) clean && \ echo -n "Prior $(subdir)/$(DEPDIR) version " && \ cat $@ && \ rm -rf $(DEPDIR) && \ @@ -1170,17 +1516,10 @@ $(DEPDIR)/deps-ver: $(top_srcdir)/deps-ver .) \ ./config.status Makefile depfiles \ ;; \ - ..) \ - cd .. && \ - ./config.status $(subdir)/Makefile depfiles && \ - cd $(subdir) \ - ;; \ *) \ - echo 'Fatal: depsver.mf Automake fragment limited' \ - 'to immediate subdirectories.' && \ - echo "top_builddir: $(top_builddir)" && \ - echo "subdir: $(subdir)" && \ - exit 1 \ + cd "$(top_builddir)" && \ + ./config.status $(subdir)/Makefile depfiles && \ + cd $(subdir) \ ;; \ esac && \ echo -n "Cleaned $(subdir)/$(DEPDIR) version " && \ @@ -1189,7 +1528,7 @@ $(DEPDIR)/deps-ver: $(top_srcdir)/deps-ver cp $(top_srcdir)/deps-ver $@ .deps-ver: $(top_srcdir)/deps-ver - @[ ! -d $(DEPDIR) ] || $(MAKE) $(DEPDIR)/deps-ver + @[ ! -d $(DEPDIR) ] || $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/deps-ver @touch $@ # diff --git a/libntp/a_md5encrypt.c b/libntp/a_md5encrypt.c index fe5dbb0d464ad..ffabc47c7d097 100644 --- a/libntp/a_md5encrypt.c +++ b/libntp/a_md5encrypt.c @@ -9,11 +9,7 @@ #include "ntp_string.h" #include "ntp_stdlib.h" #include "ntp.h" -#ifdef OPENSSL -# include "openssl/evp.h" -#else -# include "ntp_md5.h" /* provides clone of OpenSSL MD5 API */ -#endif +#include "ntp_md5.h" /* provides OpenSSL digest API */ /* * MD5authencrypt - generate message digest @@ -38,8 +34,16 @@ MD5authencrypt( * was creaded. */ INIT_SSL(); +#if defined(OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x0090700fL + if (!EVP_DigestInit(&ctx, EVP_get_digestbynid(type))) { + msyslog(LOG_ERR, + "MAC encrypt: digest init failed"); + return (0); + } +#else EVP_DigestInit(&ctx, EVP_get_digestbynid(type)); - EVP_DigestUpdate(&ctx, key, (u_int)cache_keylen); +#endif + EVP_DigestUpdate(&ctx, key, cache_secretsize); EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length); EVP_DigestFinal(&ctx, digest, &len); memmove((u_char *)pkt + length + 4, digest, len); @@ -71,8 +75,16 @@ MD5authdecrypt( * was created. */ INIT_SSL(); +#if defined(OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x0090700fL + if (!EVP_DigestInit(&ctx, EVP_get_digestbynid(type))) { + msyslog(LOG_ERR, + "MAC decrypt: digest init failed"); + return (0); + } +#else EVP_DigestInit(&ctx, EVP_get_digestbynid(type)); - EVP_DigestUpdate(&ctx, key, (u_int)cache_keylen); +#endif + EVP_DigestUpdate(&ctx, key, cache_secretsize); EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length); EVP_DigestFinal(&ctx, digest, &len); if ((u_int)size != len + 4) { @@ -80,7 +92,7 @@ MD5authdecrypt( "MAC decrypt: MAC length error"); return (0); } - return (!memcmp(digest, (char *)pkt + length + 4, len)); + return !memcmp(digest, (char *)pkt + length + 4, len); } /* @@ -101,10 +113,25 @@ addr2refid(sockaddr_u *addr) return (NSRCADR(addr)); INIT_SSL(); - EVP_DigestInit(&ctx, EVP_get_digestbynid(NID_md5)); + +#if defined(OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x0090700fL + EVP_MD_CTX_init(&ctx); +#ifdef EVP_MD_CTX_FLAG_NON_FIPS_ALLOW + /* MD5 is not used as a crypto hash here. */ + EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); +#endif + if (!EVP_DigestInit_ex(&ctx, EVP_md5(), NULL)) { + msyslog(LOG_ERR, + "MD5 init failed"); + exit(1); + } +#else + EVP_DigestInit(&ctx, EVP_md5()); +#endif + EVP_DigestUpdate(&ctx, (u_char *)PSOCK_ADDR6(addr), sizeof(struct in6_addr)); EVP_DigestFinal(&ctx, digest, &len); - memcpy(&addr_refid, digest, 4); + memcpy(&addr_refid, digest, sizeof(addr_refid)); return (addr_refid); } diff --git a/libntp/atoint.c b/libntp/atoint.c index 46cd96d19cf73..1064b366af169 100644 --- a/libntp/atoint.c +++ b/libntp/atoint.c @@ -1,6 +1,7 @@ /* * atoint - convert an ascii string to a signed long, with error checking */ +#include <config.h> #include <sys/types.h> #include <ctype.h> diff --git a/libntp/atolfp.c b/libntp/atolfp.c index adb67936fe444..4afeb23d33aa9 100644 --- a/libntp/atolfp.c +++ b/libntp/atolfp.c @@ -1,6 +1,7 @@ /* * atolfp - convert an ascii string to an l_fp number */ +#include <config.h> #include <stdio.h> #include <ctype.h> diff --git a/libntp/atouint.c b/libntp/atouint.c index c25e3a0c51a73..ab86130dfcdc7 100644 --- a/libntp/atouint.c +++ b/libntp/atouint.c @@ -1,33 +1,40 @@ -/* - * atouint - convert an ascii string to an unsigned long, with error checking - */ +#include <config.h> #include <sys/types.h> #include <ctype.h> #include "ntp_types.h" #include "ntp_stdlib.h" +/* + * atouint() - convert an ascii string representing a whole base 10 + * number to u_long *uval, returning TRUE if successful. + * Does not modify *uval and returns FALSE if str is not + * a positive base10 integer or is too large for a u_int32. + * this function uses u_long but should use u_int32, and + * probably be renamed. + */ int atouint( const char *str, u_long *uval ) { - register u_long u; - register const char *cp; + u_long u; + const char *cp; cp = str; - if (*cp == '\0') - return 0; + if ('\0' == *cp) + return 0; u = 0; - while (*cp != '\0') { - if (!isdigit((int)*cp)) - return 0; + while ('\0' != *cp) { + if (!isdigit(*cp)) + return 0; if (u > 429496729 || (u == 429496729 && *cp >= '6')) - return 0; /* overflow */ + return 0; /* overflow */ + /* hand-optimized u *= 10; */ u = (u << 3) + (u << 1); - u += *cp++ - '0'; /* ascii dependent */ + u += *cp++ - '0'; /* not '\0' */ } *uval = u; diff --git a/libntp/audio.c b/libntp/audio.c index d9af6b51f3bc8..2a56619827f47 100644 --- a/libntp/audio.c +++ b/libntp/audio.c @@ -176,19 +176,19 @@ audio_config_read( if (!strncmp(cc, "IDEV", 4) && 1 == sscanf(ca, "%99s", ab)) { - strncpy(cf_i_dev, ab, sizeof(cf_i_dev)); + strlcpy(cf_i_dev, ab, sizeof(cf_i_dev)); printf("idev <%s>\n", ab); } else if (!strncmp(cc, "CDEV", 4) && 1 == sscanf(ca, "%99s", ab)) { - strncpy(cf_c_dev, ab, sizeof(cf_c_dev)); + strlcpy(cf_c_dev, ab, sizeof(cf_c_dev)); printf("cdev <%s>\n", ab); } else if (!strncmp(cc, "AGC", 3) && 1 == sscanf(ca, "%99s", ab)) { - strncpy(cf_agc, ab, sizeof(cf_agc)); + strlcpy(cf_agc, ab, sizeof(cf_agc)); printf("agc <%s> %d\n", ab, i); } else if (!strncmp(cc, "MONITOR", 7) && 1 == sscanf(ca, "%99s", ab)) { - strncpy(cf_monitor, ab, sizeof(cf_monitor)); + strlcpy(cf_monitor, ab, sizeof(cf_monitor)); printf("monitor <%s> %d\n", ab, mixer_name(ab, -1)); } } @@ -251,7 +251,7 @@ audio_init( */ fd = open(dname, O_RDWR | O_NONBLOCK, 0777); if (fd < 0) { - msyslog(LOG_ERR, "audio_init: %s %m\n", dname); + msyslog(LOG_ERR, "audio_init: %s %m", dname); return (fd); } @@ -260,7 +260,7 @@ audio_init( */ ctl_fd = open(actl, O_RDWR); if (ctl_fd < 0) { - msyslog(LOG_ERR, "audio_init: invalid control device <%s>\n", + msyslog(LOG_ERR, "audio_init: invalid control device <%s>", actl); close(fd); return(ctl_fd); @@ -319,7 +319,8 @@ audio_init( if (cf_agc[0] != '\0') { int i; - i = mixer_name(cf_agc, devmask); + /* recmask */ + i = mixer_name(cf_agc, recmask); if (i >= 0) agc = MIXER_WRITE(i); else @@ -348,7 +349,7 @@ audio_init( # endif /* HAVE_SYS_AUDIOIO_H */ rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info); if (rval < 0) { - msyslog(LOG_ERR, "audio: invalid control device parameters\n"); + msyslog(LOG_ERR, "audio: invalid control device parameters"); close(ctl_fd); close(fd); return(rval); diff --git a/libntp/authkeys.c b/libntp/authkeys.c index b9b76d9e6bcfc..7b4427cd2f409 100644 --- a/libntp/authkeys.c +++ b/libntp/authkeys.c @@ -5,12 +5,13 @@ # include <config.h> #endif +#include <math.h> #include <stdio.h> -#include "ntp_types.h" -#include "ntp_fp.h" #include "ntp.h" +#include "ntp_fp.h" #include "ntpd.h" +#include "ntp_lists.h" #include "ntp_string.h" #include "ntp_malloc.h" #include "ntp_stdlib.h" @@ -18,29 +19,57 @@ /* * Structure to store keys in in the hash table. */ +typedef struct savekey symkey; + struct savekey { - struct savekey *next; - union { - u_char MD5_key[64]; /* for keys up to to 512 bits */ - } k; - keyid_t keyid; /* key identifier */ - int type; /* key type */ - u_short flags; /* flags that wave */ - u_long lifetime; /* remaining lifetime */ - int keylen; /* key length */ + symkey * hlink; /* next in hash bucket */ + DECL_DLIST_LINK(symkey, llink); /* for overall & free lists */ + u_char * secret; /* shared secret */ + u_long lifetime; /* remaining lifetime */ + keyid_t keyid; /* key identifier */ + u_short type; /* OpenSSL digest NID */ + u_short secretsize; /* secret octets */ + u_short flags; /* KEY_ flags that wave */ }; +/* define the payload region of symkey beyond the list pointers */ +#define symkey_payload secret + #define KEY_TRUSTED 0x001 /* this key is trusted */ +#ifdef DEBUG +typedef struct symkey_alloc_tag symkey_alloc; + +struct symkey_alloc_tag { + symkey_alloc * link; + void * mem; /* enable free() atexit */ +}; + +symkey_alloc * authallocs; +#endif /* DEBUG */ + +static inline u_short auth_log2(double x); +static void auth_resize_hashtable(void); +static void allocsymkey(symkey **, keyid_t, u_short, + u_short, u_long, u_short, u_char *); +static void freesymkey(symkey *, symkey **); +#ifdef DEBUG +static void free_auth_mem(void); +#endif + +symkey key_listhead; /* list of all in-use keys */; /* * The hash table. This is indexed by the low order bits of the * keyid. We make this fairly big for potentially busy servers. */ -#define HASHSIZE 64 -#define HASHMASK ((HASHSIZE)-1) -#define KEYHASH(keyid) ((keyid) & HASHMASK) +#define DEF_AUTHHASHSIZE 64 +//#define HASHMASK ((HASHSIZE)-1) +#define KEYHASH(keyid) ((keyid) & authhashmask) -struct savekey *key_hash[HASHSIZE]; +int authhashdisabled; +u_short authhashbuckets = DEF_AUTHHASHSIZE; +u_short authhashmask = DEF_AUTHHASHSIZE - 1; +symkey **key_hash; u_long authkeynotfound; /* keys not found */ u_long authkeylookups; /* calls to lookup keys */ @@ -52,21 +81,21 @@ u_long authencryptions; /* calls to encrypt */ u_long authdecryptions; /* calls to decrypt */ /* - * Storage for free key structures. We malloc() such things but + * Storage for free symkey structures. We malloc() such things but * never free them. */ -struct savekey *authfreekeys; +symkey *authfreekeys; int authnumfreekeys; -#define MEMINC 12 /* number of new free ones to get */ +#define MEMINC 16 /* number of new free ones to get */ /* * The key cache. We cache the last key we looked at here. */ keyid_t cache_keyid; /* key identifier */ -u_char *cache_key; /* key pointer */ -u_int cache_keylen; /* key length */ -int cache_type; /* key type */ +u_char *cache_secret; /* secret */ +u_short cache_secretsize; /* secret length */ +int cache_type; /* OpenSSL digest NID */ u_short cache_flags; /* flags that wave */ @@ -76,10 +105,213 @@ u_short cache_flags; /* flags that wave */ void init_auth(void) { + size_t newalloc; + /* * Initialize hash table and free list */ - memset((char *)key_hash, 0, sizeof key_hash); + newalloc = authhashbuckets * sizeof(key_hash[0]); + + key_hash = erealloc(key_hash, newalloc); + memset(key_hash, '\0', newalloc); + + INIT_DLIST(key_listhead, llink); + +#ifdef DEBUG + atexit(&free_auth_mem); +#endif +} + + +/* + * free_auth_mem - assist in leak detection by freeing all dynamic + * allocations from this module. + */ +#ifdef DEBUG +static void +free_auth_mem(void) +{ + symkey * sk; + symkey_alloc * alloc; + symkey_alloc * next_alloc; + + while (NULL != (sk = HEAD_DLIST(key_listhead, llink))) { + freesymkey(sk, &key_hash[KEYHASH(sk->keyid)]); + } + free(key_hash); + key_hash = NULL; + cache_keyid = 0; + cache_flags = 0; + for (alloc = authallocs; alloc != NULL; alloc = next_alloc) { + next_alloc = alloc->link; + free(alloc->mem); + } + authfreekeys = NULL; + authnumfreekeys = 0; +} +#endif /* DEBUG */ + + +/* + * auth_moremem - get some more free key structures + */ +void +auth_moremem( + int keycount + ) +{ + symkey * sk; + int i; +#ifdef DEBUG + void * base; + symkey_alloc * allocrec; +# define MOREMEM_EXTRA_ALLOC (sizeof(*allocrec)) +#else +# define MOREMEM_EXTRA_ALLOC (0) +#endif + + i = (keycount > 0) + ? keycount + : MEMINC; + sk = emalloc_zero(i * sizeof(*sk) + MOREMEM_EXTRA_ALLOC); +#ifdef DEBUG + base = sk; +#endif + authnumfreekeys += i; + + for (; i > 0; i--, sk++) { + LINK_SLIST(authfreekeys, sk, llink.f); + } + +#ifdef DEBUG + allocrec = (void *)sk; + allocrec->mem = base; + LINK_SLIST(authallocs, allocrec, link); +#endif +} + + +/* + * auth_prealloc_symkeys + */ +void +auth_prealloc_symkeys( + int keycount + ) +{ + int allocated; + int additional; + + allocated = authnumkeys + authnumfreekeys; + additional = keycount - allocated; + if (additional > 0) + auth_moremem(additional); + auth_resize_hashtable(); +} + + +static inline u_short +auth_log2(double x) +{ + return (u_short)(log10(x) / log10(2)); +} + + +/* + * auth_resize_hashtable + * + * Size hash table to average 4 or fewer entries per bucket initially, + * within the bounds of at least 4 and no more than 15 bits for the hash + * table index. Populate the hash table. + */ +static void +auth_resize_hashtable(void) +{ + u_long totalkeys; + u_short hashbits; + u_short hash; + size_t newalloc; + symkey * sk; + + totalkeys = authnumkeys + authnumfreekeys; + hashbits = auth_log2(totalkeys / 4.0) + 1; + hashbits = max(4, hashbits); + hashbits = min(15, hashbits); + + authhashbuckets = 1 << hashbits; + authhashmask = authhashbuckets - 1; + newalloc = authhashbuckets * sizeof(key_hash[0]); + + key_hash = erealloc(key_hash, newalloc); + memset(key_hash, '\0', newalloc); + + ITER_DLIST_BEGIN(key_listhead, sk, llink, symkey) + hash = KEYHASH(sk->keyid); + LINK_SLIST(key_hash[hash], sk, hlink); + ITER_DLIST_END() +} + + +/* + * allocsymkey - common code to allocate and link in symkey + * + * secret must be allocated with a free-compatible allocator. It is + * owned by the referring symkey structure, and will be free()d by + * freesymkey(). + */ +static void +allocsymkey( + symkey ** bucket, + keyid_t id, + u_short flags, + u_short type, + u_long lifetime, + u_short secretsize, + u_char * secret + ) +{ + symkey * sk; + + if (authnumfreekeys < 1) + auth_moremem(-1); + UNLINK_HEAD_SLIST(sk, authfreekeys, llink.f); + DEBUG_ENSURE(sk != NULL); + sk->keyid = id; + sk->flags = flags; + sk->type = type; + sk->secretsize = secretsize; + sk->secret = secret; + sk->lifetime = lifetime; + LINK_SLIST(*bucket, sk, hlink); + LINK_TAIL_DLIST(key_listhead, sk, llink); + authnumfreekeys--; + authnumkeys++; +} + + +/* + * freesymkey - common code to remove a symkey and recycle its entry. + */ +static void +freesymkey( + symkey * sk, + symkey ** bucket + ) +{ + symkey * unlinked; + + if (sk->secret != NULL) { + memset(sk->secret, '\0', sk->secretsize); + free(sk->secret); + } + UNLINK_SLIST(unlinked, *bucket, sk, hlink, symkey); + DEBUG_ENSURE(sk == unlinked); + UNLINK_DLIST(sk, llink); + memset((char *)sk + offsetof(symkey, symkey_payload), '\0', + sizeof(*sk) - offsetof(symkey, symkey_payload)); + LINK_SLIST(authfreekeys, sk, llink.f); + authnumkeys--; + authnumfreekeys++; } @@ -88,59 +320,60 @@ init_auth(void) */ struct savekey * auth_findkey( - keyid_t keyno + keyid_t id ) { - struct savekey *sk; - - sk = key_hash[KEYHASH(keyno)]; - while (sk != 0) { - if (keyno == sk->keyid) - return (sk); + symkey * sk; - sk = sk->next; + for (sk = key_hash[KEYHASH(id)]; sk != NULL; sk = sk->hlink) { + if (id == sk->keyid) { + return sk; + } } - return (0); + + return NULL; } /* - * auth_havekey - return one if the key is known + * auth_havekey - return TRUE if the key id is zero or known */ int auth_havekey( - keyid_t keyno + keyid_t id ) { - struct savekey *sk; + symkey * sk; - if (keyno == 0 || (keyno == cache_keyid)) - return (1); - - sk = key_hash[KEYHASH(keyno)]; - while (sk != 0) { - if (keyno == sk->keyid) - return (1); + if (0 == id || cache_keyid == id) { + return TRUE; + } - sk = sk->next; + for (sk = key_hash[KEYHASH(id)]; sk != NULL; sk = sk->hlink) { + if (id == sk->keyid) { + return TRUE; + } } - return (0); + + return FALSE; } /* - * authhavekey - return one and cache the key, if known and trusted. + * authhavekey - return TRUE and cache the key, if zero or both known + * and trusted. */ int authhavekey( - keyid_t keyno + keyid_t id ) { - struct savekey *sk; + symkey * sk; authkeylookups++; - if (keyno == 0 || keyno == cache_keyid) - return (1); + if (0 == id || cache_keyid == id) { + return TRUE; + } /* * Seach the bin for the key. If found and the key type @@ -148,30 +381,27 @@ authhavekey( * a key or key type. In this case consider the key missing. */ authkeyuncached++; - sk = key_hash[KEYHASH(keyno)]; - while (sk != NULL) { - if (keyno == sk->keyid) { - if (sk->type == 0) { + for (sk = key_hash[KEYHASH(id)]; sk != NULL; sk = sk->hlink) { + if (id == sk->keyid) { + if (0 == sk->type) { authkeynotfound++; - return (0); + return FALSE; } break; } - sk = sk->next; } /* * If the key is not found, or if it is found but not trusted, * the key is not considered found. */ - if (sk == NULL) { + if (NULL == sk) { authkeynotfound++; - return (0); - + return FALSE; } - if (!(sk->flags & KEY_TRUSTED)) { + if (!(KEY_TRUSTED & sk->flags)) { authnokey++; - return (0); + return FALSE; } /* @@ -180,31 +410,10 @@ authhavekey( cache_keyid = sk->keyid; cache_type = sk->type; cache_flags = sk->flags; - cache_key = sk->k.MD5_key; - cache_keylen = sk->keylen; - return (1); -} - - -/* - * auth_moremem - get some more free key structures - */ -int -auth_moremem(void) -{ - struct savekey *sk; - int i; + cache_secret = sk->secret; + cache_secretsize = sk->secretsize; - sk = (struct savekey *)calloc(MEMINC, sizeof(struct savekey)); - if (sk == 0) - return (0); - - for (i = MEMINC; i > 0; i--) { - sk->next = authfreekeys; - authfreekeys = sk++; - } - authnumfreekeys += MEMINC; - return (authnumfreekeys); + return TRUE; } @@ -213,24 +422,24 @@ auth_moremem(void) */ void authtrust( - keyid_t keyno, - u_long trust + keyid_t id, + u_long trust ) { - struct savekey *sk; + symkey ** bucket; + symkey * sk; + u_long lifetime; /* * Search bin for key; if it does not exist and is untrusted, * forget it. */ - sk = key_hash[KEYHASH(keyno)]; - while (sk != 0) { - if (keyno == sk->keyid) - break; - - sk = sk->next; + bucket = &key_hash[KEYHASH(id)]; + for (sk = *bucket; sk != NULL; sk = sk->hlink) { + if (id == sk->keyid) + break; } - if (sk == 0 && !trust) + if (!trust && NULL == sk) return; /* @@ -238,16 +447,15 @@ authtrust( * exist and is to be trusted or it does exist and is or is * not to be trusted. */ - if (sk != 0) { - if (cache_keyid == keyno) { + if (sk != NULL) { + if (cache_keyid == id) { cache_flags = 0; cache_keyid = 0; } /* * Key exists. If it is to be trusted, say so and - * update its lifetime. If not, return it to the - * free list. + * update its lifetime. */ if (trust > 0) { sk->flags |= KEY_TRUSTED; @@ -257,46 +465,22 @@ authtrust( sk->lifetime = 0; return; } - sk->flags &= ~KEY_TRUSTED; { - struct savekey *skp; - - skp = key_hash[KEYHASH(keyno)]; - if (skp == sk) { - key_hash[KEYHASH(keyno)] = sk->next; - } else { - while (skp->next != sk) - skp = skp->next; - skp->next = sk->next; - } - authnumkeys--; - sk->next = authfreekeys; - authfreekeys = sk; - authnumfreekeys++; - } + /* No longer trusted, return it to the free list. */ + freesymkey(sk, bucket); return; } /* - * Here there is not key, but the key is to be trusted. There - * seems to be a disconnect here. Here we allocate a new key, - * but do not specify a key type, key or key length. - */ - if (authnumfreekeys == 0) - if (auth_moremem() == 0) - return; - - sk = authfreekeys; - authfreekeys = sk->next; - authnumfreekeys--; - sk->keyid = keyno; - sk->type = 0; - sk->keylen = 0; - sk->flags = KEY_TRUSTED; - sk->next = key_hash[KEYHASH(keyno)]; - key_hash[KEYHASH(keyno)] = sk; - authnumkeys++; - return; + * keyid is not present, but the is to be trusted. We allocate + * a new key, but do not specify a key type or secret. + */ + if (trust > 1) { + lifetime = current_time + trust; + } else { + lifetime = 0; + } + allocsymkey(bucket, id, KEY_TRUSTED, 0, lifetime, 0, NULL); } @@ -305,30 +489,26 @@ authtrust( */ int authistrusted( - keyid_t keyno + keyid_t keyno ) { - struct savekey *sk; + symkey * sk; + symkey ** bucket; if (keyno == cache_keyid) - return ((cache_flags & KEY_TRUSTED) != 0); + return !!(KEY_TRUSTED & cache_flags); authkeyuncached++; - sk = key_hash[KEYHASH(keyno)]; - while (sk != 0) { + bucket = &key_hash[KEYHASH(keyno)]; + for (sk = *bucket; sk != NULL; sk = sk->hlink) { if (keyno == sk->keyid) - break; - sk = sk->next; + break; } - if (sk == 0) { + if (NULL == sk || !(KEY_TRUSTED & sk->flags)) { authkeynotfound++; - return (0); - - } else if (!(sk->flags & KEY_TRUSTED)) { - authkeynotfound++; - return (0); + return FALSE; } - return (1); + return TRUE; } @@ -337,25 +517,32 @@ MD5auth_setkey( keyid_t keyno, int keytype, const u_char *key, - const int len + int len ) { - struct savekey *sk; + symkey * sk; + symkey ** bucket; + u_char * secret; + size_t secretsize; + DEBUG_ENSURE(keytype <= USHRT_MAX); + DEBUG_ENSURE(len < 4 * 1024); + len = max(0, len); /* * See if we already have the key. If so just stick in the * new value. */ - sk = key_hash[KEYHASH(keyno)]; - while (sk != NULL) { + bucket = &key_hash[KEYHASH(keyno)]; + for (sk = *bucket; sk != NULL; sk = sk->hlink) { if (keyno == sk->keyid) { - sk->type = keytype; - sk->keylen = min(len, sizeof(sk->k.MD5_key)); + sk->type = (u_short)keytype; + secretsize = len; + sk->secretsize = (u_short)secretsize; #ifndef DISABLE_BUG1243_FIX - memcpy(sk->k.MD5_key, key, sk->keylen); + memcpy(sk->secret, key, secretsize); #else - strncpy((char *)sk->k.MD5_key, (const char *)key, - sizeof(sk->k.MD5_key)); + strlcpy((char *)sk->secret, (const char *)key, + secretsize); #endif if (cache_keyid == keyno) { cache_flags = 0; @@ -363,117 +550,85 @@ MD5auth_setkey( } return; } - sk = sk->next; } /* * Need to allocate new structure. Do it. */ - if (0 == authnumfreekeys && !auth_moremem()) - return; - - sk = authfreekeys; - authfreekeys = sk->next; - authnumfreekeys--; - - sk->keyid = keyno; - sk->type = keytype; - sk->flags = 0; - sk->lifetime = 0; - sk->keylen = min(len, sizeof(sk->k.MD5_key)); + secretsize = len; + secret = emalloc(secretsize); #ifndef DISABLE_BUG1243_FIX - memcpy(sk->k.MD5_key, key, sk->keylen); + memcpy(secret, key, secretsize); #else - strncpy((char *)sk->k.MD5_key, (const char *)key, - sizeof(sk->k.MD5_key)); + strlcpy((char *)secret, (const char *)key, secretsize); #endif - sk->next = key_hash[KEYHASH(keyno)]; - key_hash[KEYHASH(keyno)] = sk; + allocsymkey(bucket, keyno, 0, (u_short)keytype, 0, + (u_short)secretsize, secret); #ifdef DEBUG - if (debug > 1) { - char hex[] = "0123456789abcdef"; - int j; - - printf("auth_setkey: key %d type %d len %d ", sk->keyid, - sk->type, sk->keylen); - for (j = 0; j < sk->keylen; j++) - printf("%c%c", hex[key[j] >> 4], - hex[key[j] & 0xf]); + if (debug >= 4) { + size_t j; + + printf("auth_setkey: key %d type %d len %d ", (int)keyno, + keytype, (int)secretsize); + for (j = 0; j < secretsize; j++) + printf("%02x", secret[j]); printf("\n"); } #endif - authnumkeys++; } /* - * auth_delkeys - delete all known keys, in preparation for rereading - * the keys file (presumably) + * auth_delkeys - delete non-autokey untrusted keys, and clear all info + * except the trusted bit of non-autokey trusted keys, in + * preparation for rereading the keys file. */ void auth_delkeys(void) { - struct savekey *sk; - struct savekey **skp; - int i; + symkey * sk; + + ITER_DLIST_BEGIN(key_listhead, sk, llink, symkey) + if (sk->keyid > NTP_MAXKEY) { /* autokey */ + continue; + } - for (i = 0; i < HASHSIZE; i++) { - skp = &(key_hash[i]); - sk = key_hash[i]; /* - * Leave autokey keys alone. + * Don't lose info as to which keys are trusted. */ - while (sk != 0 && sk->keyid <= NTP_MAXKEY) { - /* - * Don't lose info as to which keys are trusted. - */ - if (sk->flags & KEY_TRUSTED) { - skp = &(sk->next); - memset(&sk->k, 0, sizeof(sk->k)); - sk->lifetime = 0; - sk->keylen = 0; - sk = sk->next; - } else { - *skp = sk->next; - authnumkeys--; - sk->next = authfreekeys; - authfreekeys = sk; - authnumfreekeys++; - sk = *skp; + if (KEY_TRUSTED & sk->flags) { + if (sk->secret != NULL) { + memset(sk->secret, '\0', sk->secretsize); + free(sk->secret); } + sk->secretsize = 0; + sk->lifetime = 0; + } else { + freesymkey(sk, &key_hash[KEYHASH(sk->keyid)]); } - } + ITER_DLIST_END() } + /* * auth_agekeys - delete keys whose lifetimes have expired */ void auth_agekeys(void) { - struct savekey *sk; - struct savekey *skp; - int i; - - for (i = 0; i < HASHSIZE; i++) { - sk = skp = key_hash[i]; - while (sk != 0) { - skp = sk->next; - if (sk->lifetime > 0 && current_time > - sk->lifetime) { - authtrust(sk->keyid, 0); - authkeyexpired++; - } - sk = skp; + symkey * sk; + + ITER_DLIST_BEGIN(key_listhead, sk, llink, symkey) + if (sk->lifetime > 0 && current_time > sk->lifetime) { + freesymkey(sk, &key_hash[KEYHASH(sk->keyid)]); + authkeyexpired++; } - } -#ifdef DEBUG - if (debug) - printf("auth_agekeys: at %lu keys %lu expired %lu\n", - current_time, authnumkeys, authkeyexpired); -#endif + ITER_DLIST_END() + DPRINTF(1, ("auth_agekeys: at %lu keys %lu expired %lu\n", + current_time, authnumkeys, authkeyexpired)); } + /* * authencrypt - generate message authenticator * @@ -481,12 +636,11 @@ auth_agekeys(void) */ int authencrypt( - keyid_t keyno, - u_int32 *pkt, - int length + keyid_t keyno, + u_int32 * pkt, + int length ) -{ - +{\ /* * A zero key identifier means the sender has not verified * the last message was correctly authenticated. The MAC @@ -494,41 +648,40 @@ authencrypt( */ authencryptions++; pkt[length / 4] = htonl(keyno); - if (keyno == 0) { - return (4); + if (0 == keyno) { + return 4; + } + if (!authhavekey(keyno)) { + return 0; } - if (!authhavekey(keyno)) - return (0); - return (MD5authencrypt(cache_type, cache_key, pkt, length)); + return MD5authencrypt(cache_type, cache_secret, pkt, length); } + /* * authdecrypt - verify message authenticator * - * Returns one if authenticator valid, zero if invalid or key not found. + * Returns TRUE if authenticator valid, FALSE if invalid or not found. */ int authdecrypt( - keyid_t keyno, - u_int32 *pkt, - int length, - int size + keyid_t keyno, + u_int32 * pkt, + int length, + int size ) { - /* * A zero key identifier means the sender has not verified - * the last message was correctly authenticated. Nevertheless, - * the authenticator itself is considered valid. + * the last message was correctly authenticated. For our + * purpose this is an invalid authenticator. */ authdecryptions++; - if (keyno == 0) - return (0); - - if (!authhavekey(keyno) || size < 4) - return (0); + if (0 == keyno || !authhavekey(keyno) || size < 4) { + return FALSE; + } - return (MD5authdecrypt(cache_type, cache_key, pkt, length, - size)); + return MD5authdecrypt(cache_type, cache_secret, pkt, length, + size); } diff --git a/libntp/authreadkeys.c b/libntp/authreadkeys.c index 063515ee02c72..9b02119d169a9 100644 --- a/libntp/authreadkeys.c +++ b/libntp/authreadkeys.c @@ -12,7 +12,8 @@ #ifdef OPENSSL #include "openssl/objects.h" -#endif /* OPENSSL */ +#include "openssl/evp.h" +#endif /* OPENSSL */ /* Forwards */ static char *nexttok (char **); @@ -34,7 +35,7 @@ nexttok( * Space past white space */ while (*cp == ' ' || *cp == '\t') - cp++; + cp++; /* * Save this and space to end of token @@ -42,19 +43,19 @@ nexttok( starttok = cp; while (*cp != '\0' && *cp != '\n' && *cp != ' ' && *cp != '\t' && *cp != '#') - cp++; + cp++; /* * If token length is zero return an error, else set end of * token to zero and return start. */ if (starttok == cp) - return (NULL); + return NULL; if (*cp == ' ' || *cp == '\t') - *cp++ = '\0'; + *cp++ = '\0'; else - *cp = '\0'; + *cp = '\0'; *str = cp; return starttok; @@ -75,7 +76,7 @@ authreadkeys( keyid_t keyno; int keytype; char buf[512]; /* lots of room for line */ - u_char keystr[20]; + u_char keystr[32]; /* Bug 2537 */ int len; int j; @@ -147,7 +148,7 @@ authreadkeys( "authreadkeys: no algorithm for key %d", keyno); continue; } -#else /* OPENSSL */ +#else /* !OPENSSL follows */ /* * The key type is unused, but is required to be 'M' or @@ -159,7 +160,7 @@ authreadkeys( continue; } keytype = KEY_TYPE_MD5; -#endif /* OPENSSL */ +#endif /* !OPENSSL */ /* * Finally, get key and insert it. If it is longer than 20 @@ -174,7 +175,7 @@ authreadkeys( continue; } len = strlen(token); - if (len <= 20) { + if (len <= 20) { /* Bug 2537 */ MD5auth_setkey(keyno, keytype, (u_char *)token, len); } else { char hex[] = "0123456789abcdef"; @@ -185,17 +186,19 @@ authreadkeys( jlim = min(len, 2 * sizeof(keystr)); for (j = 0; j < jlim; j++) { ptr = strchr(hex, tolower(token[j])); - if (ptr == NULL) { - msyslog(LOG_ERR, - "authreadkeys: invalid hex digit for key %d", keyno); - continue; - } + if (ptr == NULL) + break; /* abort decoding */ temp = (u_char)(ptr - hex); if (j & 1) keystr[j / 2] |= temp; else keystr[j / 2] = temp << 4; } + if (j < jlim) { + msyslog(LOG_ERR, + "authreadkeys: invalid hex digit for key %d", keyno); + continue; + } MD5auth_setkey(keyno, keytype, keystr, jlim / 2); } } diff --git a/libntp/authusekey.c b/libntp/authusekey.c index bef7b84732489..c1d08132c318d 100644 --- a/libntp/authusekey.c +++ b/libntp/authusekey.c @@ -1,6 +1,7 @@ /* * authusekey - decode a key from ascii and use it */ +#include <config.h> #include <stdio.h> #include <ctype.h> @@ -22,14 +23,12 @@ authusekey( const u_char *str ) { - const u_char *cp; int len; - cp = str; - len = strlen((const char *)cp); - if (len == 0) + len = strlen((const char *)str); + if (0 == len) return 0; - MD5auth_setkey(keyno, keytype, str, (int)strlen((const char *)str)); + MD5auth_setkey(keyno, keytype, str, len); return 1; } diff --git a/libntp/bsd_strerror.c b/libntp/bsd_strerror.c index 9d8ae8e4f4830..5ace9aa48542e 100644 --- a/libntp/bsd_strerror.c +++ b/libntp/bsd_strerror.c @@ -39,9 +39,10 @@ strerror( static char ebuf[20]; if ((unsigned int)errnum < sys_nerr) - return(sys_errlist[errnum]); - (void)sprintf(ebuf, "Unknown error: %d", errnum); - return(ebuf); + return sys_errlist[errnum]; + snprintf(ebuf, sizeof(ebuf), "Unknown error: %d", errnum); + + return ebuf; } #else int strerror_bs; diff --git a/libntp/buftvtots.c b/libntp/buftvtots.c index d6d9300f1241a..a77e9f7c9ba27 100644 --- a/libntp/buftvtots.c +++ b/libntp/buftvtots.c @@ -9,7 +9,7 @@ #endif #include "ntp_fp.h" #include "ntp_string.h" -#include "ntp_unixtime.h" +#include "timevalops.h" #ifndef SYS_WINNT int @@ -28,26 +28,11 @@ buftvtots( /* * and use it */ - ts->l_ui = tv.tv_sec + (u_long)JAN_1970; - if (tv.tv_usec > 999999) - return 0; - TVUTOTSF(tv.tv_usec, ts->l_uf); - return 1; -} -#else /* SYS_WINNT */ -/* - * Windows doesn't have the tty_clock line discipline, so - * don't look for a timestamp where there is none. - */ -int -buftvtots( - const char *bufp, - l_fp *ts - ) -{ - UNUSED_ARG(bufp); - UNUSED_ARG(ts); + if (tv.tv_usec > MICROSECONDS - 1) + return FALSE; + + *ts = tval_stamp_to_lfp(tv); - return 0; + return TRUE; } -#endif /* SYS_WINNT */ +#endif /* !SYS_WINNT */ diff --git a/libntp/caljulian.c b/libntp/caljulian.c index 7673061b57ce8..6463699b152a3 100644 --- a/libntp/caljulian.c +++ b/libntp/caljulian.c @@ -1,13 +1,14 @@ /* * caljulian - determine the Julian date from an NTP time. + * + * (Note: since we use the GREGORIAN calendar, this should be renamed to + * 'calgregorian' eventually...) */ +#include <config.h> #include <sys/types.h> #include "ntp_types.h" #include "ntp_calendar.h" -#include "ntp_stdlib.h" -#include "ntp_fp.h" -#include "ntp_unixtime.h" #if !(defined(ISC_CHECK_ALL) || defined(ISC_CHECK_NONE) || \ defined(ISC_CHECK_ENSURE) || defined(ISC_CHECK_INSIST) || \ @@ -17,181 +18,24 @@ #include "ntp_assert.h" -#if 1 - -/* Updated 2008-11-10 Juergen Perlinger <juergen.perlinger@t-online.de> - * - * Make the conversion 2038-proof with proper NTP epoch unfolding and extended - * precision calculations. Though we should really get a 'time_t' with more - * than 32 bits at least until 2037, because the unfolding cannot work after - * the wrap of the 32-bit 'time_t'. - */ - void caljulian( - u_long ntptime, - register struct calendar *jt + uint32_t ntp, + struct calendar * jt ) { - u_long saved_time = ntptime; - u_long ntp_day; /* days (since christian era or in year) */ - u_long n400; /* # of Gregorian cycles */ - u_long n100; /* # of normal centuries */ - u_long n4; /* # of 4-year cycles */ - u_long n1; /* # of years into a leap year cycle */ - u_long sclday; /* scaled days for month conversion */ - int leaps; /* # of leaps days in year */ - time_t now; /* current system time */ - u_int32 tmplo; /* double precision tmp value / lo part */ - int32 tmphi; /* double precision tmp value / hi part */ - - NTP_INSIST(NULL != jt); - - /* - * First we have to unfold the ntp time stamp around the current time - * to make sure we are in the right epoch. Also we we do *NOT* fold - * before the begin of the first NTP epoch, so we WILL have a - * non-negative time stamp afterwards. Though at the time of this - * writing (2008 A.D.) it would be really strange to have systems - * running with clock set to he 1960's or before... - * - * But's important to use a 32 bit max signed value -- LONG_MAX is 64 - * bit on a 64-bit system, and it will give wrong results. - */ - now = time(NULL); - tmplo = (u_int32)now; -#if ( SIZEOF_TIME_T > 4 ) - tmphi = (int32)(now >> 16 >> 16); -#else - /* - * Get the correct sign extension in the high part. - * (now >> 32) may not work correctly on every 32 bit - * system, e.g. it yields garbage under Win32/VC6. - */ - tmphi = (int32)(now >> 31); -#endif + vint64 vlong; + ntpcal_split split; - M_ADD(tmphi, tmplo, 0, ((1UL << 31)-1)); /* 32-bit max signed */ - M_ADD(tmphi, tmplo, 0, JAN_1970); - if ((ntptime > tmplo) && (tmphi > 0)) - --tmphi; - tmplo = ntptime; - /* - * Now split into days and seconds-of-day, using the fact that - * SECSPERDAY (86400) == 675 * 128; we can get roughly 17000 years of - * time scale, using only 32-bit calculations. Some magic numbers here, - * sorry for that. (This could be streamlined for 64 bit machines, but - * is worth the trouble?) - */ - ntptime = tmplo & 127; /* save remainder bits */ - tmplo = (tmplo >> 7) | (tmphi << 25); - ntp_day = (u_int32)tmplo / 675; - ntptime += ((u_int32)tmplo % 675) << 7; - - /* some checks for the algorithm - * There's some 64-bit trouble out there: the original NTP time stamp - * had only 32 bits, so our calculation invariant only holds in 32 bits! - */ - NTP_ENSURE(ntptime < SECSPERDAY); - NTP_INVARIANT((u_int32)(ntptime + ntp_day * SECSPERDAY) == (u_int32)saved_time); - - /* - * Do the easy stuff first: take care of hh:mm:ss, ignoring leap - * seconds - */ - jt->second = (u_char)(ntptime % SECSPERMIN); - ntptime /= SECSPERMIN; - jt->minute = (u_char)(ntptime % MINSPERHR); - ntptime /= MINSPERHR; - jt->hour = (u_char)(ntptime); - - /* check time invariants */ - NTP_ENSURE(jt->second < SECSPERMIN); - NTP_ENSURE(jt->minute < MINSPERHR); - NTP_ENSURE(jt->hour < HRSPERDAY); - - /* - * Find the day past 1900/01/01 00:00 UTC - */ - ntp_day += DAY_NTP_STARTS - 1; /* convert to days in CE */ - n400 = ntp_day / GREGORIAN_CYCLE_DAYS; /* split off cycles */ - ntp_day %= GREGORIAN_CYCLE_DAYS; - n100 = ntp_day / GREGORIAN_NORMAL_CENTURY_DAYS; - ntp_day %= GREGORIAN_NORMAL_CENTURY_DAYS; - n4 = ntp_day / GREGORIAN_NORMAL_LEAP_CYCLE_DAYS; - ntp_day %= GREGORIAN_NORMAL_LEAP_CYCLE_DAYS; - n1 = ntp_day / DAYSPERYEAR; - ntp_day %= DAYSPERYEAR; /* now zero-based day-of-year */ - - NTP_ENSURE(ntp_day < 366); + NTP_INSIST(NULL != jt); /* - * Calculate the year and day-of-year + * Unfold ntp time around current time into NTP domain. Split + * into days and seconds, shift days into CE domain and + * process the parts. */ - jt->year = (u_short)(400*n400 + 100*n100 + 4*n4 + n1); - - if ((n100 | n1) > 3) { - /* - * If the cycle year ever comes out to 4, it must be December - * 31st of a leap year. - */ - jt->month = 12; - jt->monthday = 31; - jt->yearday = 366; - } else { - /* - * The following code is according to the excellent book - * 'Calendrical Calculations' by Nachum Dershowitz and Edward - * Reingold. It converts the day-of-year into month and - * day-of-month, using a linear transformation with integer - * truncation. Magic numbers again, but they will not be used - * anywhere else. - */ - sclday = ntp_day * 7 + 217; - leaps = ((n1 == 3) && ((n4 != 24) || (n100 == 3))) ? 1 : 0; - if (ntp_day >= (u_long)(JAN + FEB + leaps)) - sclday += (2 - leaps) * 7; - ++jt->year; - jt->month = (u_char)(sclday / 214); - jt->monthday = (u_char)((sclday % 214) / 7 + 1); - jt->yearday = (u_short)(1 + ntp_day); - } - - /* check date invariants */ - NTP_ENSURE(1 <= jt->month && jt->month <= 12); - NTP_ENSURE(1 <= jt->monthday && jt->monthday <= 31); - NTP_ENSURE(1 <= jt->yearday && jt->yearday <= 366); -} - -#else - -/* Updated 2003-12-30 TMa - - Uses common code with the *prettydate functions to convert an ntp - seconds count into a calendar date. - Will handle ntp epoch wraparound as long as the underlying os/library - does so for the unix epoch, i.e. works after 2038. -*/ - -void -caljulian( - u_long ntptime, - register struct calendar *jt - ) -{ - struct tm *tm; - NTP_REQUIRE(jt != NULL); - - tm = ntp2unix_tm(ntptime, 0); - NTP_INSIST(tm != NULL); - - jt->hour = (u_char) tm->tm_hour; - jt->minute = (u_char) tm->tm_min; - jt->month = (u_char) (tm->tm_mon + 1); - jt->monthday = (u_char) tm->tm_mday; - jt->second = (u_char) tm->tm_sec; - jt->year = (u_short) (tm->tm_year + 1900); - jt->yearday = (u_short) (tm->tm_yday + 1); /* Assumes tm_yday starts with day 0! */ + vlong = ntpcal_ntp_to_ntp(ntp, NULL); + split = ntpcal_daysplit(&vlong); + ntpcal_daysplit_to_date(jt, &split, DAY_NTP_STARTS); } -#endif diff --git a/libntp/caltontp.c b/libntp/caltontp.c index 9c4136842d9db..4246a6a5431ca 100644 --- a/libntp/caltontp.c +++ b/libntp/caltontp.c @@ -1,12 +1,14 @@ /* * caltontp - convert a date to an NTP time */ +#include <config.h> #include <sys/types.h> #include "ntp_types.h" #include "ntp_calendar.h" #include "ntp_stdlib.h" #include "ntp_assert.h" +#include "ntp_unixtime.h" /* * Juergen Perlinger, 2008-11-12 @@ -29,15 +31,15 @@ * *not* necessarily reproduce the input, especially if the time spec is more * than 68 years off from the current time... */ -u_long + +uint32_t caltontp( const struct calendar *jt ) { - ntp_u_int32_t days; /* full days in NTP epoch */ - ntp_u_int32_t years; /* complete ACE years before date */ - ntp_u_int32_t month; /* adjusted month for calendar */ - + int32_t eraday; /* CE Rata Die number */ + vint64 ntptime;/* resulting NTP time */ + NTP_INSIST(jt != NULL); NTP_REQUIRE(jt->month <= 13); /* permit month 0..13! */ @@ -48,58 +50,19 @@ caltontp( NTP_REQUIRE(jt->second <= SECSPERMIN); /* - * First convert the date to fully elapsed days since NTP epoch. The - * expressions used here give us initially days since 0001-01-01, the - * beginning of the christian era in the proleptic gregorian calendar; - * they are rebased on-the-fly into days since beginning of the NTP - * epoch, 1900-01-01. + * First convert the date to he corresponding RataDie + * number. If yearday is not zero, assume that it contains a + * useable value and avoid all calculations involving month + * and day-of-month. Do a full evaluation otherwise. */ - if (jt->yearday) { - /* - * Assume that the day-of-year contains a useable value and - * avoid all calculations involving month and day-of-month. - */ - years = jt->year - 1; - days = years * DAYSPERYEAR /* days in previous years */ - + years / 4 /* plus prior years's leap days */ - - years / 100 /* minus leapless century years */ - + years / 400 /* plus leapful Gregorian yrs */ - + jt->yearday /* days this year */ - - DAY_NTP_STARTS; /* rebase to NTP epoch */ - } else { - /* - * The following code is according to the excellent book - * 'Calendrical Calculations' by Nachum Dershowitz and Edward - * Reingold. It does a full calendar evaluation, using one of - * the alternate algorithms: Shift to a hypothetical year - * starting on the previous march,1st; merge years, month and - * days; undo the the 9 month shift (which is 306 days). The - * advantage is that we do NOT need to now whether a year is a - * leap year or not, because the leap day is the LAST day of - * the year. - */ - month = (ntp_u_int32_t)jt->month + 9; - years = jt->year - 1 + month / 12; - month %= 12; - days = years * DAYSPERYEAR /* days in previous years */ - + years / 4 /* plus prior years's leap days */ - - years / 100 /* minus leapless century years */ - + years / 400 /* plus leapful Gregorian yrs */ - + (month * 153 + 2) / 5 /* plus days before month */ - + jt->monthday /* plus day-of-month */ - - 306 /* minus 9 months */ - - DAY_NTP_STARTS; /* rebase to NTP epoch */ - } + if (jt->yearday) + eraday = ntpcal_year_to_ystart(jt->year) + + jt->yearday - 1; + else + eraday = ntpcal_date_to_rd(jt); - /* - * Do the obvious: Merge everything together, making sure integer - * promotion doesn't play dirty tricks on us; there is probably some - * redundancy in the casts, but this drives it home with force. All - * arithmetic is done modulo 2**32, because the result is truncated - * anyway. - */ - return days * SECSPERDAY - + (ntp_u_int32_t)jt->hour * MINSPERHR*SECSPERMIN - + (ntp_u_int32_t)jt->minute * SECSPERMIN - + (ntp_u_int32_t)jt->second; + ntptime = ntpcal_dayjoin(eraday - DAY_NTP_STARTS, + ntpcal_etime_to_seconds(jt->hour, jt->minute, + jt->second)); + return ntptime.d_s.lo; } diff --git a/libntp/calyearstart.c b/libntp/calyearstart.c index c5a63f729b399..9e3f58fb393d8 100644 --- a/libntp/calyearstart.c +++ b/libntp/calyearstart.c @@ -2,6 +2,7 @@ * calyearstart - determine the NTP time at midnight of January 1 in * the year of the given date. */ +#include <config.h> #include <sys/types.h> #include "ntp_types.h" @@ -10,47 +11,78 @@ #include "ntp_assert.h" /* - * Juergen Perlinger, 2008-11-12 - * Use the result of 'caljulian' to get the delta from the time stamp to the - * beginning of the year. Do not make a second trip through 'caltontp' after - * fixing the date, apart for invariant tests. + * Juergen Perlinger, 2010-05-02 + * + * Redone in terms of the calendar functions. It's rather simple: + * - expand the NTP time stamp + * - split into days and seconds since midnight, dropping the partial day + * - get full number of days before year start in NTP epoch + * - convert to seconds, truncated to 32 bits. */ -u_long -calyearstart(u_long ntp_time) +u_int32 +calyearstart(u_int32 ntptime, const time_t *pivot) { - struct calendar jt; - ntp_u_int32_t delta; + u_int32 ndays; /* elapsed days since NTP starts */ + vint64 vlong; + ntpcal_split split; - caljulian(ntp_time,&jt); + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); + ndays = ntpcal_rd_to_ystart(split.hi + DAY_NTP_STARTS) + - DAY_NTP_STARTS; + + return (u_int32)(ndays * SECSPERDAY); +} + +/* + * calmonthstart - get NTP time at midnight of the first day of the + * current month. + */ +u_int32 +calmonthstart(u_int32 ntptime, const time_t *pivot) +{ + u_int32 ndays; /* elapsed days since NTP starts */ + vint64 vlong; + ntpcal_split split; + + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); + ndays = ntpcal_rd_to_mstart(split.hi + DAY_NTP_STARTS) + - DAY_NTP_STARTS; + + return (u_int32)(ndays * SECSPERDAY); +} + +/* + * calweekstart - get NTP time at midnight of the last monday on or + * before the current date. + */ +u_int32 +calweekstart(u_int32 ntptime, const time_t *pivot) +{ + u_int32 ndays; /* elapsed days since NTP starts */ + vint64 vlong; + ntpcal_split split; + + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); + ndays = ntpcal_weekday_le(split.hi + DAY_NTP_STARTS, CAL_MONDAY) + - DAY_NTP_STARTS; + + return (u_int32)(ndays * SECSPERDAY); +} + +/* + * caldaystart - get NTP time at midnight of the current day. + */ +u_int32 +caldaystart(u_int32 ntptime, const time_t *pivot) +{ + vint64 vlong; + ntpcal_split split; + + vlong = ntpcal_ntp_to_ntp(ntptime, pivot); + split = ntpcal_daysplit(&vlong); - /* - * Now we have days since yearstart (unity-based) and the time in that - * day. Simply merge these together to seconds and subtract that from - * input time. That's faster than going through the calendar stuff - * again... - */ - delta = (ntp_u_int32_t)jt.yearday * SECSPERDAY - + (ntp_u_int32_t)jt.hour * MINSPERHR * SECSPERMIN - + (ntp_u_int32_t)jt.minute * SECSPERMIN - + (ntp_u_int32_t)jt.second - - SECSPERDAY; /* yearday is unity-based... */ - -# if ISC_CHECK_INVARIANT - /* - * check that this computes properly: do a roundtrip! That's the only - * sensible test here, but it's a rather expensive invariant... - */ - jt.yearday = 0; - jt.month = 1; - jt.monthday = 1; - jt.hour = 0; - jt.minute = 0; - jt.second = 0; - NTP_INVARIANT((ntp_u_int32_t)(caltontp(&jt) + delta) == (ntp_u_int32_t)ntp_time); -# endif - - /* The NTP time stamps (l_fp) count seconds unsigned mod 2**32, so we - * have to calculate this in the proper way! - */ - return (ntp_u_int32_t)(ntp_time - delta); + return ntptime - split.lo; } diff --git a/libntp/clocktime.c b/libntp/clocktime.c index 371859cda21cc..c1a3ba09c0af2 100644 --- a/libntp/clocktime.c +++ b/libntp/clocktime.c @@ -2,131 +2,148 @@ * clocktime - compute the NTP date from a day of year, hour, minute * and second. */ +#include <config.h> #include "ntp_fp.h" #include "ntp_unixtime.h" #include "ntp_stdlib.h" +#include "ntp_calendar.h" /* - * Hacks to avoid excercising the multiplier. I have no pride. + * We check that the time be within CLOSETIME seconds of the receive + * time stamp. This is about 4 hours, which hopefully should be wide + * enough to collect most data, while close enough to keep things from + * getting confused. */ -#define MULBY10(x) (((x)<<3) + ((x)<<1)) -#define MULBY60(x) (((x)<<6) - ((x)<<2)) /* watch overflow */ -#define MULBY24(x) (((x)<<4) + ((x)<<3)) +#define CLOSETIME (4u*60u*60u) /* - * Two days, in seconds. + * Since we try to match years, the result of a full search will not + * change when we are already less than a half year from the receive + * time stamp. Since the length of a year is variable we use a + * slightly narrower limit; this might require a full evaluation near + * the edge, but will make sure we always get the correct result. */ -#define TWODAYS (2*24*60*60) +#define NEARTIME (182u * SECSPERDAY) /* - * We demand that the time be within CLOSETIME seconds of the receive - * time stamp. This is about 4 hours, which hopefully should be - * wide enough to collect most data, while close enough to keep things - * from getting confused. + * local calendar helpers */ -#define CLOSETIME (4*60*60) - +static int32 ntp_to_year(u_int32); +static u_int32 year_to_ntp(int32); +/* + * Take a time spec given as day-of-year, hour, minute and second as + * well as a GMT offset in hours and convert it to a NTP time stamp in + * '*ts_ui'. The value will be in the range (rec_ui-0.5yrs) to + * (rec_ui+0.5yrs). A hint for the current start-of-year will be + * read from '*yearstart'. + * + * On return '*ts_ui' will always the best matching solution, and + * '*yearstart' will receive the associated start-of-year. + * + * The function will tell if the result in 'ts_ui' is in CLOSETIME + * (+/-4hrs) around the receive time by returning a non-zero value. + * + * Note: The function puts no constraints on the value ranges for the + * time specification, but evaluates the effective seconds in + * 32-bit arithmetic. + */ int clocktime( - int yday, - int hour, - int minute, - int second, - int tzoff, - u_long rec_ui, - u_long *yearstart, - u_int32 *ts_ui - ) + int yday , /* day-of-year */ + int hour , /* hour of day */ + int minute , /* minute of hour */ + int second , /* second of minute */ + int tzoff , /* hours west of GMT */ + u_int32 rec_ui , /* pivot value */ + u_long *yearstart, /* cached start-of-year, should be fixed to u_int32 */ + u_int32 *ts_ui ) /* effective time stamp */ { - register long tmp; - register u_long date; - register u_long yst; - + u_int32 ystt[3]; /* year start */ + u_int32 test[3]; /* result time stamp */ + u_int32 diff[3]; /* abs difference to receive */ + int32 y, tmp, idx, min; + /* - * Compute the offset into the year in seconds. Note that + * Compute the offset into the year in seconds. Note that * this could come out to be a negative number. */ - tmp = (long)(MULBY24((yday-1)) + hour + tzoff); - tmp = MULBY60(tmp) + (long)minute; - tmp = MULBY60(tmp) + (long)second; - + tmp = ((int32)second + + SECSPERMIN * ((int32)minute + + MINSPERHR * ((int32)hour + (int32)tzoff + + HRSPERDAY * ((int32)yday - 1)))); /* - * Initialize yearstart, if necessary. + * Based on the cached year start, do a first attempt. Be + * happy and return if this gets us better than NEARTIME to + * the receive time stamp. Do this only if the cached year + * start is not zero, which will not happen after 1900 for the + * next few thousand years. */ - yst = *yearstart; - if (yst == 0) { - yst = calyearstart(rec_ui); - *yearstart = yst; + if (*yearstart) { + /* -- get time stamp of potential solution */ + test[0] = (u_int32)(*yearstart) + tmp; + /* -- calc absolute difference to receive time */ + diff[0] = test[0] - rec_ui; + if (diff[0] >= 0x80000000u) + diff[0] = ~diff[0] + 1; + /* -- can't get closer if diff < NEARTIME */ + if (diff[0] < NEARTIME) { + *ts_ui = test[0]; + return diff[0] < CLOSETIME; + } } /* - * Now the fun begins. We demand that the received clock time - * be within CLOSETIME of the receive timestamp, but - * there is uncertainty about the year the timestamp is in. - * Use the current year start for the first check, this should - * work most of the time. + * Now the dance begins. Based on the receive time stamp and + * the seconds offset in 'tmp', we make an educated guess + * about the year to start with. This takes us on the spot + * with a fuzz of +/-1 year. + * + * We calculate the effective timestamps for the three years + * around the guess and select the entry with the minimum + * absolute difference to the receive time stamp. */ - date = (u_long)(tmp + (long)yst); - if (date < (rec_ui + CLOSETIME) && - date > (rec_ui - CLOSETIME)) { - *ts_ui = date; - return 1; + y = ntp_to_year(rec_ui - tmp); + for (idx = 0; idx < 3; idx++) { + /* -- get year start of potential solution */ + ystt[idx] = year_to_ntp(y + idx - 1); + /* -- get time stamp of potential solution */ + test[idx] = ystt[idx] + tmp; + /* -- calc absolute difference to receive time */ + diff[idx] = test[idx] - rec_ui; + if (diff[idx] >= 0x80000000u) + diff[idx] = ~diff[idx] + 1; } + /* -*- assume current year fits best, then search best fit */ + for (min = 1, idx = 0; idx < 3; idx++) + if (diff[idx] < diff[min]) + min = idx; + /* -*- store results and update year start */ + *ts_ui = test[min]; + *yearstart = ystt[min]; - /* - * Trouble. Next check is to see if the year rolled over and, if - * so, try again with the new year's start. - */ - yst = calyearstart(rec_ui); - if (yst != *yearstart) { - date = (u_long)((long)yst + tmp); - *ts_ui = date; - if (date < (rec_ui + CLOSETIME) && - date > (rec_ui - CLOSETIME)) { - *yearstart = yst; - return 1; - } - } + /* -*- tell if we could get into CLOSETIME*/ + return diff[min] < CLOSETIME; +} - /* - * Here we know the year start matches the current system - * time. One remaining possibility is that the time code - * is in the year previous to that of the system time. This - * is only worth checking if the receive timestamp is less - * than a couple of days into the new year. - */ - if ((rec_ui - yst) < TWODAYS) { - yst = calyearstart(yst - TWODAYS); - if (yst != *yearstart) { - date = (u_long)(tmp + (long)yst); - if (date < (rec_ui + CLOSETIME) && - date > (rec_ui - CLOSETIME)) { - *yearstart = yst; - *ts_ui = date; - return 1; - } - } - } +static int32 +ntp_to_year( + u_int32 ntp) +{ + vint64 t; + ntpcal_split s; - /* - * One last possibility is that the time stamp is in the year - * following the year the system is in. Try this one before - * giving up. - */ - yst = calyearstart(rec_ui + TWODAYS); - if (yst != *yearstart) { - date = (u_long)((long)yst + tmp); - if (date < (rec_ui + CLOSETIME) && - date > (rec_ui - CLOSETIME)) { - *yearstart = yst; - *ts_ui = date; - return 1; - } - } + t = ntpcal_ntp_to_ntp(ntp, NULL); + s = ntpcal_daysplit(&t); + s = ntpcal_split_eradays(s.hi + DAY_NTP_STARTS - 1, NULL); + return s.hi + 1; +} - /* - * Give it up. - */ - return 0; +static u_int32 +year_to_ntp( + int32 year) +{ + u_int32 days; + days = ntpcal_days_in_years(year-1) - DAY_NTP_STARTS + 1; + return days * SECSPERDAY; } diff --git a/libntp/clocktypes.c b/libntp/clocktypes.c index 4459830ed19de..de7f6b4f3854a 100644 --- a/libntp/clocktypes.c +++ b/libntp/clocktypes.c @@ -1,6 +1,7 @@ /* * Data for pretty printing clock types */ +#include <config.h> #include <stdio.h> #include "ntp_fp.h" @@ -100,6 +101,10 @@ struct clktype clktypes[] = { "GPS_RIPENCC" }, { REFCLK_NEOCLOCK4X, "NeoClock4X DCF77 / TDF receiver (44)", "NEOCLK4X"}, + { REFCLK_TSYNCPCI, "Spectracom TSYNC PCI timing board (45)", + "PCI_TSYNC"}, + { REFCLK_GPSDJSON, "GPSD JSON socket (46)", + "GPSD_JSON"}, { -1, "", "" } }; diff --git a/libntp/decodenetnum.c b/libntp/decodenetnum.c index f265daebf9c66..187d5cae7e5b6 100644 --- a/libntp/decodenetnum.c +++ b/libntp/decodenetnum.c @@ -51,8 +51,7 @@ decodenetnum( else if (NULL != strchr(pp + 1, ':')) cp = num; /* two or more colons */ else { /* one colon */ - strncpy(name, num, sizeof(name)); - name[sizeof(name) - 1] = '\0'; + strlcpy(name, num, sizeof(name)); cp = name; pp = strchr(cp, ':'); *pp = '\0'; @@ -74,6 +73,7 @@ decodenetnum( if (err != 0) return 0; NTP_INSIST(ai->ai_addrlen <= sizeof(*netnum)); + ZERO(*netnum); memcpy(netnum, ai->ai_addr, ai->ai_addrlen); freeaddrinfo(ai); if (NULL == port_str || 1 != sscanf(port_str, "%hu", &port)) diff --git a/libntp/dofptoa.c b/libntp/dofptoa.c index 0f96909f11751..758af2fd7f9f1 100644 --- a/libntp/dofptoa.c +++ b/libntp/dofptoa.c @@ -1,6 +1,7 @@ /* * dofptoa - do the grunge work to convert an fp number to ascii */ +#include <config.h> #include <stdio.h> #include "ntp_fp.h" @@ -32,7 +33,7 @@ dofptoa( /* * Zero out the buffer */ - memset((char *)cbuf, 0, sizeof cbuf); + ZERO(cbuf); /* * Set the pointers to point at the first @@ -116,3 +117,43 @@ dofptoa( *bp = '\0'; return buf; } + + +char * +fptoa( + s_fp fpv, + short ndec + ) +{ + u_fp plusfp; + int neg; + + neg = (fpv < 0); + if (neg) { + plusfp = (u_fp)(-fpv); + } else { + plusfp = (u_fp)fpv; + } + + return dofptoa(plusfp, neg, ndec, FALSE); +} + + +char * +fptoms( + s_fp fpv, + short ndec + ) +{ + u_fp plusfp; + int neg; + + neg = (fpv < 0); + if (neg) { + plusfp = (u_fp)(-fpv); + } else { + plusfp = (u_fp)fpv; + } + + return dofptoa(plusfp, neg, ndec, TRUE); +} diff --git a/libntp/dolfptoa.c b/libntp/dolfptoa.c index f68679cf000bb..07ead950f4559 100644 --- a/libntp/dolfptoa.c +++ b/libntp/dolfptoa.c @@ -1,6 +1,7 @@ /* * dolfptoa - do the grunge work of converting an l_fp number to decimal */ +#include <config.h> #include <stdio.h> #include "ntp_fp.h" @@ -10,20 +11,17 @@ char * dolfptoa( - u_long fpi, - u_long fpv, + u_int32 fpi, + u_int32 fpv, int neg, short ndec, int msec ) { - register u_char *cp, *cpend; - register u_long lwork; - register int dec; + u_char *cp, *cpend, *cpdec; + int dec; u_char cbuf[24]; - u_char *cpdec; - char *buf; - char *bp; + char *buf, *bp; /* * Get a string buffer before starting @@ -33,113 +31,81 @@ dolfptoa( /* * Zero the character buffer */ - memset((char *) cbuf, 0, sizeof(cbuf)); + ZERO(cbuf); /* - * safeguard against sign extensions and other mishaps on 64 bit platforms - * the code following is designed for and only for 32-bit inputs and - * only 32-bit worth of input are supplied. - */ - fpi &= 0xffffffff; - fpv &= 0xffffffff; - - /* - * Work on the integral part. This is biased by what I know - * compiles fairly well for a 68000. + * Work on the integral part. This should work reasonable on + * all machines with 32 bit arithmetic. Please note that 32 bits + * can *always* be represented with at most 10 decimal digits, + * including a possible rounding from the fractional part. */ - cp = cpend = &cbuf[10]; - lwork = fpi; - if (lwork & 0xffff0000) { - register u_long lten = 10; - register u_long ltmp; - - do { - ltmp = lwork; - lwork /= lten; - ltmp -= (lwork << 3) + (lwork << 1); - if (cp < cbuf) abort(); /* rather die a horrible death than trash the memory */ - *--cp = (u_char)ltmp; - } while (lwork & 0xffff0000); - } - if (lwork != 0) { - register u_short sten = 10; - register u_short stmp; - register u_short swork = (u_short)lwork; - - do { - stmp = swork; - swork = (u_short) (swork/sten); - stmp = (u_short)(stmp - ((swork<<3) + (swork<<1))); - if (cp < cbuf) abort(); /* rather die a horrible death than trash the memory */ - *--cp = (u_char)stmp; - } while (swork != 0); + cp = cpend = cpdec = &cbuf[10]; + for (dec = cp - cbuf; dec > 0 && fpi != 0; dec--) { + /* can add another digit */ + u_int32 digit; + + digit = fpi; + fpi /= 10U; + digit -= (fpi << 3) + (fpi << 1); /* i*10 */ + *--cp = (u_char)digit; } /* * Done that, now deal with the problem of the fraction. First * determine the number of decimal places. */ + dec = ndec; + if (dec < 0) + dec = 0; if (msec) { - dec = ndec + 3; - if (dec < 3) - dec = 3; - cpdec = &cbuf[13]; - } else { - dec = ndec; - if (dec < 0) - dec = 0; - cpdec = &cbuf[10]; + dec += 3; + cpdec += 3; } - if (dec > 12) - dec = 12; + if ((size_t)dec > sizeof(cbuf) - (cpend - cbuf)) + dec = sizeof(cbuf) - (cpend - cbuf); /* * If there's a fraction to deal with, do so. */ - if (fpv != 0) { - l_fp work; - - work.l_ui = 0; - work.l_uf = fpv; - while (dec > 0) { - l_fp ftmp; - - dec--; - /* - * The scheme here is to multiply the - * fraction (0.1234...) by ten. This moves - * a junk of BCD into the units part. - * record that and iterate. - */ - work.l_ui = 0; - L_LSHIFT(&work); - ftmp = work; - L_LSHIFT(&work); - L_LSHIFT(&work); - L_ADD(&work, &ftmp); - *cpend++ = (u_char)work.l_ui; - if (work.l_uf == 0) - break; - if (cpend > (cbuf + sizeof(cbuf))) abort(); /* rather die a horrible death than trash the memory */ - } - + for (/*NOP*/; dec > 0 && fpv != 0; dec--) { + u_int32 digit, tmph, tmpl; + /* - * Rounding is rotten + * The scheme here is to multiply the fraction + * (0.1234...) by ten. This moves a junk of BCD into + * the units part. record that and iterate. + * multiply by shift/add in two dwords. */ - if (work.l_uf & 0x80000000) { - register u_char *tp = cpend; + digit = 0; + M_LSHIFT(digit, fpv); + tmph = digit; + tmpl = fpv; + M_LSHIFT(digit, fpv); + M_LSHIFT(digit, fpv); + M_ADD(digit, fpv, tmph, tmpl); + *cpend++ = (u_char)digit; + } + + /* decide whether to round or simply extend by zeros */ + if (dec > 0) { + /* only '0' digits left -- just reposition end */ + cpend += dec; + } else { + /* some bits remain in 'fpv'; do round */ + u_char *tp = cpend; + int carry = ((fpv & 0x80000000) != 0); - *(--tp) += 1; - while (*tp >= 10) { + for (dec = tp - cbuf; carry && dec > 0; dec--) { + *--tp += 1; + if (*tp == 10) *tp = 0; - *(--tp) += 1; - }; - if (tp < cp) - cp = tp; + else + carry = FALSE; } - } - cpend += dec; + if (tp < cp) /* rounding from 999 to 1000 or similiar? */ + cp = tp; + } /* * We've now got the fraction in cbuf[], with cp pointing at @@ -148,21 +114,18 @@ dolfptoa( * Remove leading zeros, then format the number into the * buffer. */ - while (cp < cpdec) { - if (*cp != 0) - break; + while (cp < cpdec && *cp == 0) cp++; - } - if (cp == cpdec) - --cp; + if (cp >= cpdec) + cp = cpdec - 1; bp = buf; if (neg) - *bp++ = '-'; + *bp++ = '-'; while (cp < cpend) { if (cp == cpdec) - *bp++ = '.'; - *bp++ = (char)(*cp++ + '0'); /* ascii dependent? */ + *bp++ = '.'; + *bp++ = (char)(*cp++) + '0'; } *bp = '\0'; @@ -171,3 +134,41 @@ dolfptoa( */ return buf; } + + +char * +mfptoa( + u_int32 fpi, + u_int32 fpf, + short ndec + ) +{ + int isneg; + + isneg = M_ISNEG(fpi); + if (isneg) { + M_NEG(fpi, fpf); + } + + return dolfptoa(fpi, fpf, isneg, ndec, FALSE); +} + + +char * +mfptoms( + u_int32 fpi, + u_int32 fpf, + short ndec + ) +{ + int isneg; + + isneg = M_ISNEG(fpi); + if (isneg) { + M_NEG(fpi, fpf); + } + + return dolfptoa(fpi, fpf, isneg, ndec, TRUE); +} + + diff --git a/libntp/findconfig.c b/libntp/findconfig.c index 562c01764c3c1..1785ff700395b 100644 --- a/libntp/findconfig.c +++ b/libntp/findconfig.c @@ -22,7 +22,7 @@ FindConfig( struct utsname unamebuf; /* All keyed by initial target being a directory */ - (void) strcpy(result, base); + strlcpy(result, base, sizeof(result)); if (stat(result, &sbuf) == 0) { if (S_ISDIR(sbuf.st_mode)) { @@ -49,7 +49,9 @@ FindConfig( if (stat(result, &sbuf) == 0) { goto outahere; } else { - (void) strcpy(result, "/not/found"); + strlcpy(result, + "/not/found", + sizeof(result)); } } } diff --git a/libntp/fptoa.c b/libntp/fptoa.c deleted file mode 100644 index 025ad21e55b4b..0000000000000 --- a/libntp/fptoa.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * fptoa - return an asciized representation of an s_fp number - */ -#include "ntp_fp.h" -#include "ntp_stdlib.h" - -char * -fptoa( - s_fp fpv, - short ndec - ) -{ - u_fp plusfp; - int neg; - - if (fpv < 0) { - plusfp = (u_fp)(-fpv); - neg = 1; - } else { - plusfp = (u_fp)fpv; - neg = 0; - } - - return dofptoa(plusfp, neg, ndec, 0); -} diff --git a/libntp/fptoms.c b/libntp/fptoms.c deleted file mode 100644 index 0bfca55561604..0000000000000 --- a/libntp/fptoms.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * fptoms - return an asciized s_fp number in milliseconds - */ -#include "ntp_fp.h" - -char * -fptoms( - s_fp fpv, - short ndec - ) -{ - u_fp plusfp; - int neg; - - if (fpv < 0) { - plusfp = (u_fp)(-fpv); - neg = 1; - } else { - plusfp = (u_fp)fpv; - neg = 0; - } - - return dofptoa(plusfp, neg, ndec, 1); -} diff --git a/libntp/getopt.c b/libntp/getopt.c index 7b344f0dc6f4c..63c82faa6f774 100644 --- a/libntp/getopt.c +++ b/libntp/getopt.c @@ -13,6 +13,7 @@ /*LINTLIBRARY*/ +#include <config.h> #include <stdio.h> #include "ntp_stdlib.h" diff --git a/libntp/hextoint.c b/libntp/hextoint.c index a2e8c043fb350..d24b5a0bf8a53 100644 --- a/libntp/hextoint.c +++ b/libntp/hextoint.c @@ -2,6 +2,7 @@ * hextoint - convert an ascii string in hex to an unsigned * long, with error checking */ +#include <config.h> #include <ctype.h> #include "ntp_stdlib.h" diff --git a/libntp/hextolfp.c b/libntp/hextolfp.c index d0b624340d93b..8fbce2e5b8633 100644 --- a/libntp/hextolfp.c +++ b/libntp/hextolfp.c @@ -1,6 +1,7 @@ /* * hextolfp - convert an ascii hex string to an l_fp number */ +#include <config.h> #include <stdio.h> #include <ctype.h> diff --git a/libntp/humandate.c b/libntp/humandate.c index 36510c5293804..f88d8d24cb4d3 100644 --- a/libntp/humandate.c +++ b/libntp/humandate.c @@ -1,13 +1,14 @@ /* - * humandate - convert an NTP (or the current) time to something readable + * humandate.c - convert an NTP (or the current) time to something readable */ +#include <config.h> #include <stdio.h> + #include "ntp_fp.h" #include "ntp_unixtime.h" /* includes <sys/time.h> and <time.h> */ #include "lib_strbuf.h" #include "ntp_stdlib.h" -extern const char *months[]; /* prettydate.c */ /* This is used in msyslog.c; we don't want to clutter up the log with the year and day of the week, etc.; just the minimal date and time. */ @@ -32,3 +33,28 @@ humanlogtime(void) return bp; } + + +/* + * humantime() -- like humanlogtime() but without date, and with the + * time to display given as an argument. + */ +char * +humantime( + time_t cursec + ) +{ + char * bp; + struct tm * tm; + + tm = localtime(&cursec); + if (!tm) + return "--:--:--"; + + LIB_GETBUF(bp); + + snprintf(bp, LIB_BUFLENGTH, "%02d:%02d:%02d", + tm->tm_hour, tm->tm_min, tm->tm_sec); + + return bp; +} diff --git a/libntp/inttoa.c b/libntp/inttoa.c deleted file mode 100644 index f34710e1c8083..0000000000000 --- a/libntp/inttoa.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * inttoa - return an asciized signed integer - */ -#include <config.h> -#include <stdio.h> - -#include "lib_strbuf.h" -#include "ntp_stdlib.h" - -char * -inttoa( - long val - ) -{ - register char *buf; - - LIB_GETBUF(buf); - snprintf(buf, LIB_BUFLENGTH, "%ld", val); - - return buf; -} diff --git a/libntp/iosignal.c b/libntp/iosignal.c index 5859e40e0e783..8749a23b8e81f 100644 --- a/libntp/iosignal.c +++ b/libntp/iosignal.c @@ -45,7 +45,14 @@ #include "iosignal.h" #if defined(HAVE_SIGNALED_IO) +static RETSIGTYPE sigio_handler (int); + +/* consistency safegurad to catch BLOCK/UNBLOCK oversights */ static int sigio_block_count = 0; + +/* main inputhandler to be called on SIGIO */ +static input_handler_t *input_handler_callback = NULL; + # if defined(HAVE_SIGACTION) /* * If sigaction() is used for signal handling and a signal is @@ -59,40 +66,11 @@ static int sigio_block_count = 0; */ static int sigio_handler_active = 0; # endif -extern void input_handler (l_fp *); /* * SIGPOLL and SIGIO ROUTINES. */ - /* - * 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! - */ -# if defined(USE_SIGPOLL) -# undef USE_SIGPOLL -# endif -# if defined(USE_SIGIO) -# undef USE_SIGIO -# endif - -# 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_SIGIO */ /* @@ -128,7 +106,7 @@ init_clock_sig( pgrp = getpid(); if (ioctl(rio->fd, FIOSSAIOOWN, (char *)&pgrp) == -1) { - msyslog(LOG_ERR, "ioctl(FIOSSAIOOWN) fails for clock I/O: %m"); + msyslog(LOG_ERR, "ioctl(FIOSSAIOOWN) fails for clock I/O: %m - EXITING"); exit(1); /*NOTREACHED*/ } @@ -138,14 +116,14 @@ init_clock_sig( */ if (ioctl(rio->fd, FIOSNBIO, (char *)&on) == -1) { - msyslog(LOG_ERR, "ioctl(FIOSNBIO) fails for clock I/O: %m"); + msyslog(LOG_ERR, "ioctl(FIOSNBIO) fails for clock I/O: %m - EXITING"); exit(1); /*NOTREACHED*/ } if (ioctl(rio->fd, FIOSSAIOSTAT, (char *)&on) == -1) { - msyslog(LOG_ERR, "ioctl(FIOSSAIOSTAT) fails for clock I/O: %m"); + msyslog(LOG_ERR, "ioctl(FIOSSAIOSTAT) fails for clock I/O: %m - EXITING"); exit(1); /*NOTREACHED*/ } @@ -232,7 +210,7 @@ init_socket_sig( if (ioctl(fd, I_SETSIG, S_INPUT) < 0) { msyslog(LOG_ERR, - "init_socket_sig: ioctl(I_SETSIG, S_INPUT) failed: %m"); + "init_socket_sig: ioctl(I_SETSIG, S_INPUT) failed: %m - EXITING"); exit(1); } } @@ -246,7 +224,7 @@ init_socket_sig( # if defined(FIOASYNC) if (ioctl(fd, FIOASYNC, (char *)&on) == -1) { - msyslog(LOG_ERR, "ioctl(FIOASYNC) fails: %m"); + msyslog(LOG_ERR, "ioctl(FIOASYNC) fails: %m - EXITING"); exit(1); /*NOTREACHED*/ } @@ -256,13 +234,13 @@ init_socket_sig( if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { - msyslog(LOG_ERR, "fcntl(F_GETFL) fails: %m"); + msyslog(LOG_ERR, "fcntl(F_GETFL) fails: %m - EXITING"); exit(1); /*NOTREACHED*/ } if (fcntl(fd, F_SETFL, flags|FASYNC) < 0) { - msyslog(LOG_ERR, "fcntl(...|FASYNC) fails: %m"); + msyslog(LOG_ERR, "fcntl(...|FASYNC) fails: %m - EXITING"); exit(1); /*NOTREACHED*/ } @@ -280,21 +258,21 @@ init_socket_sig( # if defined(SIOCSPGRP) if (ioctl(fd, SIOCSPGRP, (char *)&pgrp) == -1) { - msyslog(LOG_ERR, "ioctl(SIOCSPGRP) fails: %m"); + msyslog(LOG_ERR, "ioctl(SIOCSPGRP) fails: %m - EXITING"); exit(1); /*NOTREACHED*/ } # elif defined(FIOSETOWN) if (ioctl(fd, FIOSETOWN, (char*)&pgrp) == -1) { - msyslog(LOG_ERR, "ioctl(FIOSETOWN) fails: %m"); + msyslog(LOG_ERR, "ioctl(FIOSETOWN) fails: %m - EXITING"); exit(1); /*NOTREACHED*/ } # elif defined(F_SETOWN) if (fcntl(fd, F_SETOWN, pgrp) == -1) { - msyslog(LOG_ERR, "fcntl(F_SETOWN) fails: %m"); + msyslog(LOG_ERR, "fcntl(F_SETOWN) fails: %m - EXITING"); exit(1); /*NOTREACHED*/ } @@ -305,7 +283,7 @@ init_socket_sig( # endif /* USE_UDP_SIGPOLL */ } -RETSIGTYPE +static RETSIGTYPE sigio_handler( int sig ) @@ -321,7 +299,8 @@ sigio_handler( msyslog(LOG_ERR, "sigio_handler: sigio_handler_active != 1"); # endif - (void)input_handler(&ts); + INSIST(input_handler_callback != NULL); + (*input_handler_callback)(&ts); # if defined(HAVE_SIGACTION) sigio_handler_active--; @@ -337,8 +316,13 @@ sigio_handler( */ # ifdef HAVE_SIGACTION void -set_signal(void) +set_signal(input_handler_t *input) { + INSIST(input != NULL); + + input_handler_callback = input; + + using_sigio = TRUE; # ifdef USE_SIGIO (void) signal_no_reset(SIGIO, sigio_handler); # endif @@ -507,8 +491,13 @@ block_sigio(void) } void -set_signal(void) +set_signal(input_handler_t *input) { + INSIST(input != NULL); + + input_handler_callback = input; + + using_sigio = TRUE; (void) signal_no_reset(SIGIO, sigio_handler); } diff --git a/libntp/lib_strbuf.c b/libntp/lib_strbuf.c index e0becbcbc4051..76f70163de981 100644 --- a/libntp/lib_strbuf.c +++ b/libntp/lib_strbuf.c @@ -7,17 +7,22 @@ #include <isc/net.h> #include <isc/result.h> + +#include "ntp_fp.h" #include "ntp_stdlib.h" #include "lib_strbuf.h" + /* * Storage declarations */ -char lib_stringbuf[LIB_NUMBUFS][LIB_BUFLENGTH]; -int lib_nextbuf; -int ipv4_works; -int ipv6_works; -int lib_inited = 0; +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. @@ -25,8 +30,10 @@ int lib_inited = 0; void init_lib(void) { - lib_nextbuf = 0; + if (lib_inited) + return; ipv4_works = (ISC_R_SUCCESS == isc_net_probeipv4()); ipv6_works = (ISC_R_SUCCESS == isc_net_probeipv6()); - lib_inited = 1; + init_systime(); + lib_inited = TRUE; } diff --git a/libntp/machines.c b/libntp/machines.c index 7b3201d4203e4..43944f9edb3f4 100644 --- a/libntp/machines.c +++ b/libntp/machines.c @@ -14,6 +14,7 @@ #include "ntp_stdlib.h" #include "ntp_unixtime.h" #include "lib_strbuf.h" +#include "ntp_debug.h" #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -432,14 +433,13 @@ ntp_set_tod( void *tzp ) { - static int tod; - int rc = -1; - int saved_errno = 0; + static int tod; + int rc; + int saved_errno; -#ifdef DEBUG - if (debug) - printf("In ntp_set_tod\n"); -#endif + TRACE(1, ("In ntp_set_tod\n")); + rc = -1; + saved_errno = 0; #ifdef HAVE_CLOCK_SETTIME if (rc && (SET_TOD_CLOCK_SETTIME == tod || !tod)) { @@ -452,12 +452,7 @@ ntp_set_tod( errno = 0; rc = clock_settime(CLOCK_REALTIME, &ts); saved_errno = errno; -#ifdef DEBUG - if (debug) { - printf("ntp_set_tod: clock_settime: %d: %s\n", - rc, strerror(saved_errno)); - } -#endif + TRACE(1, ("ntp_set_tod: clock_settime: %d %m\n", rc)); if (!tod && !rc) tod = SET_TOD_CLOCK_SETTIME; @@ -476,12 +471,7 @@ ntp_set_tod( errno = 0; rc = SETTIMEOFDAY(tvp, tzp); saved_errno = errno; -#ifdef DEBUG - if (debug) { - printf("ntp_set_tod: settimeofday: %d: %s\n", - rc, strerror(saved_errno)); - } -#endif + TRACE(1, ("ntp_set_tod: settimeofday: %d %m\n", rc)); if (!tod && !rc) tod = SET_TOD_SETTIMEOFDAY; } @@ -493,23 +483,15 @@ ntp_set_tod( errno = 0; rc = stime(&tp); /* lie as bad as SysVR4 */ saved_errno = errno; -#ifdef DEBUG - if (debug) { - printf("ntp_set_tod: stime: %d: %s\n", - rc, strerror(saved_errno)); - } -#endif + TRACE(1, ("ntp_set_tod: stime: %d %m\n", rc)); if (!tod && !rc) tod = SET_TOD_STIME; } #endif /* HAVE_STIME */ -#ifdef DEBUG - if (debug) { - printf("ntp_set_tod: Final result: %s: %d: %s\n", - set_tod_used[tod], rc, strerror(saved_errno)); - } -#endif + errno = saved_errno; /* for %m below */ + 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 */ @@ -549,16 +531,3 @@ getpass(const char * prompt) return password; } #endif /* SYS_WINNT */ - -#if !defined(HAVE_MEMSET) -void -ntp_memset( - char *a, - int x, - int c - ) -{ - while (c-- > 0) - *a++ = (char) x; -} -#endif /*POSIX*/ diff --git a/libntp/memmove.c b/libntp/memmove.c deleted file mode 100644 index 8ccc4b1bb3c4e..0000000000000 --- a/libntp/memmove.c +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifndef HAVE_MEMMOVE -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#include <string.h> - -#include "l_stdlib.h" - -/* - * sizeof(word) MUST BE A POWER OF TWO - * SO THAT wmask BELOW IS ALL ONES - */ -typedef int word; /* "word" used for optimal copy speed */ - -#define wsize sizeof(word) -#define wmask (wsize - 1) - -/* - * Copy a block of memory, handling overlap. - * This is the routine that actually implements - * (the portable versions of) bcopy, memcpy, and memmove. - */ -void * -memmove( - void *dst0, - const void *src0, - register size_t length - ) -{ - register char *dst = dst0; - register const char *src = src0; - register size_t t; - - if (length == 0 || dst == src) /* nothing to do */ - goto done; - - /* - * Macros: loop-t-times; and loop-t-times, t>0 - */ -#define TLOOP(s) if (t) TLOOP1(s) -#define TLOOP1(s) do { s; } while (--t) - - if ((unsigned long)dst < (unsigned long)src) { - /* - * Copy forward. - */ - t = (int)src; /* only need low bits */ - if ((t | (int)dst) & wmask) { - /* - * Try to align operands. This cannot be done - * unless the low bits match. - */ - if ((t ^ (int)dst) & wmask || length < wsize) - t = length; - else - t = wsize - (t & wmask); - length -= t; - TLOOP1(*dst++ = *src++); - } - /* - * Copy whole words, then mop up any trailing bytes. - */ - t = length / wsize; - TLOOP(*(word *)dst = *(const word *)src; src += wsize; - dst += wsize); - t = length & wmask; - TLOOP(*dst++ = *src++); - } else { - /* - * Copy backwards. Otherwise essentially the same. - * Alignment works as before, except that it takes - * (t&wmask) bytes to align, not wsize-(t&wmask). - */ - src += length; - dst += length; - t = (int)src; - if ((t | (int)dst) & wmask) { - if ((t ^ (int)dst) & wmask || length <= wsize) - t = length; - else - t &= wmask; - length -= t; - TLOOP1(*--dst = *--src); - } - t = length / wsize; - TLOOP(src -= wsize; dst -= wsize; - *(word *)dst = *(const word *)src); - t = length & wmask; - TLOOP(*--dst = *--src); - } - done: - return (dst0); -} -#else -int memmove_bs; -#endif diff --git a/libntp/mfptoa.c b/libntp/mfptoa.c deleted file mode 100644 index 6450b2c136be6..0000000000000 --- a/libntp/mfptoa.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * mfptoa - Return an asciized representation of a signed long fp number - */ -#include "ntp_fp.h" -#include "ntp_stdlib.h" - -char * -mfptoa( - u_long fpi, - u_long fpf, - short ndec - ) -{ - int isneg; - - if (M_ISNEG(fpi, fpf)) { - isneg = 1; - M_NEG(fpi, fpf); - } else - isneg = 0; - - return dolfptoa(fpi, fpf, isneg, ndec, 0); -} diff --git a/libntp/mfptoms.c b/libntp/mfptoms.c deleted file mode 100644 index d2bfd71eeceed..0000000000000 --- a/libntp/mfptoms.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * mfptoms - Return an asciized signed long fp number in milliseconds - */ -#include "ntp_fp.h" -#include "ntp_stdlib.h" - -char * -mfptoms( - u_long fpi, - u_long fpf, - short ndec - ) -{ - int isneg; - - if (M_ISNEG(fpi, fpf)) { - isneg = 1; - M_NEG(fpi, fpf); - } else - isneg = 0; - - return dolfptoa(fpi, fpf, isneg, ndec, 1); -} diff --git a/libntp/mktime.c b/libntp/mktime.c index f5590d1c0d61b..50d2a08104083 100644 --- a/libntp/mktime.c +++ b/libntp/mktime.c @@ -59,9 +59,10 @@ * by hand. Sorry about that. */ +#include <config.h> #include "ntp_machine.h" -#if !defined(HAVE_MKTIME) || !defined(HAVE_TIMEGM) +#if !defined(HAVE_MKTIME) || ( !defined(HAVE_TIMEGM) && defined(WANT_TIMEGM) ) #if SIZEOF_TIME_T >= 8 #error libntp supplied mktime()/timegm() do not support 64-bit time_t @@ -288,6 +289,7 @@ mktime( } #endif /* !HAVE_MKTIME */ +#ifdef WANT_TIMEGM #ifndef HAVE_TIMEGM time_t timegm( @@ -305,3 +307,4 @@ timegm( return WRONG; } #endif /* !HAVE_TIMEGM */ +#endif /* WANT_TIMEGM */ diff --git a/libntp/modetoa.c b/libntp/modetoa.c index 9daf1bb1239f1..b476bc9e90f25 100644 --- a/libntp/modetoa.c +++ b/libntp/modetoa.c @@ -1,6 +1,7 @@ /* * modetoa - return an asciized mode */ +#include <config.h> #include <stdio.h> #include "lib_strbuf.h" @@ -12,7 +13,7 @@ modetoa( ) { char *bp; - static const char *modestrings[] = { + static const char * const modestrings[] = { "unspec", "sym_active", "sym_passive", diff --git a/libntp/mstolfp.c b/libntp/mstolfp.c index e4e909df7dbeb..1a1a02b5fc463 100644 --- a/libntp/mstolfp.c +++ b/libntp/mstolfp.c @@ -1,6 +1,7 @@ /* * mstolfp - convert an ascii string in milliseconds to an l_fp number */ +#include <config.h> #include <stdio.h> #include <ctype.h> diff --git a/libntp/msutotsf.c b/libntp/msutotsf.c deleted file mode 100644 index eb3babe9cd1aa..0000000000000 --- a/libntp/msutotsf.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * msutotsf - tables for converting from a subsecond millisecond value - * to a time stamp fraction. - */ -#include <sys/types.h> - -#include "ntp_types.h" - -/* - * Index each of these tables with five bits of the (less than) 10 - * bit millisecond value. Note that the tables are rounded (not - * truncated). The error in the result will thus be +-1 low order - * bit in the time stamp fraction. - */ -u_long msutotsflo[32] = { - 0x00000000, 0x00418937, 0x0083126f, 0x00c49ba6, - 0x010624dd, 0x0147ae14, 0x0189374c, 0x01cac083, - 0x020c49ba, 0x024dd2f2, 0x028f5c29, 0x02d0e560, - 0x03126e98, 0x0353f7cf, 0x03958106, 0x03d70a3d, - 0x04189375, 0x045a1cac, 0x049ba5e3, 0x04dd2f1b, - 0x051eb852, 0x05604189, 0x05a1cac1, 0x05e353f8, - 0x0624dd2f, 0x06666666, 0x06a7ef9e, 0x06e978d5, - 0x072b020c, 0x076c8b44, 0x07ae147b, 0x07ef9db2 -}; - -u_long msutotsfhi[32] = { - 0x00000000, 0x083126e9, 0x10624dd3, 0x189374bc, - 0x20c49ba6, 0x28f5c28f, 0x3126e979, 0x39581062, - 0x4189374c, 0x49ba5e35, 0x51eb851f, 0x5a1cac08, - 0x624dd2f2, 0x6a7ef9db, 0x72b020c5, 0x7ae147ae, - 0x83126e98, 0x8b439581, 0x9374bc6a, 0x9ba5e354, - 0xa3d70a3d, 0xac083127, 0xb4395810, 0xbc6a7efa, - 0xc49ba5e3, 0xcccccccd, 0xd4fdf3b6, 0xdd2f1aa0, - 0xe5604189, 0xed916873, 0xf5c28f5c, 0xfdf3b646 -}; diff --git a/libntp/msyslog.c b/libntp/msyslog.c index 60f8a1309e86c..283414d744235 100644 --- a/libntp/msyslog.c +++ b/libntp/msyslog.c @@ -15,8 +15,9 @@ #endif #include <stdio.h> -#include "ntp.h" #include "ntp_string.h" +#include "ntp.h" +#include "ntp_debug.h" #include "ntp_syslog.h" #ifdef SYS_WINNT @@ -25,20 +26,116 @@ #endif -int syslogit = 1; +int syslogit = TRUE; int msyslog_term = FALSE; /* duplicate to stdout/err */ +int msyslog_term_pid = TRUE; +int msyslog_include_timestamp = TRUE; FILE * syslog_file; +char * syslog_fname; +char * syslog_abs_fname; -u_int32 ntp_syslogmask = ~(u_int32)0; /* libntp default is all lit */ +/* libntp default ntp_syslogmask is all bits lit */ +#define INIT_NTP_SYSLOGMASK ~(u_int32)0 +u_int32 ntp_syslogmask = INIT_NTP_SYSLOGMASK; extern char * progname; /* Declare the local functions */ void addto_syslog (int, const char *); +#ifndef VSNPRINTF_PERCENT_M void format_errmsg (char *, size_t, const char *, int); +/* format_errmsg() is under #ifndef VSNPRINTF_PERCENT_M above */ +void +format_errmsg( + char * nfmt, + size_t lennfmt, + const char * fmt, + int errval + ) +{ + char errmsg[256]; + char c; + char *n; + const char *f; + size_t len; + + n = nfmt; + f = fmt; + while ((c = *f++) != '\0' && n < (nfmt + lennfmt - 1)) { + if (c != '%') { + *n++ = c; + continue; + } + if ((c = *f++) != 'm') { + *n++ = '%'; + if ('\0' == c) + break; + *n++ = c; + continue; + } + errno_to_str(errval, errmsg, sizeof(errmsg)); + len = strlen(errmsg); + + /* Make sure we have enough space for the error message */ + if ((n + len) < (nfmt + lennfmt - 1)) { + memcpy(n, errmsg, len); + n += len; + } + } + *n = '\0'; +} +#endif /* VSNPRINTF_PERCENT_M */ + /* + * errno_to_str() - a thread-safe strerror() replacement. + * Hides the varied signatures of strerror_r(). + * For Windows, we have: + * #define errno_to_str isc_strerror + */ +#ifndef errno_to_str +void +errno_to_str( + int err, + char * buf, + size_t bufsiz + ) +{ +# if defined(STRERROR_R_CHAR_P) || !HAVE_DECL_STRERROR_R + char * pstatic; + + buf[0] = '\0'; +# ifdef STRERROR_R_CHAR_P + pstatic = strerror_r(err, buf, bufsiz); +# else + pstatic = strerror(err); +# endif + if (NULL == pstatic && '\0' == buf[0]) + snprintf(buf, bufsiz, "%s(%d): errno %d", +# ifdef STRERROR_R_CHAR_P + "strerror_r", +# else + "strerror", +# endif + err, errno); + /* protect against believing an int return is a pointer */ + else if (pstatic != buf && pstatic > (char *)bufsiz) + strlcpy(buf, pstatic, bufsiz); +# else + int rc; + + rc = strerror_r(err, buf, bufsiz); + if (rc < 0) + snprintf(buf, bufsiz, "strerror_r(%d): errno %d", + err, errno); +# endif +} +#endif /* errno_to_str */ + + +/* + * addto_syslog() * This routine adds the contents of a buffer to the syslog or an * application-specific logfile. */ @@ -55,6 +152,7 @@ addto_syslog( FILE * term_file; int log_to_term; int log_to_file; + int pid; const char * nl_or_empty; const char * human_time; @@ -87,7 +185,14 @@ addto_syslog( return; /* syslog() adds the timestamp, name, and pid */ - human_time = humanlogtime(); + if (msyslog_include_timestamp) + human_time = humanlogtime(); + else /* suppress gcc pot. uninit. warning */ + human_time = NULL; + if (msyslog_term_pid || log_to_file) + pid = getpid(); + else /* suppress gcc pot. uninit. warning */ + pid = -1; /* syslog() adds trailing \n if not present */ if ('\n' != msg[strlen(msg) - 1]) @@ -99,60 +204,24 @@ addto_syslog( term_file = (level <= LOG_ERR) ? stderr : stdout; - fprintf(term_file, "%s %s[%d]: %s%s", human_time, prog, - (int)getpid(), msg, nl_or_empty); + if (msyslog_include_timestamp) + fprintf(term_file, "%s ", human_time); + if (msyslog_term_pid) + fprintf(term_file, "%s[%d]: ", prog, pid); + fprintf(term_file, "%s%s", msg, nl_or_empty); fflush(term_file); } if (log_to_file) { - fprintf(syslog_file, "%s %s[%d]: %s%s", human_time, - prog, (int)getpid(), msg, nl_or_empty); + if (msyslog_include_timestamp) + fprintf(syslog_file, "%s ", human_time); + fprintf(syslog_file, "%s[%d]: %s%s", prog, pid, msg, + nl_or_empty); fflush(syslog_file); } } -void -format_errmsg( - char * nfmt, - size_t lennfmt, - const char * fmt, - int errval - ) -{ - char c; - char *n; - const char *f; - size_t len; - char *err; - - n = nfmt; - f = fmt; - while ((c = *f++) != '\0' && n < (nfmt + lennfmt - 1)) { - if (c != '%') { - *n++ = c; - continue; - } - if ((c = *f++) != 'm') { - *n++ = '%'; - if ('\0' == c) - break; - *n++ = c; - continue; - } - err = strerror(errval); - len = strlen(err); - - /* Make sure we have enough space for the error message */ - if ((n + len) < (nfmt + lennfmt - 1)) { - memcpy(n, err, len); - n += len; - } - } - *n = '\0'; -} - - int mvsnprintf( char * buf, @@ -287,3 +356,217 @@ msyslog( va_end(ap); addto_syslog(level, buf); } + + +/* + * Initialize the logging + * + * Called once per process, including forked children. + */ +void +init_logging( + const char * name, + u_int32 def_syslogmask, + int is_daemon + ) +{ + static int was_daemon; + const char * cp; + const char * pname; + + /* + * ntpd defaults to only logging sync-category events, when + * NLOG() is used to conditionalize. Other libntp clients + * leave it alone so that all NLOG() conditionals will fire. + * This presumes all bits lit in ntp_syslogmask can't be + * configured via logconfig and all lit is thereby a sentinel + * that ntp_syslogmask is still at its default from libntp, + * keeping in mind this function is called in forked children + * where it has already been called in the parent earlier. + * Forked children pass 0 for def_syslogmask. + */ + if (INIT_NTP_SYSLOGMASK == ntp_syslogmask && + 0 != def_syslogmask) + ntp_syslogmask = def_syslogmask; /* set more via logconfig */ + + /* + * Logging. This may actually work on the gizmo board. Find a name + * to log with by using the basename + */ + cp = strrchr(name, DIR_SEP); + if (NULL == cp) + pname = name; + else + pname = 1 + cp; /* skip DIR_SEP */ + progname = estrdup(pname); +#ifdef SYS_WINNT /* strip ".exe" */ + cp = strrchr(progname, '.'); + if (NULL != cp && !strcasecmp(cp, ".exe")) + progname[cp - progname] = '\0'; +#endif + +#if !defined(VMS) + + if (is_daemon) + was_daemon = TRUE; +# ifndef LOG_DAEMON + openlog(progname, LOG_PID); +# else /* LOG_DAEMON */ + +# ifndef LOG_NTP +# define LOG_NTP LOG_DAEMON +# endif + openlog(progname, LOG_PID | LOG_NDELAY, (was_daemon) + ? LOG_NTP + : 0); +# ifdef DEBUG + if (debug) + setlogmask(LOG_UPTO(LOG_DEBUG)); + else +# endif /* DEBUG */ + setlogmask(LOG_UPTO(LOG_DEBUG)); /* @@@ was INFO */ +# endif /* LOG_DAEMON */ +#endif /* !VMS */ +} + + +/* + * change_logfile() + * + * Used to change from syslog to a logfile, or from one logfile to + * another, and to reopen logfiles after forking. On systems where + * ntpd forks, deals with converting relative logfile paths to + * absolute (root-based) because we reopen logfiles after the current + * directory has changed. + */ +int +change_logfile( + const char * fname, + int leave_crumbs + ) +{ + FILE * new_file; + const char * log_fname; + char * abs_fname; +#if !defined(SYS_WINNT) && !defined(SYS_VXWORKS) && !defined(VMS) + char curdir[512]; + size_t cd_octets; + size_t octets; +#endif /* POSIX */ + + NTP_REQUIRE(fname != NULL); + log_fname = fname; + + /* + * In a forked child of a parent which is logging to a file + * instead of syslog, syslog_file will be NULL and both + * syslog_fname and syslog_abs_fname will be non-NULL. + * If we are given the same filename previously opened + * and it's still open, there's nothing to do here. + */ + if (syslog_file != NULL && syslog_fname != NULL && + 0 == strcmp(syslog_fname, log_fname)) + return 0; + + if (0 == strcmp(log_fname, "stderr")) { + new_file = stderr; + abs_fname = estrdup(log_fname); + } else if (0 == strcmp(log_fname, "stdout")) { + new_file = stdout; + abs_fname = estrdup(log_fname); + } else { + if (syslog_fname != NULL && + 0 == strcmp(log_fname, syslog_fname)) + log_fname = syslog_abs_fname; +#if !defined(SYS_WINNT) && !defined(SYS_VXWORKS) && !defined(VMS) + if (log_fname != syslog_abs_fname && + DIR_SEP != log_fname[0] && + 0 != strcmp(log_fname, "stderr") && + 0 != strcmp(log_fname, "stdout") && + NULL != getcwd(curdir, sizeof(curdir))) { + cd_octets = strlen(curdir); + /* trim any trailing '/' */ + if (cd_octets > 1 && + DIR_SEP == curdir[cd_octets - 1]) + cd_octets--; + octets = cd_octets; + octets += 1; /* separator '/' */ + octets += strlen(log_fname); + octets += 1; /* NUL terminator */ + abs_fname = emalloc(octets); + snprintf(abs_fname, octets, "%.*s%c%s", + (int)cd_octets, curdir, DIR_SEP, + log_fname); + } else +#endif + abs_fname = estrdup(log_fname); + TRACE(1, ("attempting to open log %s\n", abs_fname)); + new_file = fopen(abs_fname, "a"); + } + + if (NULL == new_file) { + free(abs_fname); + return -1; + } + + /* leave a pointer in the old log */ + if (leave_crumbs && (syslogit || log_fname != syslog_abs_fname)) + msyslog(LOG_NOTICE, "switching logging to file %s", + abs_fname); + + if (syslog_file != NULL && + syslog_file != stderr && syslog_file != stdout && + fileno(syslog_file) != fileno(new_file)) + fclose(syslog_file); + syslog_file = new_file; + if (log_fname == syslog_abs_fname) { + free(abs_fname); + } else { + if (syslog_abs_fname != NULL && + syslog_abs_fname != syslog_fname) + free(syslog_abs_fname); + if (syslog_fname != NULL) + free(syslog_fname); + syslog_fname = estrdup(log_fname); + syslog_abs_fname = abs_fname; + } + syslogit = FALSE; + + return 0; +} + + +/* + * setup_logfile() + * + * Redirect logging to a file if requested with -l/--logfile or via + * ntp.conf logfile directive. + * + * This routine is invoked three different times in the sequence of a + * typical daemon ntpd with DNS lookups to do. First it is invoked in + * the original ntpd process, then again in the daemon after closing + * all descriptors. In both of those cases, ntp.conf has not been + * processed, so only -l/--logfile will trigger logfile redirection in + * those invocations. Finally, if DNS names are resolved, the worker + * child invokes this routine after its fork and close of all + * descriptors. In this case, ntp.conf has been processed and any + * "logfile" directive needs to be honored in the child as well. + */ +void +setup_logfile( + const char * name + ) +{ + if (NULL == syslog_fname && NULL != name) { + if (-1 == change_logfile(name, TRUE)) + msyslog(LOG_ERR, "Cannot open log file %s, %m", + name); + return ; + } + if (NULL == syslog_fname) + return; + + if (-1 == change_logfile(syslog_fname, FALSE)) + msyslog(LOG_ERR, "Cannot reopen log file %s, %m", + syslog_fname); +} diff --git a/libntp/netof.c b/libntp/netof.c index 55a4092befe16..c8831c3dd9cda 100644 --- a/libntp/netof.c +++ b/libntp/netof.c @@ -2,6 +2,7 @@ * netof - return the net address part of an ip address in a sockaddr_storage structure * (zero out host part) */ +#include <config.h> #include <stdio.h> #include <syslog.h> @@ -42,7 +43,7 @@ netof( } else if (IS_IPV6(netaddr)) /* assume the typical /64 subnet size */ - memset(&NSRCADR6(netaddr)[8], 0, 8); + zero_mem(&NSRCADR6(netaddr)[8], 8); #ifdef DEBUG else { msyslog(LOG_ERR, "netof unknown AF %d", AF(netaddr)); diff --git a/libntp/ntp_calendar.c b/libntp/ntp_calendar.c new file mode 100644 index 0000000000000..e557f4ec682e1 --- /dev/null +++ b/libntp/ntp_calendar.c @@ -0,0 +1,1615 @@ +/* + * ntp_calendar.c - calendar and helper functions + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + */ +#include <config.h> +#include <sys/types.h> + +#include "ntp_types.h" +#include "ntp_calendar.h" +#include "ntp_stdlib.h" +#include "ntp_fp.h" +#include "ntp_unixtime.h" + +/* + *--------------------------------------------------------------------- + * replacing the 'time()' function + * -------------------------------------------------------------------- + */ + +static systime_func_ptr systime_func = &time; +static inline time_t now(void); + + +systime_func_ptr +ntpcal_set_timefunc( + systime_func_ptr nfunc + ) +{ + systime_func_ptr res; + + res = systime_func; + if (NULL == nfunc) + nfunc = &time; + systime_func = nfunc; + + return res; +} + + +static inline time_t +now(void) +{ + return (*systime_func)(NULL); +} + +/* + *--------------------------------------------------------------------- + * Convert between 'time_t' and 'vint64' + *--------------------------------------------------------------------- + */ +vint64 +time_to_vint64( + const time_t * ptt + ) +{ + vint64 res; + time_t tt; + + tt = *ptt; + +#if SIZEOF_TIME_T <= 4 + + res.D_s.hi = 0; + if (tt < 0) { + res.D_s.lo = (uint32_t)-tt; + M_NEG(res.D_s.hi, res.D_s.lo); + } else { + res.D_s.lo = (uint32_t)tt; + } + +#elif defined(HAVE_INT64) + + res.q_s = tt; + +#else + /* + * shifting negative signed quantities is compiler-dependent, so + * we better avoid it and do it all manually. And shifting more + * than the width of a quantity is undefined. Also a don't do! + */ + if (tt < 0) { + tt = -tt; + res.D_s.lo = (uint32_t)tt; + res.D_s.hi = (uint32_t)(tt >> 32); + M_NEG(res.D_s.hi, res.D_s.lo); + } else { + res.D_s.lo = (uint32_t)tt; + res.D_s.hi = (uint32_t)(tt >> 32); + } + +#endif + + return res; +} + + +time_t +vint64_to_time( + const vint64 *tv + ) +{ + time_t res; + +#if SIZEOF_TIME_T <= 4 + + res = (time_t)tv->D_s.lo; + +#elif defined(HAVE_INT64) + + res = (time_t)tv->q_s; + +#else + + res = ((time_t)tv->d_s.hi << 32) | tv->D_s.lo; + +#endif + + return res; +} + +/* + *--------------------------------------------------------------------- + * Get the build date & time + *--------------------------------------------------------------------- + */ +int +ntpcal_get_build_date( + struct calendar * jd + ) +{ + /* The C standard tells us the format of '__DATE__': + * + * __DATE__ The date of translation of the preprocessing + * translation unit: a character string literal of the form "Mmm + * dd yyyy", where the names of the months are the same as those + * generated by the asctime function, and the first character of + * dd is a space character if the value is less than 10. If the + * date of translation is not available, an + * implementation-defined valid date shall be supplied. + * + * __TIME__ The time of translation of the preprocessing + * translation unit: a character string literal of the form + * "hh:mm:ss" as in the time generated by the asctime + * function. If the time of translation is not available, an + * implementation-defined valid time shall be supplied. + * + * Note that MSVC declares DATE and TIME to be in the local time + * zone, while neither the C standard nor the GCC docs make any + * statement about this. As a result, we may be +/-12hrs off + * UTC. But for practical purposes, this should not be a + * problem. + * + */ + static const char build[] = __TIME__ "/" __DATE__; + static const char mlist[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + char monstr[4]; + const char * cp; + unsigned short hour, minute, second, day, year; + /* Note: The above quantities are used for sscanf 'hu' format, + * so using 'uint16_t' is contra-indicated! + */ + +#ifdef DEBUG + static int ignore = 0; +#endif + + ZERO(*jd); + jd->year = 1970; + jd->month = 1; + jd->monthday = 1; + +#ifdef DEBUG + /* check environment if build date should be ignored */ + if (0 == ignore) { + const char * envstr; + envstr = getenv("NTPD_IGNORE_BUILD_DATE"); + ignore = 1 + (envstr && (!*envstr || !strcasecmp(envstr, "yes"))); + } + if (ignore > 1) + return FALSE; +#endif + + if (6 == sscanf(build, "%hu:%hu:%hu/%3s %hu %hu", + &hour, &minute, &second, monstr, &day, &year)) { + cp = strstr(mlist, monstr); + if (NULL != cp) { + jd->year = year; + jd->month = (uint8_t)((cp - mlist) / 3 + 1); + jd->monthday = (uint8_t)day; + jd->hour = (uint8_t)hour; + jd->minute = (uint8_t)minute; + jd->second = (uint8_t)second; + + return TRUE; + } + } + + return FALSE; +} + + +/* + *--------------------------------------------------------------------- + * basic calendar stuff + * -------------------------------------------------------------------- + */ + +/* month table for a year starting with March,1st */ +static const uint16_t shift_month_table[13] = { + 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337, 366 +}; + +/* month tables for years starting with January,1st; regular & leap */ +static const uint16_t real_month_table[2][13] = { + /* -*- table for regular years -*- */ + { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, + /* -*- table for leap years -*- */ + { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } +}; + +/* + * Some notes on the terminology: + * + * We use the proleptic Gregorian calendar, which is the Gregorian + * calendar extended in both directions ad infinitum. This totally + * disregards the fact that this calendar was invented in 1582, and + * was adopted at various dates over the world; sometimes even after + * the start of the NTP epoch. + * + * Normally date parts are given as current cycles, while time parts + * are given as elapsed cycles: + * + * 1970-01-01/03:04:05 means 'IN the 1970st. year, IN the first month, + * ON the first day, with 3hrs, 4minutes and 5 seconds elapsed. + * + * The basic calculations for this calendar implementation deal with + * ELAPSED date units, which is the number of full years, full months + * and full days before a date: 1970-01-01 would be (1969, 0, 0) in + * that notation. + * + * To ease the numeric computations, month and day values outside the + * normal range are acceptable: 2001-03-00 will be treated as the day + * before 2001-03-01, 2000-13-32 will give the same result as + * 2001-02-01 and so on. + * + * 'rd' or 'RD' is used as an abbreviation for the latin 'rata die' + * (day number). This is the number of days elapsed since 0000-12-31 + * in the proleptic Gregorian calendar. The begin of the Christian Era + * (0001-01-01) is RD(1). + * + * + * Some notes on the implementation: + * + * Calendar algorithms thrive on the division operation, which is one of + * the slowest numerical operations in any CPU. What saves us here from + * abysmal performance is the fact that all divisions are divisions by + * constant numbers, and most compilers can do this by a multiplication + * operation. But this might not work when using the div/ldiv/lldiv + * function family, because many compilers are not able to do inline + * expansion of the code with following optimisation for the + * constant-divider case. + * + * Also div/ldiv/lldiv are defined in terms of int/long/longlong, which + * are inherently target dependent. Nothing that could not be cured with + * autoconf, but still a mess... + * + * Furthermore, we need floor division while C demands truncation to + * zero, so additional steps are required to make sure the algorithms + * work. + * + * For all this, all divisions by constant are coded manually, even when + * there is a joined div/mod operation: The optimiser should sort that + * out, if possible. + * + * Finally, the functions do not check for overflow conditions. This + * is a sacrifice made for execution speed; since a 32-bit day counter + * covers +/- 5,879,610 years, this should not pose a problem here. + */ + + +/* + * ================================================================== + * + * General algorithmic stuff + * + * ================================================================== + */ + +/* + *--------------------------------------------------------------------- + * Do a periodic extension of 'value' around 'pivot' with a period of + * 'cycle'. + * + * The result 'res' is a number that holds to the following properties: + * + * 1) res MOD cycle == value MOD cycle + * 2) pivot <= res < pivot + cycle + * (replace </<= with >/>= for negative cycles) + * + * where 'MOD' denotes the modulo operator for FLOOR DIVISION, which + * is not the same as the '%' operator in C: C requires division to be + * a truncated division, where remainder and dividend have the same + * sign if the remainder is not zero, whereas floor division requires + * divider and modulus to have the same sign for a non-zero modulus. + * + * This function has some useful applications: + * + * + let Y be a calendar year and V a truncated 2-digit year: then + * periodic_extend(Y-50, V, 100) + * is the closest expansion of the truncated year with respect to + * the full year, that is a 4-digit year with a difference of less + * than 50 years to the year Y. ("century unfolding") + * + * + let T be a UN*X time stamp and V be seconds-of-day: then + * perodic_extend(T-43200, V, 86400) + * is a time stamp that has the same seconds-of-day as the input + * value, with an absolute difference to T of <= 12hrs. ("day + * unfolding") + * + * + Wherever you have a truncated periodic value and a non-truncated + * base value and you want to match them somehow... + * + * Basically, the function delivers 'pivot + (value - pivot) % cycle', + * but the implementation takes some pains to avoid internal signed + * integer overflows in the '(value - pivot) % cycle' part and adheres + * to the floor division convention. + * + * If 64bit scalars where available on all intended platforms, writing a + * version that uses 64 bit ops would be easy; writing a general + * division routine for 64bit ops on a platform that can only do + * 32/16bit divisions and is still performant is a bit more + * difficult. Since most usecases can be coded in a way that does only + * require the 32-bit version a 64bit version is NOT provided here. + * --------------------------------------------------------------------- + */ +int32_t +ntpcal_periodic_extend( + int32_t pivot, + int32_t value, + int32_t cycle + ) +{ + uint32_t diff; + char cpl = 0; /* modulo complement flag */ + char neg = 0; /* sign change flag */ + + /* make the cycle positive and adjust the flags */ + if (cycle < 0) { + cycle = - cycle; + neg ^= 1; + cpl ^= 1; + } + /* guard against div by zero or one */ + if (cycle > 1) { + /* + * Get absolute difference as unsigned quantity and + * the complement flag. This is done by always + * subtracting the smaller value from the bigger + * one. This implementation works only on a two's + * complement machine! + */ + if (value >= pivot) { + diff = (uint32_t)value - (uint32_t)pivot; + } else { + diff = (uint32_t)pivot - (uint32_t)value; + cpl ^= 1; + } + diff %= (uint32_t)cycle; + if (diff) { + if (cpl) + diff = cycle - diff; + if (neg) + diff = ~diff + 1; + pivot += diff; + } + } + return pivot; +} + +/* + *------------------------------------------------------------------- + * Convert a timestamp in NTP scale to a 64bit seconds value in the UN*X + * scale with proper epoch unfolding around a given pivot or the current + * system time. This function happily accepts negative pivot values as + * timestamps befor 1970-01-01, so be aware of possible trouble on + * platforms with 32bit 'time_t'! + * + * This is also a periodic extension, but since the cycle is 2^32 and + * the shift is 2^31, we can do some *very* fast math without explicit + * divisions. + *------------------------------------------------------------------- + */ +vint64 +ntpcal_ntp_to_time( + uint32_t ntp, + const time_t * pivot + ) +{ + vint64 res; + +#ifdef HAVE_INT64 + + res.q_s = (pivot != NULL) + ? *pivot + : now(); + res.Q_s -= 0x80000000; /* unshift of half range */ + ntp -= (uint32_t)JAN_1970; /* warp into UN*X domain */ + ntp -= res.D_s.lo; /* cycle difference */ + res.Q_s += (uint64_t)ntp; /* get expanded time */ + +#else /* no 64bit scalars */ + + time_t tmp; + + tmp = (pivot != NULL) + ? *pivot + : now(); + res = time_to_vint64(&tmp); + M_SUB(res.D_s.hi, res.D_s.lo, 0, 0x80000000); + ntp -= (uint32_t)JAN_1970; /* warp into UN*X domain */ + ntp -= res.D_s.lo; /* cycle difference */ + M_ADD(res.D_s.hi, res.D_s.lo, 0, ntp); + +#endif /* no 64bit scalars */ + + return res; +} + +/* + *------------------------------------------------------------------- + * Convert a timestamp in NTP scale to a 64bit seconds value in the NTP + * scale with proper epoch unfolding around a given pivot or the current + * system time. + * + * Note: The pivot must be given in the UN*X time domain! + * + * This is also a periodic extension, but since the cycle is 2^32 and + * the shift is 2^31, we can do some *very* fast math without explicit + * divisions. + *------------------------------------------------------------------- + */ +vint64 +ntpcal_ntp_to_ntp( + uint32_t ntp, + const time_t *pivot + ) +{ + vint64 res; + +#ifdef HAVE_INT64 + + res.q_s = (pivot) + ? *pivot + : now(); + res.Q_s -= 0x80000000; /* unshift of half range */ + res.Q_s += (uint32_t)JAN_1970; /* warp into NTP domain */ + ntp -= res.D_s.lo; /* cycle difference */ + res.Q_s += (uint64_t)ntp; /* get expanded time */ + +#else /* no 64bit scalars */ + + time_t tmp; + + tmp = (pivot) + ? *pivot + : now(); + res = time_to_vint64(&tmp); + M_SUB(res.D_s.hi, res.D_s.lo, 0, 0x80000000u); + M_ADD(res.D_s.hi, res.D_s.lo, 0, (uint32_t)JAN_1970);/*into NTP */ + ntp -= res.D_s.lo; /* cycle difference */ + M_ADD(res.D_s.hi, res.D_s.lo, 0, ntp); + +#endif /* no 64bit scalars */ + + return res; +} + + +/* + * ================================================================== + * + * Splitting values to composite entities + * + * ================================================================== + */ + +/* + *------------------------------------------------------------------- + * Split a 64bit seconds value into elapsed days in 'res.hi' and + * elapsed seconds since midnight in 'res.lo' using explicit floor + * division. This function happily accepts negative time values as + * timestamps before the respective epoch start. + * ------------------------------------------------------------------- + */ +ntpcal_split +ntpcal_daysplit( + const vint64 *ts + ) +{ + ntpcal_split res; + +#ifdef HAVE_INT64 + + /* manual floor division by SECSPERDAY */ + res.hi = (int32_t)(ts->q_s / SECSPERDAY); + res.lo = (int32_t)(ts->q_s % SECSPERDAY); + if (res.lo < 0) { + res.hi -= 1; + res.lo += SECSPERDAY; + } + +#else + + /* + * since we do not have 64bit ops, we have to this by hand. + * Luckily SECSPERDAY is 86400 is 675*128, so we do the division + * using chained 32/16 bit divisions and shifts. + */ + vint64 op; + uint32_t q, r, a; + int isneg; + + memcpy(&op, ts, sizeof(op)); + /* fix sign */ + isneg = M_ISNEG(op.D_s.hi); + if (isneg) + M_NEG(op.D_s.hi, op.D_s.lo); + + /* save remainder of DIV 128, shift for divide */ + r = op.D_s.lo & 127; /* save remainder bits */ + op.D_s.lo = (op.D_s.lo >> 7) | (op.D_s.hi << 25); + op.D_s.hi = (op.D_s.hi >> 7); + + /* now do a mnual division, trying to remove as many ops as + * possible -- division is always slow! An since we do not have + * the advantage of a specific 64/32 bit or even a specific 32/16 + * bit division op, but must use the general 32/32bit division + * even if we *know* the divider fits into unsigned 16 bits, the + * exra code pathes should pay off. + */ + a = op.D_s.hi; + if (a > 675u) + a = a % 675u; + if (a) { + a = (a << 16) | op.W_s.lh; + q = a / 675u; + a = a % 675u; + + a = (a << 16) | op.W_s.ll; + q = (q << 16) | (a / 675u); + } else { + a = op.D_s.lo; + q = a / 675u; + } + a = a % 675u; + + /* assemble remainder */ + r |= a << 7; + + /* fix sign of result */ + if (isneg) { + if (r) { + r = SECSPERDAY - r; + q = ~q; + } else + q = ~q + 1; + } + + res.hi = q; + res.lo = r; + +#endif + return res; +} + +/* + *------------------------------------------------------------------- + * Split a 32bit seconds value into h/m/s and excessive days. This + * function happily accepts negative time values as timestamps before + * midnight. + * ------------------------------------------------------------------- + */ +static int32_t +priv_timesplit( + int32_t split[3], + int32_t ts + ) +{ + int32_t days = 0; + + /* make sure we have a positive offset into a day */ + if (ts < 0 || ts >= SECSPERDAY) { + days = ts / SECSPERDAY; + ts = ts % SECSPERDAY; + if (ts < 0) { + days -= 1; + ts += SECSPERDAY; + } + } + + /* get secs, mins, hours */ + split[2] = (uint8_t)(ts % SECSPERMIN); + ts /= SECSPERMIN; + split[1] = (uint8_t)(ts % MINSPERHR); + split[0] = (uint8_t)(ts / MINSPERHR); + + return days; +} + +/* + * --------------------------------------------------------------------- + * Given the number of elapsed days in the calendar era, split this + * number into the number of elapsed years in 'res.hi' and the number + * of elapsed days of that year in 'res.lo'. + * + * if 'isleapyear' is not NULL, it will receive an integer that is 0 for + * regular years and a non-zero value for leap years. + *--------------------------------------------------------------------- + */ +ntpcal_split +ntpcal_split_eradays( + int32_t days, + int *isleapyear + ) +{ + ntpcal_split res; + int32_t n400, n100, n004, n001, yday; /* calendar year cycles */ + + /* + * Split off calendar cycles, using floor division in the first + * step. After that first step, simple division does it because + * all operands are positive; alas, we have to be aware of the + * possibe cycle overflows for 100 years and 1 year, caused by + * the additional leap day. + */ + n400 = days / GREGORIAN_CYCLE_DAYS; + yday = days % GREGORIAN_CYCLE_DAYS; + if (yday < 0) { + n400 -= 1; + yday += GREGORIAN_CYCLE_DAYS; + } + n100 = yday / GREGORIAN_NORMAL_CENTURY_DAYS; + yday = yday % GREGORIAN_NORMAL_CENTURY_DAYS; + n004 = yday / GREGORIAN_NORMAL_LEAP_CYCLE_DAYS; + yday = yday % GREGORIAN_NORMAL_LEAP_CYCLE_DAYS; + n001 = yday / DAYSPERYEAR; + yday = yday % DAYSPERYEAR; + + /* + * check for leap cycle overflows and calculate the leap flag + * if needed + */ + if ((n001 | n100) > 3) { + /* hit last day of leap year */ + n001 -= 1; + yday += DAYSPERYEAR; + if (isleapyear) + *isleapyear = 1; + } else if (isleapyear) + *isleapyear = (n001 == 3) && ((n004 != 24) || (n100 == 3)); + + /* now merge the cycles to elapsed years, using horner scheme */ + res.hi = ((4*n400 + n100)*25 + n004)*4 + n001; + res.lo = yday; + + return res; +} + +/* + *--------------------------------------------------------------------- + * Given a number of elapsed days in a year and a leap year indicator, + * split the number of elapsed days into the number of elapsed months in + * 'res.hi' and the number of elapsed days of that month in 'res.lo'. + * + * This function will fail and return {-1,-1} if the number of elapsed + * days is not in the valid range! + *--------------------------------------------------------------------- + */ +ntpcal_split +ntpcal_split_yeardays( + int32_t eyd, + int isleapyear + ) +{ + ntpcal_split res; + const uint16_t *lt; /* month length table */ + + /* check leap year flag and select proper table */ + lt = real_month_table[(isleapyear != 0)]; + if (0 <= eyd && eyd < lt[12]) { + /* get zero-based month by approximation & correction step */ + res.hi = eyd >> 5; /* approx month; might be 1 too low */ + if (lt[res.hi + 1] <= eyd) /* fixup approximative month value */ + res.hi += 1; + res.lo = eyd - lt[res.hi]; + } else { + res.lo = res.hi = -1; + } + + return res; +} + +/* + *--------------------------------------------------------------------- + * Convert a RD into the date part of a 'struct calendar'. + *--------------------------------------------------------------------- + */ +int +ntpcal_rd_to_date( + struct calendar *jd, + int32_t rd + ) +{ + ntpcal_split split; + int leaps; + int retv; + + leaps = 0; + retv = 0; + /* get day-of-week first */ + jd->weekday = rd % 7; + if (jd->weekday >= 7) /* unsigned! */ + jd->weekday += 7; + + split = ntpcal_split_eradays(rd - 1, &leaps); + retv = leaps; + /* get year and day-of-year */ + jd->year = (uint16_t)split.hi + 1; + if (jd->year != split.hi + 1) { + jd->year = 0; + retv = -1; /* bletch. overflow trouble. */ + } + jd->yearday = (uint16_t)split.lo + 1; + + /* convert to month and mday */ + split = ntpcal_split_yeardays(split.lo, leaps); + jd->month = (uint8_t)split.hi + 1; + jd->monthday = (uint8_t)split.lo + 1; + + return retv ? retv : leaps; +} + +/* + *--------------------------------------------------------------------- + * Convert a RD into the date part of a 'struct tm'. + *--------------------------------------------------------------------- + */ +int +ntpcal_rd_to_tm( + struct tm *utm, + int32_t rd + ) +{ + ntpcal_split split; + int leaps; + + leaps = 0; + /* get day-of-week first */ + utm->tm_wday = rd % 7; + if (utm->tm_wday < 0) + utm->tm_wday += 7; + + /* get year and day-of-year */ + split = ntpcal_split_eradays(rd - 1, &leaps); + utm->tm_year = split.hi - 1899; + utm->tm_yday = split.lo; /* 0-based */ + + /* convert to month and mday */ + split = ntpcal_split_yeardays(split.lo, leaps); + utm->tm_mon = split.hi; /* 0-based */ + utm->tm_mday = split.lo + 1; /* 1-based */ + + return leaps; +} + +/* + *--------------------------------------------------------------------- + * Take a value of seconds since midnight and split it into hhmmss in a + * 'struct calendar'. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_daysec_to_date( + struct calendar *jd, + int32_t sec + ) +{ + int32_t days; + int ts[3]; + + days = priv_timesplit(ts, sec); + jd->hour = (uint8_t)ts[0]; + jd->minute = (uint8_t)ts[1]; + jd->second = (uint8_t)ts[2]; + + return days; +} + +/* + *--------------------------------------------------------------------- + * Take a value of seconds since midnight and split it into hhmmss in a + * 'struct tm'. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_daysec_to_tm( + struct tm *utm, + int32_t sec + ) +{ + int32_t days; + int32_t ts[3]; + + days = priv_timesplit(ts, sec); + utm->tm_hour = ts[0]; + utm->tm_min = ts[1]; + utm->tm_sec = ts[2]; + + return days; +} + +/* + *--------------------------------------------------------------------- + * take a split representation for day/second-of-day and day offset + * and convert it to a 'struct calendar'. The seconds will be normalised + * into the range of a day, and the day will be adjusted accordingly. + * + * returns >0 if the result is in a leap year, 0 if in a regular + * year and <0 if the result did not fit into the calendar struct. + *--------------------------------------------------------------------- + */ +int +ntpcal_daysplit_to_date( + struct calendar *jd, + const ntpcal_split *ds, + int32_t dof + ) +{ + dof += ntpcal_daysec_to_date(jd, ds->lo); + return ntpcal_rd_to_date(jd, ds->hi + dof); +} + +/* + *--------------------------------------------------------------------- + * take a split representation for day/second-of-day and day offset + * and convert it to a 'struct tm'. The seconds will be normalised + * into the range of a day, and the day will be adjusted accordingly. + * + * returns 1 if the result is in a leap year and zero if in a regular + * year. + *--------------------------------------------------------------------- + */ +int +ntpcal_daysplit_to_tm( + struct tm *utm, + const ntpcal_split *ds , + int32_t dof + ) +{ + dof += ntpcal_daysec_to_tm(utm, ds->lo); + + return ntpcal_rd_to_tm(utm, ds->hi + dof); +} + +/* + *--------------------------------------------------------------------- + * Take a UN*X time and convert to a calendar structure. + *--------------------------------------------------------------------- + */ +int +ntpcal_time_to_date( + struct calendar *jd, + const vint64 *ts + ) +{ + ntpcal_split ds; + + ds = ntpcal_daysplit(ts); + ds.hi += ntpcal_daysec_to_date(jd, ds.lo); + ds.hi += DAY_UNIX_STARTS; + + return ntpcal_rd_to_date(jd, ds.hi); +} + + +/* + * ================================================================== + * + * merging composite entities + * + * ================================================================== + */ + +/* + *--------------------------------------------------------------------- + * Merge a number of days and a number of seconds into seconds, + * expressed in 64 bits to avoid overflow. + *--------------------------------------------------------------------- + */ +vint64 +ntpcal_dayjoin( + int32_t days, + int32_t secs + ) +{ + vint64 res; + +#ifdef HAVE_INT64 + + res.q_s = days; + res.q_s *= SECSPERDAY; + res.q_s += secs; + +#else + + uint32_t p1, p2; + int isneg; + + /* + * res = days *86400 + secs, using manual 16/32 bit + * multiplications and shifts. + */ + isneg = (days < 0); + if (isneg) + days = -days; + + /* assemble days * 675 */ + res.D_s.lo = (days & 0xFFFF) * 675u; + res.D_s.hi = 0; + p1 = (days >> 16) * 675u; + p2 = p1 >> 16; + p1 = p1 << 16; + M_ADD(res.D_s.hi, res.D_s.lo, p2, p1); + + /* mul by 128, using shift */ + res.D_s.hi = (res.D_s.hi << 7) | (res.D_s.lo >> 25); + res.D_s.lo = (res.D_s.lo << 7); + + /* fix sign */ + if (isneg) + M_NEG(res.D_s.hi, res.D_s.lo); + + /* properly add seconds */ + p2 = 0; + if (secs < 0) { + p1 = (uint32_t)-secs; + M_NEG(p2, p1); + } else { + p1 = (uint32_t)secs; + } + M_ADD(res.D_s.hi, res.D_s.lo, p2, p1); + +#endif + + return res; +} + +/* + *--------------------------------------------------------------------- + * Convert elapsed years in Era into elapsed days in Era. + * + * To accomodate for negative values of years, floor division would be + * required for all division operations. This can be eased by first + * splitting the years into full 400-year cycles and years in the + * cycle. Only this operation must be coded as a full floor division; as + * the years in the cycle is a non-negative number, all other divisions + * can be regular truncated divisions. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_days_in_years( + int32_t years + ) +{ + int32_t cycle; /* full gregorian cycle */ + + /* split off full calendar cycles, using floor division */ + cycle = years / 400; + years = years % 400; + if (years < 0) { + cycle -= 1; + years += 400; + } + + /* + * Calculate days in cycle. years now is a non-negative number, + * holding the number of years in the 400-year cycle. + */ + return cycle * GREGORIAN_CYCLE_DAYS + + years * DAYSPERYEAR /* days inregular years */ + + years / 4 /* 4 year leap rule */ + - years / 100; /* 100 year leap rule */ + /* the 400-year rule does not apply due to full-cycle split-off */ +} + +/* + *--------------------------------------------------------------------- + * Convert a number of elapsed month in a year into elapsed days in year. + * + * The month will be normalized, and 'res.hi' will contain the + * excessive years that must be considered when converting the years, + * while 'res.lo' will contain the number of elapsed days since start + * of the year. + * + * This code uses the shifted-month-approach to convert month to days, + * because then there is no need to have explicit leap year + * information. The slight disadvantage is that for most month values + * the result is a negative value, and the year excess is one; the + * conversion is then simply based on the start of the following year. + *--------------------------------------------------------------------- + */ +ntpcal_split +ntpcal_days_in_months( + int32_t m + ) +{ + ntpcal_split res; + + /* normalize month into range */ + res.hi = 0; + res.lo = m; + if (res.lo < 0 || res.lo >= 12) { + res.hi = res.lo / 12; + res.lo = res.lo % 12; + if (res.lo < 0) { + res.hi -= 1; + res.lo += 12; + } + } + + /* add 10 month for year starting with march */ + if (res.lo < 2) + res.lo += 10; + else { + res.hi += 1; + res.lo -= 2; + } + + /* get cummulated days in year with unshift */ + res.lo = shift_month_table[res.lo] - 306; + + return res; +} + +/* + *--------------------------------------------------------------------- + * Convert ELAPSED years/months/days of gregorian calendar to elapsed + * days in Gregorian epoch. + * + * If you want to convert years and days-of-year, just give a month of + * zero. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_edate_to_eradays( + int32_t years, + int32_t mons, + int32_t mdays + ) +{ + ntpcal_split tmp; + int32_t res; + + if (mons) { + tmp = ntpcal_days_in_months(mons); + res = ntpcal_days_in_years(years + tmp.hi) + tmp.lo; + } else + res = ntpcal_days_in_years(years); + res += mdays; + + return res; +} + +/* + *--------------------------------------------------------------------- + * Convert ELAPSED years/months/days of gregorian calendar to elapsed + * days in year. + * + * Note: This will give the true difference to the start of the given year, + * even if months & days are off-scale. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_edate_to_yeardays( + int32_t years, + int32_t mons, + int32_t mdays + ) +{ + ntpcal_split tmp; + + if (0 <= mons && mons < 12) { + years += 1; + mdays += real_month_table[is_leapyear(years)][mons]; + } else { + tmp = ntpcal_days_in_months(mons); + mdays += tmp.lo + + ntpcal_days_in_years(years + tmp.hi) + - ntpcal_days_in_years(years); + } + + return mdays; +} + +/* + *--------------------------------------------------------------------- + * Convert elapsed days and the hour/minute/second information into + * total seconds. + * + * If 'isvalid' is not NULL, do a range check on the time specification + * and tell if the time input is in the normal range, permitting for a + * single leapsecond. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_etime_to_seconds( + int32_t hours, + int32_t minutes, + int32_t seconds + ) +{ + int32_t res; + + res = (hours * MINSPERHR + minutes) * SECSPERMIN + seconds; + + return res; +} + +/* + *--------------------------------------------------------------------- + * Convert the date part of a 'struct tm' (that is, year, month, + * day-of-month) into the RD of that day. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_tm_to_rd( + const struct tm *utm + ) +{ + return ntpcal_edate_to_eradays(utm->tm_year + 1899, + utm->tm_mon, + utm->tm_mday - 1) + 1; +} + +/* + *--------------------------------------------------------------------- + * Convert the date part of a 'struct calendar' (that is, year, month, + * day-of-month) into the RD of that day. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_date_to_rd( + const struct calendar *jd + ) +{ + return ntpcal_edate_to_eradays((int32_t)jd->year - 1, + (int32_t)jd->month - 1, + (int32_t)jd->monthday - 1) + 1; +} + +/* + *--------------------------------------------------------------------- + * convert a year number to rata die of year start + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_year_to_ystart( + int32_t year + ) +{ + return ntpcal_days_in_years(year - 1) + 1; +} + +/* + *--------------------------------------------------------------------- + * For a given RD, get the RD of the associated year start, + * that is, the RD of the last January,1st on or before that day. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_rd_to_ystart( + int32_t rd + ) +{ + /* + * Rather simple exercise: split the day number into elapsed + * years and elapsed days, then remove the elapsed days from the + * input value. Nice'n sweet... + */ + return rd - ntpcal_split_eradays(rd - 1, NULL).lo; +} + +/* + *--------------------------------------------------------------------- + * For a given RD, get the RD of the associated month start. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_rd_to_mstart( + int32_t rd + ) +{ + ntpcal_split split; + int leaps; + + split = ntpcal_split_eradays(rd - 1, &leaps); + split = ntpcal_split_yeardays(split.lo, leaps); + + return rd - split.lo; +} + +/* + *--------------------------------------------------------------------- + * take a 'struct calendar' and get the seconds-of-day from it. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_date_to_daysec( + const struct calendar *jd + ) +{ + return ntpcal_etime_to_seconds(jd->hour, jd->minute, + jd->second); +} + +/* + *--------------------------------------------------------------------- + * take a 'struct tm' and get the seconds-of-day from it. + *--------------------------------------------------------------------- + */ +int32_t +ntpcal_tm_to_daysec( + const struct tm *utm + ) +{ + return ntpcal_etime_to_seconds(utm->tm_hour, utm->tm_min, + utm->tm_sec); +} + +/* + *--------------------------------------------------------------------- + * take a 'struct calendar' and convert it to a 'time_t' + *--------------------------------------------------------------------- + */ +time_t +ntpcal_date_to_time( + const struct calendar *jd + ) +{ + vint64 join; + int32_t days, secs; + + days = ntpcal_date_to_rd(jd) - DAY_UNIX_STARTS; + secs = ntpcal_date_to_daysec(jd); + join = ntpcal_dayjoin(days, secs); + + return vint64_to_time(&join); +} + + +/* + * ================================================================== + * + * extended and unchecked variants of caljulian/caltontp + * + * ================================================================== + */ +int +ntpcal_ntp64_to_date( + struct calendar *jd, + const vint64 *ntp + ) +{ + ntpcal_split ds; + + ds = ntpcal_daysplit(ntp); + ds.hi += ntpcal_daysec_to_date(jd, ds.lo); + + return ntpcal_rd_to_date(jd, ds.hi + DAY_NTP_STARTS); +} + +int +ntpcal_ntp_to_date( + struct calendar *jd, + uint32_t ntp, + const time_t *piv + ) +{ + vint64 ntp64; + + /* + * Unfold ntp time around current time into NTP domain. Split + * into days and seconds, shift days into CE domain and + * process the parts. + */ + ntp64 = ntpcal_ntp_to_ntp(ntp, piv); + return ntpcal_ntp64_to_date(jd, &ntp64); +} + + +vint64 +ntpcal_date_to_ntp64( + const struct calendar *jd + ) +{ + /* + * Convert date to NTP. Ignore yearday, use d/m/y only. + */ + return ntpcal_dayjoin(ntpcal_date_to_rd(jd) - DAY_NTP_STARTS, + ntpcal_date_to_daysec(jd)); +} + + +uint32_t +ntpcal_date_to_ntp( + const struct calendar *jd + ) +{ + /* + * Get lower half of 64-bit NTP timestamp from date/time. + */ + return ntpcal_date_to_ntp64(jd).d_s.lo; +} + + + +/* + * ================================================================== + * + * day-of-week calculations + * + * ================================================================== + */ +/* + * Given a RataDie and a day-of-week, calculate a RDN that is reater-than, + * greater-or equal, closest, less-or-equal or less-than the given RDN + * and denotes the given day-of-week + */ +int32_t +ntpcal_weekday_gt( + int32_t rdn, + int32_t dow + ) +{ + return ntpcal_periodic_extend(rdn+1, dow, 7); +} + +int32_t +ntpcal_weekday_ge( + int32_t rdn, + int32_t dow + ) +{ + return ntpcal_periodic_extend(rdn, dow, 7); +} + +int32_t +ntpcal_weekday_close( + int32_t rdn, + int32_t dow + ) +{ + return ntpcal_periodic_extend(rdn-3, dow, 7); +} + +int32_t +ntpcal_weekday_le( + int32_t rdn, + int32_t dow + ) +{ + return ntpcal_periodic_extend(rdn, dow, -7); +} + +int32_t +ntpcal_weekday_lt( + int32_t rdn, + int32_t dow + ) +{ + return ntpcal_periodic_extend(rdn-1, dow, -7); +} + +/* + * ================================================================== + * + * ISO week-calendar conversions + * + * The ISO8601 calendar defines a calendar of years, weeks and weekdays. + * It is related to the Gregorian calendar, and a ISO year starts at the + * Monday closest to Jan,1st of the corresponding Gregorian year. A ISO + * calendar year has always 52 or 53 weeks, and like the Grogrian + * calendar the ISO8601 calendar repeats itself every 400 years, or + * 146097 days, or 20871 weeks. + * + * While it is possible to write ISO calendar functions based on the + * Gregorian calendar functions, the following implementation takes a + * different approach, based directly on years and weeks. + * + * Analysis of the tabulated data shows that it is not possible to + * interpolate from years to weeks over a full 400 year range; cyclic + * shifts over 400 years do not provide a solution here. But it *is* + * possible to interpolate over every single century of the 400-year + * cycle. (The centennial leap year rule seems to be the culprit here.) + * + * It can be shown that a conversion from years to weeks can be done + * using a linear transformation of the form + * + * w = floor( y * a + b ) + * + * where the slope a must hold to + * + * 52.1780821918 <= a < 52.1791044776 + * + * and b must be chosen according to the selected slope and the number + * of the century in a 400-year period. + * + * The inverse calculation can also be done in this way. Careful scaling + * provides an unlimited set of integer coefficients a,k,b that enable + * us to write the calulation in the form + * + * w = (y * a + b ) / k + * y = (w * a' + b') / k' + * + * In this implementation the values of k and k' are chosen to be + * smallest possible powers of two, so the division can be implemented + * as shifts if the optimiser chooses to do so. + * + * ================================================================== + */ + +/* + * Given a number of elapsed (ISO-)years since the begin of the + * christian era, return the number of elapsed weeks corresponding to + * the number of years. + */ +int32_t +isocal_weeks_in_years( + int32_t years + ) +{ + /* + * use: w = (y * 53431 + b[c]) / 1024 as interpolation + */ + static const int32_t bctab[4] = { 449, 157, 889, 597 }; + int32_t cycle; /* full gregorian cycle */ + int32_t cents; /* full centuries */ + int32_t weeks; /* accumulated weeks */ + + /* split off full calendar cycles, using floor division */ + cycle = years / 400; + years = years % 400; + if (years < 0) { + cycle -= 1; + years += 400; + } + + /* split off full centuries */ + cents = years / 100; + years = years % 100; + + /* + * calculate elapsed weeks, taking into account that the + * first, third and fourth century have 5218 weeks but the + * second century falls short by one week. + */ + weeks = (years * 53431 + bctab[cents]) / 1024; + + return cycle * GREGORIAN_CYCLE_WEEKS + + cents * 5218 - (cents > 1) + + weeks; +} + +/* + * Given a number of elapsed weeks since the begin of the christian + * era, split this number into the number of elapsed years in res.hi + * and the excessive number of weeks in res.lo. (That is, res.lo is + * the number of elapsed weeks in the remaining partial year.) + */ +ntpcal_split +isocal_split_eraweeks( + int32_t weeks + ) +{ + /* + * use: y = (w * 157 + b[c]) / 8192 as interpolation + */ + static const int32_t bctab[4] = { 85, 131, 17, 62 }; + ntpcal_split res; + int32_t cents; + + /* + * split off 400-year cycles, using the fact that a 400-year + * cycle has 146097 days, which is exactly 20871 weeks. + */ + res.hi = weeks / GREGORIAN_CYCLE_WEEKS; + res.lo = weeks % GREGORIAN_CYCLE_WEEKS; + if (res.lo < 0) { + res.hi -= 1; + res.lo += GREGORIAN_CYCLE_WEEKS; + } + res.hi *= 400; + + /* + * split off centuries, taking into account that the first, + * third and fourth century have 5218 weeks but that the + * second century falls short by one week. + */ + res.lo += (res.lo >= 10435); + cents = res.lo / 5218; + res.lo %= 5218; /* res.lo is weeks in century now */ + + /* convert elapsed weeks in century to elapsed years and weeks */ + res.lo = res.lo * 157 + bctab[cents]; + res.hi += cents * 100 + res.lo / 8192; + res.lo = (res.lo % 8192) / 157; + + return res; +} + +/* + * Given a second in the NTP time scale and a pivot, expand the NTP + * time stamp around the pivot and convert into an ISO calendar time + * stamp. + */ +int +isocal_ntp64_to_date( + struct isodate *id, + const vint64 *ntp + ) +{ + ntpcal_split ds; + int32_t ts[3]; + + /* + * Split NTP time into days and seconds, shift days into CE + * domain and process the parts. + */ + ds = ntpcal_daysplit(ntp); + + /* split time part */ + ds.hi += priv_timesplit(ts, ds.lo); + id->hour = (uint8_t)ts[0]; + id->minute = (uint8_t)ts[1]; + id->second = (uint8_t)ts[2]; + + /* split date part */ + ds.lo = ds.hi + DAY_NTP_STARTS - 1; /* elapsed era days */ + ds.hi = ds.lo / 7; /* elapsed era weeks */ + ds.lo = ds.lo % 7; /* elapsed week days */ + if (ds.lo < 0) { /* floor division! */ + ds.hi -= 1; + ds.lo += 7; + } + id->weekday = (uint8_t)ds.lo + 1; /* weekday result */ + + ds = isocal_split_eraweeks(ds.hi); /* elapsed years&week*/ + id->year = (uint16_t)ds.hi + 1; /* shift to current */ + id->week = (uint8_t )ds.lo + 1; + + return (ds.hi >= 0 && ds.hi < 0xFFFFU); +} + +int +isocal_ntp_to_date( + struct isodate *id, + uint32_t ntp, + const time_t *piv + ) +{ + vint64 ntp64; + + /* + * Unfold ntp time around current time into NTP domain, then + * convert the full time stamp. + */ + ntp64 = ntpcal_ntp_to_ntp(ntp, piv); + return isocal_ntp64_to_date(id, &ntp64); +} + +/* + * Convert a ISO date spec into a second in the NTP time scale, + * properly truncated to 32 bit. + */ +vint64 +isocal_date_to_ntp64( + const struct isodate *id + ) +{ + int32_t weeks, days, secs; + + weeks = isocal_weeks_in_years((int32_t)id->year - 1) + + (int32_t)id->week - 1; + days = weeks * 7 + (int32_t)id->weekday; + /* days is RDN of ISO date now */ + secs = ntpcal_etime_to_seconds(id->hour, id->minute, id->second); + + return ntpcal_dayjoin(days - DAY_NTP_STARTS, secs); +} + +uint32_t +isocal_date_to_ntp( + const struct isodate *id + ) +{ + /* + * Get lower half of 64-bit NTP timestamp from date/time. + */ + return isocal_date_to_ntp64(id).d_s.lo; +} + +/* -*-EOF-*- */ diff --git a/libntp/ntp_crypto_rnd.c b/libntp/ntp_crypto_rnd.c new file mode 100644 index 0000000000000..62a808db3447f --- /dev/null +++ b/libntp/ntp_crypto_rnd.c @@ -0,0 +1,96 @@ +/* + * Crypto-quality random number functions + * + * Author: Harlan Stenn, 2014 + * + * This file is Copyright (c) 2014 by Network Time Foundation. + * BSD terms apply: see the file COPYRIGHT in the distribution root for details. + */ + +#include "config.h" +#include <sys/types.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif +#include <stdio.h> + +#include <l_stdlib.h> +#include <ntp_random.h> + +#ifdef USE_OPENSSL_CRYPTO_RAND +#include <openssl/err.h> +#include <openssl/rand.h> + +int crypto_rand_init = 0; +#endif + +/* + * As of late 2014, here's how we plan to provide cryptographic-quality + * random numbers: + * + * - If we are building with OpenSSL, use RAND_poll() and RAND_bytes(). + * - Otherwise, use arc4random(). + * + * Use of arc4random() can be forced using configure --disable-openssl-random + * + * We can count on arc4random existing, thru the OS or thru libevent. + * The quality of arc4random depends on the implementor. + * + * RAND_poll() doesn't show up until XXX. If it's not present, we + * need to either provide our own or use arc4random(). + */ + +/* + * ntp_crypto_srandom: + * + * Initialize the random number generator, if needed by the underlying + * crypto random number generation mechanism. + */ + +void +ntp_crypto_srandom( + void + ) +{ +#ifdef USE_OPENSSL_CRYPTO_RAND + if (!crypto_rand_init) { + RAND_poll(); + crypto_rand_init = 1; + } +#else + /* No initialization needed for arc4random() */ +#endif +} + + +/* + * ntp_crypto_random_buf: + * + * Returns 0 on success, -1 on error. + */ +int +ntp_crypto_random_buf( + void *buf, + size_t nbytes + ) +{ +#ifdef USE_OPENSSL_CRYPTO_RAND + int rc; + + rc = RAND_bytes(buf, nbytes); + if (1 != rc) { + unsigned long err; + char *err_str; + + err = ERR_get_error(); + err_str = ERR_error_string(err, NULL); + /* XXX: Log the error */ + + return -1; + } + return 0; +#else + arc4random_buf(buf, nbytes); + return 0; +#endif +} diff --git a/libntp/ntp_intres.c b/libntp/ntp_intres.c new file mode 100644 index 0000000000000..2ac70c1a416dd --- /dev/null +++ b/libntp/ntp_intres.c @@ -0,0 +1,1143 @@ +/* + * ntp_intres.c - Implements a generic blocking worker child or thread, + * initially to provide a nonblocking solution for DNS + * name to address lookups available with getaddrinfo(). + * + * This is a new implementation as of 2009 sharing the filename and + * very little else with the prior implementation, which used a + * temporary file to receive a single set of requests from the parent, + * and a NTP mode 7 authenticated request to push back responses. + * + * A primary goal in rewriting this code was the need to support the + * pool configuration directive's requirement to retrieve multiple + * addresses resolving a single name, which has previously been + * satisfied with blocking resolver calls from the ntpd mainline code. + * + * A secondary goal is to provide a generic mechanism for other + * blocking operations to be delegated to a worker using a common + * model for both Unix and Windows ntpd. ntp_worker.c, work_fork.c, + * and work_thread.c implement the generic mechanism. This file + * implements the two current consumers, getaddrinfo_sometime() and the + * presently unused getnameinfo_sometime(). + * + * Both routines deliver results to a callback and manage memory + * allocation, meaning there is no freeaddrinfo_sometime(). + * + * The initial implementation for Unix uses a pair of unidirectional + * pipes, one each for requests and responses, connecting the forked + * blocking child worker with the ntpd mainline. The threaded code + * uses arrays of pointers to queue requests and responses. + * + * The parent drives the process, including scheduling sleeps between + * retries. + * + * Memory is managed differently for a child process, which mallocs + * request buffers to read from the pipe into, whereas the threaded + * code mallocs a copy of the request to hand off to the worker via + * the queueing array. The resulting request buffer is free()d by + * platform-independent code. A wrinkle is the request needs to be + * available to the requestor during response processing. + * + * Response memory allocation is also platform-dependent. With a + * separate process and pipes, the response is free()d after being + * written to the pipe. With threads, the same memory is handed + * over and the requestor frees it after processing is completed. + * + * The code should be generalized to support threads on Unix using + * much of the same code used for Windows initially. + * + */ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "ntp_workimpl.h" + +#ifdef WORKER + +#include <stdio.h> +#include <ctype.h> +#include <signal.h> + +/**/ +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#include <arpa/inet.h> +/**/ +#ifdef HAVE_SYS_PARAM_H +# include <sys/param.h> +#endif + +#if !defined(HAVE_RES_INIT) && defined(HAVE___RES_INIT) +# define HAVE_RES_INIT +#endif + +#if defined(HAVE_RESOLV_H) && defined(HAVE_RES_INIT) +# ifdef HAVE_ARPA_NAMESER_H +# include <arpa/nameser.h> /* DNS HEADER struct */ +# endif +# ifdef HAVE_NETDB_H +# include <netdb.h> +# endif +# include <resolv.h> +# ifdef HAVE_INT32_ONLY_WITH_DNS +# define HAVE_INT32 +# endif +# ifdef HAVE_U_INT32_ONLY_WITH_DNS +# define HAVE_U_INT32 +# endif +#endif + +#include "ntp.h" +#include "ntp_debug.h" +#include "ntp_malloc.h" +#include "ntp_syslog.h" +#include "ntp_unixtime.h" +#include "ntp_intres.h" +#include "intreswork.h" + + +/* + * Following are implementations of getaddrinfo_sometime() and + * getnameinfo_sometime(). Each is implemented in three routines: + * + * getaddrinfo_sometime() getnameinfo_sometime() + * blocking_getaddrinfo() blocking_getnameinfo() + * getaddrinfo_sometime_complete() getnameinfo_sometime_complete() + * + * The first runs in the parent and marshalls (or serializes) request + * parameters into a request blob which is processed in the child by + * the second routine, blocking_*(), which serializes the results into + * a response blob unpacked by the third routine, *_complete(), which + * calls the callback routine provided with the request and frees + * _request_ memory allocated by the first routine. Response memory + * is managed by the code which calls the *_complete routines. + */ + +/* === typedefs === */ +typedef struct blocking_gai_req_tag { /* marshalled args */ + size_t octets; + u_int dns_idx; + time_t scheduled; + time_t earliest; + struct addrinfo hints; + int retry; + gai_sometime_callback callback; + void * context; + size_t nodesize; + size_t servsize; +} blocking_gai_req; + +typedef struct blocking_gai_resp_tag { + size_t octets; + int retcode; + int retry; + int gai_errno; /* for EAI_SYSTEM case */ + int ai_count; + /* + * Followed by ai_count struct addrinfo and then ai_count + * sockaddr_u and finally the canonical name strings. + */ +} blocking_gai_resp; + +typedef struct blocking_gni_req_tag { + size_t octets; + u_int dns_idx; + time_t scheduled; + time_t earliest; + int retry; + size_t hostoctets; + size_t servoctets; + int flags; + gni_sometime_callback callback; + void * context; + sockaddr_u socku; +} blocking_gni_req; + +typedef struct blocking_gni_resp_tag { + size_t octets; + int retcode; + int gni_errno; /* for EAI_SYSTEM case */ + int retry; + size_t hostoctets; + size_t servoctets; + /* + * Followed by hostoctets bytes of null-terminated host, + * then servoctets bytes of null-terminated service. + */ +} blocking_gni_resp; + +/* per-DNS-worker state in parent */ +typedef struct dnschild_ctx_tag { + u_int index; + time_t next_dns_timeslot; +} dnschild_ctx; + +/* per-DNS-worker state in worker */ +typedef struct dnsworker_ctx_tag { + blocking_child * c; + time_t ignore_scheduled_before; +#ifdef HAVE_RES_INIT + time_t next_res_init; +#endif +} dnsworker_ctx; + + +/* === variables === */ +dnschild_ctx ** dnschild_contexts; /* parent */ +u_int dnschild_contexts_alloc; +dnsworker_ctx ** dnsworker_contexts; /* child */ +u_int dnsworker_contexts_alloc; + +#ifdef HAVE_RES_INIT +static time_t next_res_init; +#endif + + +/* === forward declarations === */ +static u_int reserve_dnschild_ctx(void); +static u_int get_dnschild_ctx(void); +static void alloc_dnsworker_context(u_int); +/* static void free_dnsworker_context(u_int); */ +static dnsworker_ctx * get_worker_context(blocking_child *, u_int); +static void scheduled_sleep(time_t, time_t, + dnsworker_ctx *); +static void manage_dns_retry_interval(time_t *, time_t *, + int *, + time_t *); +static int should_retry_dns(int, int); +#ifdef HAVE_RES_INIT +static void reload_resolv_conf(dnsworker_ctx *); +#else +# define reload_resolv_conf(wc) \ + do { \ + (void)(wc); \ + } while (FALSE) +#endif +static void getaddrinfo_sometime_complete(blocking_work_req, + void *, size_t, + void *); +static void getnameinfo_sometime_complete(blocking_work_req, + void *, size_t, + void *); + + +/* === functions === */ +/* + * getaddrinfo_sometime - uses blocking child to call getaddrinfo then + * invokes provided callback completion function. + */ +int +getaddrinfo_sometime( + const char * node, + const char * service, + const struct addrinfo * hints, + int retry, + gai_sometime_callback callback, + void * context + ) +{ + blocking_gai_req * gai_req; + u_int idx; + dnschild_ctx * child_ctx; + size_t req_size; + size_t nodesize; + size_t servsize; + time_t now; + + NTP_REQUIRE(NULL != node); + if (NULL != hints) { + NTP_REQUIRE(0 == hints->ai_addrlen); + NTP_REQUIRE(NULL == hints->ai_addr); + NTP_REQUIRE(NULL == hints->ai_canonname); + NTP_REQUIRE(NULL == hints->ai_next); + } + + idx = get_dnschild_ctx(); + child_ctx = dnschild_contexts[idx]; + + nodesize = strlen(node) + 1; + servsize = strlen(service) + 1; + req_size = sizeof(*gai_req) + nodesize + servsize; + + gai_req = emalloc_zero(req_size); + + gai_req->octets = req_size; + gai_req->dns_idx = idx; + now = time(NULL); + gai_req->scheduled = now; + gai_req->earliest = max(now, child_ctx->next_dns_timeslot); + child_ctx->next_dns_timeslot = gai_req->earliest; + if (hints != NULL) + gai_req->hints = *hints; + gai_req->retry = retry; + gai_req->callback = callback; + gai_req->context = context; + gai_req->nodesize = nodesize; + gai_req->servsize = servsize; + + memcpy((char *)gai_req + sizeof(*gai_req), node, nodesize); + memcpy((char *)gai_req + sizeof(*gai_req) + nodesize, service, + servsize); + + if (queue_blocking_request( + BLOCKING_GETADDRINFO, + gai_req, + req_size, + &getaddrinfo_sometime_complete, + gai_req)) { + + msyslog(LOG_ERR, "unable to queue getaddrinfo request"); + errno = EFAULT; + return -1; + } + + return 0; +} + +int +blocking_getaddrinfo( + blocking_child * c, + blocking_pipe_header * req + ) +{ + blocking_gai_req * gai_req; + dnsworker_ctx * worker_ctx; + blocking_pipe_header * resp; + blocking_gai_resp * gai_resp; + char * node; + char * service; + struct addrinfo * ai_res; + struct addrinfo * ai; + struct addrinfo * serialized_ai; + size_t canons_octets; + size_t this_octets; + size_t resp_octets; + char * cp; + time_t time_now; + + gai_req = (void *)((char *)req + sizeof(*req)); + node = (char *)gai_req + sizeof(*gai_req); + service = node + gai_req->nodesize; + + worker_ctx = get_worker_context(c, gai_req->dns_idx); + scheduled_sleep(gai_req->scheduled, gai_req->earliest, + worker_ctx); + reload_resolv_conf(worker_ctx); + + /* + * Take a shot at the final size, better to overestimate + * at first and then realloc to a smaller size. + */ + + resp_octets = sizeof(*resp) + sizeof(*gai_resp) + + 16 * (sizeof(struct addrinfo) + + sizeof(sockaddr_u)) + + 256; + resp = emalloc_zero(resp_octets); + gai_resp = (void *)(resp + 1); + + 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); +#endif + ai_res = NULL; + gai_resp->retcode = getaddrinfo(node, service, &gai_req->hints, + &ai_res); + gai_resp->retry = gai_req->retry; +#ifdef EAI_SYSTEM + if (EAI_SYSTEM == gai_resp->retcode) + gai_resp->gai_errno = errno; +#endif + canons_octets = 0; + + if (0 == gai_resp->retcode) { + ai = ai_res; + while (NULL != ai) { + gai_resp->ai_count++; + if (ai->ai_canonname) + canons_octets += strlen(ai->ai_canonname) + 1; + ai = ai->ai_next; + } + /* + * If this query succeeded only after retrying, DNS may have + * just become responsive. Ignore previously-scheduled + * retry sleeps once for each pending request, similar to + * the way scheduled_sleep() does when its worker_sleep() + * is interrupted. + */ + if (gai_resp->retry > INITIAL_DNS_RETRY) { + time_now = time(NULL); + worker_ctx->ignore_scheduled_before = time_now; + TRACE(1, ("DNS success after retry, ignoring sleeps scheduled before now (%s)\n", + humantime(time_now))); + } + } + + /* + * Our response consists of a header, followed by ai_count + * addrinfo structs followed by ai_count sockaddr_storage + * structs followed by the canonical names. + */ + gai_resp->octets = sizeof(*gai_resp) + + gai_resp->ai_count + * (sizeof(gai_req->hints) + + sizeof(sockaddr_u)) + + canons_octets; + + resp_octets = sizeof(*resp) + gai_resp->octets; + resp = erealloc(resp, resp_octets); + gai_resp = (void *)(resp + 1); + + /* cp serves as our current pointer while serializing */ + cp = (void *)(gai_resp + 1); + canons_octets = 0; + + if (0 == gai_resp->retcode) { + ai = ai_res; + while (NULL != ai) { + memcpy(cp, ai, sizeof(*ai)); + serialized_ai = (void *)cp; + cp += sizeof(*ai); + + /* transform ai_canonname into offset */ + if (NULL != serialized_ai->ai_canonname) { + serialized_ai->ai_canonname = (char *)canons_octets; + canons_octets += strlen(ai->ai_canonname) + 1; + } + + /* leave fixup of ai_addr pointer for receiver */ + + ai = ai->ai_next; + } + + ai = ai_res; + while (NULL != ai) { + NTP_INSIST(ai->ai_addrlen <= sizeof(sockaddr_u)); + memcpy(cp, ai->ai_addr, ai->ai_addrlen); + cp += sizeof(sockaddr_u); + + ai = ai->ai_next; + } + + ai = ai_res; + while (NULL != ai) { + if (NULL != ai->ai_canonname) { + this_octets = strlen(ai->ai_canonname) + 1; + memcpy(cp, ai->ai_canonname, this_octets); + cp += this_octets; + } + + ai = ai->ai_next; + } + freeaddrinfo(ai_res); + } + + /* + * make sure our walk and earlier calc match + */ + DEBUG_INSIST((size_t)(cp - (char *)resp) == resp_octets); + + if (queue_blocking_response(c, resp, resp_octets, req)) { + msyslog(LOG_ERR, "blocking_getaddrinfo can not queue response"); + return -1; + } + + return 0; +} + + +static void +getaddrinfo_sometime_complete( + blocking_work_req rtype, + void * context, + size_t respsize, + void * resp + ) +{ + blocking_gai_req * gai_req; + blocking_gai_resp * gai_resp; + dnschild_ctx * child_ctx; + struct addrinfo * ai; + struct addrinfo * next_ai; + sockaddr_u * psau; + char * node; + char * service; + char * canon_start; + time_t time_now; + int again; + int af; + const char * fam_spec; + int i; + + gai_req = context; + gai_resp = resp; + + DEBUG_REQUIRE(BLOCKING_GETADDRINFO == rtype); + DEBUG_REQUIRE(respsize == gai_resp->octets); + + node = (char *)gai_req + sizeof(*gai_req); + service = node + gai_req->nodesize; + + child_ctx = dnschild_contexts[gai_req->dns_idx]; + + if (0 == gai_resp->retcode) { + /* + * If this query succeeded only after retrying, DNS may have + * just become responsive. + */ + if (gai_resp->retry > INITIAL_DNS_RETRY) { + time_now = time(NULL); + child_ctx->next_dns_timeslot = 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, + gai_resp->gai_errno); + /* + * exponential backoff of DNS retries to 64s + */ + if (gai_req->retry > 0 && again) { + /* log the first retry only */ + if (INITIAL_DNS_RETRY == gai_req->retry) + NLOG(NLOG_SYSINFO) { + af = gai_req->hints.ai_family; + fam_spec = (AF_INET6 == af) + ? " (AAAA)" + : (AF_INET == af) + ? " (A)" + : ""; +#ifdef EAI_SYSTEM + if (EAI_SYSTEM == gai_resp->retcode) { + errno = gai_resp->gai_errno; + msyslog(LOG_INFO, + "retrying DNS %s%s: EAI_SYSTEM %d: %m", + node, fam_spec, + gai_resp->gai_errno); + } else +#endif + msyslog(LOG_INFO, + "retrying DNS %s%s: %s (%d)", + node, fam_spec, + gai_strerror(gai_resp->retcode), + gai_resp->retcode); + } + manage_dns_retry_interval(&gai_req->scheduled, + &gai_req->earliest, &gai_req->retry, + &child_ctx->next_dns_timeslot); + if (!queue_blocking_request( + BLOCKING_GETADDRINFO, + gai_req, + gai_req->octets, + &getaddrinfo_sometime_complete, + gai_req)) + return; + else + msyslog(LOG_ERR, + "unable to retry hostname %s", + node); + } + } + + /* + * fixup pointers in returned addrinfo array + */ + ai = (void *)((char *)gai_resp + sizeof(*gai_resp)); + next_ai = NULL; + for (i = gai_resp->ai_count - 1; i >= 0; i--) { + ai[i].ai_next = next_ai; + next_ai = &ai[i]; + } + + psau = (void *)((char *)ai + gai_resp->ai_count * sizeof(*ai)); + canon_start = (char *)psau + gai_resp->ai_count * sizeof(*psau); + + for (i = 0; i < gai_resp->ai_count; i++) { + if (NULL != ai[i].ai_addr) + ai[i].ai_addr = &psau->sa; + psau++; + if (NULL != ai[i].ai_canonname) + ai[i].ai_canonname += (size_t)canon_start; + } + + NTP_ENSURE((char *)psau == canon_start); + + if (!gai_resp->ai_count) + ai = NULL; + + (*gai_req->callback)(gai_resp->retcode, gai_resp->gai_errno, + gai_req->context, node, service, + &gai_req->hints, ai); + + free(gai_req); + /* gai_resp is part of block freed by process_blocking_resp() */ +} + + +#ifdef TEST_BLOCKING_WORKER +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) +{ + sockaddr_u addr; + + if (rescode) { + 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); + 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); + + ai_res = ai_res->ai_next; + } +} +#endif /* TEST_BLOCKING_WORKER */ + + +int +getnameinfo_sometime( + sockaddr_u * psau, + size_t hostoctets, + size_t servoctets, + int flags, + gni_sometime_callback callback, + void * context + ) +{ + blocking_gni_req * gni_req; + u_int idx; + dnschild_ctx * child_ctx; + time_t time_now; + + NTP_REQUIRE(hostoctets); + NTP_REQUIRE(hostoctets + servoctets < 1024); + + idx = get_dnschild_ctx(); + child_ctx = dnschild_contexts[idx]; + + gni_req = emalloc_zero(sizeof(*gni_req)); + + gni_req->octets = sizeof(*gni_req); + gni_req->dns_idx = idx; + time_now = time(NULL); + gni_req->scheduled = time_now; + gni_req->earliest = max(time_now, child_ctx->next_dns_timeslot); + child_ctx->next_dns_timeslot = gni_req->earliest; + memcpy(&gni_req->socku, psau, SOCKLEN(psau)); + gni_req->hostoctets = hostoctets; + gni_req->servoctets = servoctets; + gni_req->flags = flags; + gni_req->retry = INITIAL_DNS_RETRY; + gni_req->callback = callback; + gni_req->context = context; + + if (queue_blocking_request( + BLOCKING_GETNAMEINFO, + gni_req, + sizeof(*gni_req), + &getnameinfo_sometime_complete, + gni_req)) { + + msyslog(LOG_ERR, "unable to queue getnameinfo request"); + errno = EFAULT; + return -1; + } + + return 0; +} + + +int +blocking_getnameinfo( + blocking_child * c, + blocking_pipe_header * req + ) +{ + blocking_gni_req * gni_req; + dnsworker_ctx * worker_ctx; + blocking_pipe_header * resp; + blocking_gni_resp * gni_resp; + size_t octets; + size_t resp_octets; + char * host; + char * service; + char * cp; + int rc; + time_t time_now; + + gni_req = (void *)((char *)req + sizeof(*req)); + + octets = gni_req->hostoctets + gni_req->servoctets; + + /* + * Some alloca() implementations are fragile regarding + * large allocations. We only need room for the host + * and service names. + */ + NTP_REQUIRE(octets < 1024); + +#ifndef HAVE_ALLOCA + host = emalloc(octets); +#else + host = alloca(octets); + if (NULL == host) { + msyslog(LOG_ERR, + "blocking_getnameinfo unable to allocate %lu octets on stack", + (u_long)octets); + exit(1); + } +#endif + service = host + gni_req->hostoctets; + + worker_ctx = get_worker_context(c, gni_req->dns_idx); + scheduled_sleep(gni_req->scheduled, gni_req->earliest, + worker_ctx); + reload_resolv_conf(worker_ctx); + + /* + * Take a shot at the final size, better to overestimate + * then realloc to a smaller size. + */ + + resp_octets = sizeof(*resp) + sizeof(*gni_resp) + octets; + resp = emalloc_zero(resp_octets); + gni_resp = (void *)((char *)resp + sizeof(*resp)); + + 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), + host, + gni_req->hostoctets, + service, + gni_req->servoctets, + gni_req->flags); + gni_resp->retry = gni_req->retry; +#ifdef EAI_SYSTEM + if (EAI_SYSTEM == gni_resp->retcode) + gni_resp->gni_errno = errno; +#endif + + if (0 != gni_resp->retcode) { + gni_resp->hostoctets = 0; + gni_resp->servoctets = 0; + } else { + gni_resp->hostoctets = strlen(host) + 1; + gni_resp->servoctets = strlen(service) + 1; + /* + * If this query succeeded only after retrying, DNS may have + * just become responsive. Ignore previously-scheduled + * retry sleeps once for each pending request, similar to + * the way scheduled_sleep() does when its worker_sleep() + * is interrupted. + */ + if (gni_req->retry > INITIAL_DNS_RETRY) { + time_now = time(NULL); + worker_ctx->ignore_scheduled_before = time_now; + TRACE(1, ("DNS success after retrying, ignoring sleeps scheduled before now (%s)\n", + humantime(time_now))); + } + } + octets = gni_resp->hostoctets + gni_resp->servoctets; + /* + * Our response consists of a header, followed by the host and + * service strings, each null-terminated. + */ + resp_octets = sizeof(*resp) + sizeof(*gni_resp) + octets; + + resp = erealloc(resp, resp_octets); + gni_resp = (void *)(resp + 1); + + gni_resp->octets = sizeof(*gni_resp) + octets; + + /* cp serves as our current pointer while serializing */ + cp = (void *)(gni_resp + 1); + + if (0 == gni_resp->retcode) { + memcpy(cp, host, gni_resp->hostoctets); + cp += gni_resp->hostoctets; + memcpy(cp, service, gni_resp->servoctets); + cp += gni_resp->servoctets; + } + + NTP_INSIST((size_t)(cp - (char *)resp) == resp_octets); + NTP_INSIST(resp_octets - sizeof(*resp) == gni_resp->octets); + + rc = queue_blocking_response(c, resp, resp_octets, req); + if (rc) + msyslog(LOG_ERR, "blocking_getnameinfo unable to queue response"); +#ifndef HAVE_ALLOCA + free(host); +#endif + return rc; +} + + +static void +getnameinfo_sometime_complete( + blocking_work_req rtype, + void * context, + size_t respsize, + void * resp + ) +{ + blocking_gni_req * gni_req; + blocking_gni_resp * gni_resp; + dnschild_ctx * child_ctx; + char * host; + char * service; + time_t time_now; + int again; + + gni_req = context; + gni_resp = resp; + + DEBUG_REQUIRE(BLOCKING_GETNAMEINFO == rtype); + DEBUG_REQUIRE(respsize == gni_resp->octets); + + child_ctx = dnschild_contexts[gni_req->dns_idx]; + + if (0 == gni_resp->retcode) { + /* + * If this query succeeded only after retrying, DNS may have + * just become responsive. + */ + if (gni_resp->retry > INITIAL_DNS_RETRY) { + time_now = time(NULL); + child_ctx->next_dns_timeslot = 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); + /* + * exponential backoff of DNS retries to 64s + */ + if (gni_req->retry > 0) + manage_dns_retry_interval(&gni_req->scheduled, + &gni_req->earliest, &gni_req->retry, + &child_ctx->next_dns_timeslot); + + if (gni_req->retry > 0 && again) { + if (!queue_blocking_request( + BLOCKING_GETNAMEINFO, + gni_req, + gni_req->octets, + &getnameinfo_sometime_complete, + gni_req)) + return; + + msyslog(LOG_ERR, "unable to retry reverse lookup of %s", stoa(&gni_req->socku)); + } + } + + if (!gni_resp->hostoctets) { + host = NULL; + service = NULL; + } else { + host = (char *)gni_resp + sizeof(*gni_resp); + service = (gni_resp->servoctets) + ? host + gni_resp->hostoctets + : NULL; + } + + (*gni_req->callback)(gni_resp->retcode, gni_resp->gni_errno, + &gni_req->socku, gni_req->flags, host, + service, gni_req->context); + + free(gni_req); + /* gni_resp is part of block freed by process_blocking_resp() */ +} + + +#ifdef TEST_BLOCKING_WORKER +void gni_test_callback(int rescode, int gni_errno, sockaddr_u *psau, int flags, const char *host, const char *service, void *context) +{ + if (!rescode) + TRACE(1, ("gni_test_callback got host '%s' serv '%s' for addr %s context %p\n", + host, service, stoa(psau), context)); + else + 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 */ + + +#ifdef HAVE_RES_INIT +static void +reload_resolv_conf( + dnsworker_ctx * worker_ctx + ) +{ + time_t time_now; + + /* + * This is ad-hoc. Reload /etc/resolv.conf once per minute + * to pick up on changes from the DHCP client. [Bug 1226] + * When using threads for the workers, this needs to happen + * only once per minute process-wide. + */ + time_now = time(NULL); +# ifdef WORK_THREAD + worker_ctx->next_res_init = next_res_init; +# endif + if (worker_ctx->next_res_init <= time_now) { + if (worker_ctx->next_res_init != 0) + res_init(); + worker_ctx->next_res_init = time_now + 60; +# ifdef WORK_THREAD + next_res_init = worker_ctx->next_res_init; +# endif + } +} +#endif /* HAVE_RES_INIT */ + + +static u_int +reserve_dnschild_ctx(void) +{ + const size_t ps = sizeof(dnschild_contexts[0]); + const size_t cs = sizeof(*dnschild_contexts[0]); + u_int c; + u_int new_alloc; + size_t octets; + size_t new_octets; + + c = 0; + while (TRUE) { + for ( ; c < dnschild_contexts_alloc; c++) { + if (NULL == dnschild_contexts[c]) { + dnschild_contexts[c] = emalloc_zero(cs); + + return c; + } + } + new_alloc = dnschild_contexts_alloc + 20; + new_octets = new_alloc * ps; + octets = dnschild_contexts_alloc * ps; + dnschild_contexts = erealloc_zero(dnschild_contexts, + new_octets, octets); + dnschild_contexts_alloc = new_alloc; + } +} + + +static u_int +get_dnschild_ctx(void) +{ + static u_int shared_ctx = UINT_MAX; + + if (worker_per_query) + return reserve_dnschild_ctx(); + + if (UINT_MAX == shared_ctx) + shared_ctx = reserve_dnschild_ctx(); + + return shared_ctx; +} + + +static void +alloc_dnsworker_context( + u_int idx + ) +{ + const size_t worker_context_sz = sizeof(*dnsworker_contexts[0]); + + REQUIRE(NULL == dnsworker_contexts[idx]); + dnsworker_contexts[idx] = emalloc_zero(worker_context_sz); +} + + +static dnsworker_ctx * +get_worker_context( + blocking_child * c, + u_int idx + ) +{ + static size_t ps = sizeof(dnsworker_contexts[0]); + u_int min_new_alloc; + u_int new_alloc; + size_t octets; + size_t new_octets; + + if (dnsworker_contexts_alloc <= idx) { + min_new_alloc = 1 + idx; + /* round new_alloc up to nearest multiple of 4 */ + new_alloc = (min_new_alloc + 4) & ~(4 - 1); + new_octets = new_alloc * ps; + octets = dnsworker_contexts_alloc * ps; + dnsworker_contexts = erealloc_zero(dnsworker_contexts, + new_octets, octets); + dnsworker_contexts_alloc = new_alloc; + } + + if (NULL == dnsworker_contexts[idx]) + alloc_dnsworker_context(idx); + ZERO(*dnsworker_contexts[idx]); + dnsworker_contexts[idx]->c = c; + + return dnsworker_contexts[idx]; +} + + +static void +scheduled_sleep( + time_t scheduled, + time_t earliest, + dnsworker_ctx * worker_ctx + ) +{ + time_t now; + + if (scheduled < 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) { + 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); + worker_ctx->ignore_scheduled_before = now; +#ifdef HAVE_RES_INIT + worker_ctx->next_res_init = now + 60; + next_res_init = worker_ctx->next_res_init; + res_init(); +#endif + TRACE(1, ("sleep interrupted by daemon, ignoring sleeps scheduled before now (%s)\n", + humantime(worker_ctx->ignore_scheduled_before))); + } + } +} + + +/* + * manage_dns_retry_interval is a helper used by + * getaddrinfo_sometime_complete and getnameinfo_sometime_complete + * to calculate the new retry interval and schedule the next query. + */ +static void +manage_dns_retry_interval( + time_t * pscheduled, + time_t * pwhen, + int * pretry, + time_t * pnext_timeslot + ) +{ + time_t now; + time_t when; + int retry; + + now = time(NULL); + retry = *pretry; + when = max(now + retry, *pnext_timeslot); + *pnext_timeslot = when; + retry = min(64, retry << 1); + + *pscheduled = now; + *pwhen = when; + *pretry = retry; +} + +/* + * should_retry_dns is a helper used by getaddrinfo_sometime_complete + * and getnameinfo_sometime_complete which implements ntpd's DNS retry + * policy. + */ +static int +should_retry_dns( + int rescode, + int res_errno + ) +{ + static int eai_again_seen; + int again; +#if defined (EAI_SYSTEM) && defined(DEBUG) + char msg[256]; +#endif + + /* + * If the resolver failed, see if the failure is + * temporary. If so, return success. + */ + again = 0; + + switch (rescode) { + + case EAI_FAIL: + again = 1; + break; + + case EAI_AGAIN: + again = 1; + eai_again_seen = 1; /* [Bug 1178] */ + break; + + case EAI_NONAME: +#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) + case EAI_NODATA: +#endif + again = !eai_again_seen; /* [Bug 1178] */ + break; + +#ifdef EAI_SYSTEM + case EAI_SYSTEM: + /* + * EAI_SYSTEM means the real error is in errno. We should be more + * discriminating about which errno values require retrying, but + * this matches existing behavior. + */ + again = 1; +# ifdef DEBUG + errno_to_str(res_errno, msg, sizeof(msg)); + TRACE(1, ("intres: EAI_SYSTEM errno %d (%s) means try again, right?\n", + res_errno, msg)); +# endif + break; +#endif + } + + TRACE(2, ("intres: resolver returned: %s (%d), %sretrying\n", + gai_strerror(rescode), rescode, again ? "" : "not ")); + + return again; +} + +#else /* !WORKER follows */ +int ntp_intres_nonempty_compilation_unit; +#endif diff --git a/libntp/ntp_libopts.c b/libntp/ntp_libopts.c index f155970019947..c504f8bf18cce 100644 --- a/libntp/ntp_libopts.c +++ b/libntp/ntp_libopts.c @@ -17,9 +17,11 @@ extern const char *Version; /* version.c for each program */ /* - * ntpOptionProcess() is a clone of libopts' optionProcess which - * overrides the --version output, appending detail from version.c - * which was not available at Autogen time. + * ntpOptionProcess() was a clone of libopts' optionProcess which + * overrode the --version output, appending detail from version.c + * which was not available at Autogen time. This is now done via + * AutoOpts' version-proc = override in copyright.def, so this + * routine is a straightforward wrapper of optionProcess(). */ int ntpOptionProcess( @@ -28,27 +30,29 @@ ntpOptionProcess( char ** argv ) { - char * pchOpts; - char ** ppzFullVersion; - char * pzNewFV; - char * pzAutogenFV; - size_t octets; - int rc; + return optionProcess(pOpts, argc, argv); +} + - pchOpts = (void *)pOpts; - ppzFullVersion = (char **)(pchOpts + offsetof(tOptions, - pzFullVersion)); - pzAutogenFV = *ppzFullVersion; - octets = strlen(pzAutogenFV) + - 1 + /* '\n' */ - strlen(Version) + - 1; /* '\0' */ - pzNewFV = emalloc(octets); - snprintf(pzNewFV, octets, "%s\n%s", pzAutogenFV, Version); - *ppzFullVersion = pzNewFV; - rc = optionProcess(pOpts, argc, argv); - *ppzFullVersion = pzAutogenFV; - free(pzNewFV); +/* + * ntpOptionPrintVersion() replaces the stock optionPrintVersion() via + * version-proc = ntpOptionPrintVersion; in copyright.def. It differs + * from the stock function by displaying the complete version string, + * including compile time which was unknown when Autogen ran. + * + * Like optionPrintVersion() this function must exit(0) rather than + * return. + */ +void +ntpOptionPrintVersion( + tOptions * pOpts, + tOptDesc * pOD + ) +{ + UNUSED_ARG(pOpts); + UNUSED_ARG(pOD); - return rc; + printf("%s\n", Version); + fflush(stdout); + exit(EXIT_SUCCESS); } diff --git a/libntp/ntp_lineedit.c b/libntp/ntp_lineedit.c index 55fdf0430ee82..c5aad31086140 100644 --- a/libntp/ntp_lineedit.c +++ b/libntp/ntp_lineedit.c @@ -93,8 +93,7 @@ ntp_readline_init( if (NULL == ntp_hist) { - fprintf(stderr, "history_init(): %s\n", - strerror(errno)); + mfprintf(stderr, "history_init(): %m\n"); fflush(stderr); el_end(ntp_el); @@ -103,7 +102,7 @@ ntp_readline_init( success = 0; } else { - memset(&hev, 0, sizeof(hev)); + ZERO(hev); #ifdef H_SETSIZE history(ntp_hist, &hev, H_SETSIZE, 128); #endif diff --git a/libntp/ntp_random.c b/libntp/ntp_random.c index c982a0d0ac1aa..0ada44f256b04 100644 --- a/libntp/ntp_random.c +++ b/libntp/ntp_random.c @@ -45,7 +45,7 @@ static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95"; #endif #include <stdio.h> -#include <ntp_types.h> +#include <l_stdlib.h> #include <ntp_random.h> #include <ntp_unixtime.h> @@ -140,15 +140,8 @@ static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95"; #define DEG_4 63 #define SEP_4 1 -/* - * Array versions of the above information to make code run faster -- - * relies on fact that TYPE_i == i. - */ #define MAX_TYPES 5 /* max number of types above */ -static long degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; -static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; - /* * Initially, everything is set up as if from: * @@ -163,7 +156,7 @@ static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3. */ -static long randtbl[DEG_3 + 1] = { +static unsigned long randtbl[DEG_3 + 1] = { TYPE_3, #ifdef USE_WEAK_SEEDING /* Historic implementation compatibility */ @@ -198,8 +191,8 @@ static long randtbl[DEG_3 + 1] = { * in the initialization of randtbl) because the state table pointer is set * to point to randtbl[1] (as explained below). */ -static long *fptr = &randtbl[SEP_3 + 1]; -static long *rptr = &randtbl[1]; +static unsigned long *fptr = &randtbl[SEP_3 + 1]; +static unsigned long *rptr = &randtbl[1]; /* * The following things are the pointer to the state information table, the @@ -211,11 +204,11 @@ static long *rptr = &randtbl[1]; * this is more efficient than indexing every time to find the address of * the last element to see if the front and rear pointers have wrapped. */ -static long *state = &randtbl[1]; +static unsigned long *state = &randtbl[1]; static long rand_type = TYPE_3; static long rand_deg = DEG_3; static long rand_sep = SEP_3; -static long *end_ptr = &randtbl[DEG_3 + 1]; +static unsigned long *end_ptr = &randtbl[DEG_3 + 1]; static inline long good_rand (long); @@ -268,19 +261,22 @@ ntp_srandom( unsigned long x ) { - register long i; + long i; - if (rand_type == TYPE_0) + if (rand_type == TYPE_0) { state[0] = x; - else { + } else { state[0] = x; for (i = 1; i < rand_deg; i++) state[i] = good_rand(state[i - 1]); fptr = &state[rand_sep]; rptr = &state[0]; for (i = 0; i < 10 * rand_deg; i++) - (void)ntp_random(); + x = ntp_random(); } + + /* seed the likely faster (and poorer) rand() as well */ + srand((u_int)x); } /* @@ -307,6 +303,24 @@ ntp_srandomdev( void ) } #endif + +/* + * ntp_initstate() and ntp_setstate() are unused in our codebase and + * trigger warnings due to casting to a more-strictly-aligned pointer + * on alignment-sensitive platforms. #ifdef them away to save noise, + * build time, and binary space, but retain the code in case we find a + * use. + */ +#ifdef COMPILE_UNUSED_FUNCTIONS +/* + * Array versions of the above information to make code run faster -- + * relies on fact that TYPE_i == i. + */ +#define MAX_TYPES 5 /* max number of types above */ + +static long degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; +static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; + /* * initstate: * @@ -370,7 +384,7 @@ ntp_initstate( rand_deg = DEG_4; rand_sep = SEP_4; } - state = (long *) (long_arg_state + 1); /* first location */ + state = (unsigned long *) (long_arg_state + 1); /* first location */ end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */ ntp_srandom(seed); if (rand_type == TYPE_0) @@ -404,7 +418,7 @@ ntp_setstate( char *arg_state /* pointer to state array */ ) { - register long *new_state = (long *) arg_state; + register unsigned long *new_state = (unsigned long *) arg_state; register long type = new_state[0] % MAX_TYPES; register long rear = new_state[0] / MAX_TYPES; char *ostate = (char *)(&state[-1]); @@ -427,7 +441,7 @@ ntp_setstate( (void)fprintf(stderr, "random: state info corrupted; not changed.\n"); } - state = (long *) (new_state + 1); + state = (new_state + 1); if (rand_type != TYPE_0) { rptr = &state[rear]; fptr = &state[(rear + rand_sep) % rand_deg]; @@ -435,6 +449,8 @@ ntp_setstate( end_ptr = &state[rand_deg]; /* set end_ptr too */ return(ostate); } +#endif /* COMPILE_UNUSED_FUNCTIONS */ + /* * random: @@ -457,7 +473,7 @@ long ntp_random( void ) { register long i; - register long *f, *r; + register unsigned long *f, *r; if (rand_type == TYPE_0) { i = state[0]; diff --git a/libntp/ntp_rfc2553.c b/libntp/ntp_rfc2553.c index 03af593cf71e0..f267999c5e3fa 100644 --- a/libntp/ntp_rfc2553.c +++ b/libntp/ntp_rfc2553.c @@ -80,8 +80,152 @@ #include "ntpd.h" #include "ntp_malloc.h" -#include "ntp_stdlib.h" #include "ntp_string.h" +#include "ntp_debug.h" + + +/* + * copy_addrinfo() - copy a single addrinfo to malloc()'d block. + * copy_addrinfo_list() - copy an addrinfo list to malloc()'d block. + * + * Copies an addrinfo list and its associated data to a contiguous block + * of storage from emalloc(). Callback routines invoked via + * getaddrinfo_sometime() have access to the resulting addrinfo list + * only until they return. This routine provides an easy way to make a + * persistent copy. Although the list provided to gai_sometime_callback + * routines is similarly contiguous, to keep this code usable in any + * context where we might want to duplicate an addrinfo list, it does + * not require the input list be contiguous. + * + * The returned list head pointer is passed to free() to release the + * entire list. + * + * In keeping with the rest of the NTP distribution, sockaddr_u is used + * in preference to struct sockaddr_storage, which is a member of the + * former union and so compatible. + * + * The rest of ntp_rfc2553.c is conditioned on ISC_PLATFORM_HAVEIPV6 + * not being defined, copy_addrinfo_*() are exceptions. + */ +struct addrinfo * copy_addrinfo_common(const struct addrinfo *, int +#ifdef EREALLOC_CALLSITE + , + const char *, int +#endif + ); + + +struct addrinfo * +copy_addrinfo_impl( + const struct addrinfo * src +#ifdef EREALLOC_CALLSITE + , + const char * caller_file, + int caller_line +#endif + ) +{ + return copy_addrinfo_common(src, TRUE +#ifdef EREALLOC_CALLSITE + , + caller_file, caller_line +#endif + ); +} + + +struct addrinfo * +copy_addrinfo_list_impl( + const struct addrinfo * src +#ifdef EREALLOC_CALLSITE + , + const char * caller_file, + int caller_line +#endif + ) +{ + return copy_addrinfo_common(src, FALSE +#ifdef EREALLOC_CALLSITE + , + caller_file, caller_line +#endif + ); +} + + +struct addrinfo * +copy_addrinfo_common( + const struct addrinfo * src, + int just_one +#ifdef EREALLOC_CALLSITE + , + const char * caller_file, + int caller_line +#endif + ) +{ + const struct addrinfo * ai_src; + const struct addrinfo * ai_nxt; + struct addrinfo * ai_cpy; + struct addrinfo * dst; + sockaddr_u * psau; + char * pcanon; + u_int elements; + size_t octets; + size_t canons_octets; + size_t str_octets; + + elements = 0; + canons_octets = 0; + + for (ai_src = src; NULL != ai_src; ai_src = ai_nxt) { + if (just_one) + ai_nxt = NULL; + else + ai_nxt = ai_src->ai_next; + ++elements; + if (NULL != ai_src->ai_canonname) + canons_octets += 1 + strlen(ai_src->ai_canonname); + } + + octets = elements * (sizeof(*ai_cpy) + sizeof(*psau)); + octets += canons_octets; + + dst = erealloczsite(NULL, octets, 0, TRUE, caller_file, + caller_line); + ai_cpy = dst; + psau = (void *)(ai_cpy + elements); + pcanon = (void *)(psau + elements); + + for (ai_src = src; NULL != ai_src; ai_src = ai_nxt) { + if (just_one) + ai_nxt = NULL; + else + ai_nxt = ai_src->ai_next; + *ai_cpy = *ai_src; + REQUIRE(ai_src->ai_addrlen <= sizeof(sockaddr_u)); + memcpy(psau, ai_src->ai_addr, ai_src->ai_addrlen); + ai_cpy->ai_addr = &psau->sa; + ++psau; + if (NULL != ai_cpy->ai_canonname) { + ai_cpy->ai_canonname = pcanon; + str_octets = 1 + strlen(ai_src->ai_canonname); + memcpy(pcanon, ai_src->ai_canonname, str_octets); + pcanon += str_octets; + } + if (NULL != ai_cpy->ai_next) { + if (just_one) + ai_cpy->ai_next = NULL; + else + ai_cpy->ai_next = ai_cpy + 1; + } + ++ai_cpy; + } + NTP_ENSURE(pcanon == ((char *)dst + octets)); + + return dst; +} + #ifndef ISC_PLATFORM_HAVEIPV6 @@ -290,7 +434,6 @@ getnameinfo (const struct sockaddr *sa, u_int salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { struct hostent *hp; - int namelen; if (sa->sa_family != AF_INET) return (EAI_FAMILY); @@ -303,16 +446,8 @@ getnameinfo (const struct sockaddr *sa, u_int salen, char *host, else return (EAI_FAIL); } - if (host != NULL && hostlen > 0) { - /* - * Don't exceed buffer - */ - namelen = min(strlen(hp->h_name), hostlen - 1); - if (namelen > 0) { - strncpy(host, hp->h_name, namelen); - host[namelen] = '\0'; - } - } + if (host != NULL && hostlen > 0) + strlcpy(host, hp->h_name, hostlen); return (0); } @@ -433,7 +568,7 @@ do_nodename( #ifdef ISC_PLATFORM_HAVESALEN ai->ai_addr->sa_len = sizeof(struct sockaddr); #endif - if (hints != NULL && hints->ai_flags & AI_CANONNAME) + if (hints != NULL && (hints->ai_flags & AI_CANONNAME)) ai->ai_canonname = estrdup(hp->h_name); return (0); } diff --git a/libntp/ntp_worker.c b/libntp/ntp_worker.c new file mode 100644 index 0000000000000..bb1cb87e44a04 --- /dev/null +++ b/libntp/ntp_worker.c @@ -0,0 +1,340 @@ +/* + * ntp_worker.c + */ +#include <config.h> +#include "ntp_workimpl.h" + +#ifdef WORKER + +#include <stdio.h> +#include <ctype.h> +#include <signal.h> + +#include "iosignal.h" +#include "ntp_stdlib.h" +#include "ntp_malloc.h" +#include "ntp_syslog.h" +#include "ntpd.h" +#include "ntp_io.h" +#include "ntp_assert.h" +#include "ntp_unixtime.h" +#include "intreswork.h" + + +#define CHILD_MAX_IDLE (3 * 60) /* seconds, idle worker limit */ + +blocking_child ** blocking_children; +size_t blocking_children_alloc; +int worker_per_query; /* boolean */ +int intres_req_pending; + + +#ifndef HAVE_IO_COMPLETION_PORT +/* + * pipe_socketpair() + * + * Provides an AF_UNIX socketpair on systems which have them, otherwise + * pair of unidirectional pipes. + */ +int +pipe_socketpair( + int caller_fds[2], + int * is_pipe + ) +{ + int rc; + int fds[2]; + int called_pipe; + +#ifdef HAVE_SOCKETPAIR + rc = socketpair(AF_UNIX, SOCK_STREAM, 0, &fds[0]); +#else + rc = -1; +#endif + + if (-1 == rc) { + rc = pipe(&fds[0]); + called_pipe = TRUE; + } else { + called_pipe = FALSE; + } + + if (-1 == rc) + return rc; + + caller_fds[0] = fds[0]; + caller_fds[1] = fds[1]; + if (is_pipe != NULL) + *is_pipe = called_pipe; + + return 0; +} + + +/* + * close_all_except() + * + * Close all file descriptors except the given keep_fd. + */ +void +close_all_except( + int keep_fd + ) +{ + int fd; + + for (fd = 0; fd < keep_fd; fd++) + close(fd); + + close_all_beyond(keep_fd); +} + + +/* + * close_all_beyond() + * + * Close all file descriptors after the given keep_fd, which is the + * highest fd to keep open. + */ +void +close_all_beyond( + int keep_fd + ) +{ +# ifdef HAVE_CLOSEFROM + closefrom(keep_fd + 1); +# elif defined(F_CLOSEM) + /* + * From 'Writing Reliable AIX Daemons,' SG24-4946-00, + * by Eric Agar (saves us from doing 32767 system + * calls) + */ + if (fcntl(keep_fd + 1, F_CLOSEM, 0) == -1) + msyslog(LOG_ERR, "F_CLOSEM(%d): %m", keep_fd + 1); +# else /* !HAVE_CLOSEFROM && !F_CLOSEM follows */ + int fd; + int max_fd; + + max_fd = GETDTABLESIZE(); + for (fd = keep_fd + 1; fd < max_fd; fd++) + close(fd); +# endif /* !HAVE_CLOSEFROM && !F_CLOSEM */ +} +#endif /* HAVE_IO_COMPLETION_PORT */ + + +u_int +available_blocking_child_slot(void) +{ + const size_t each = sizeof(blocking_children[0]); + u_int slot; + size_t prev_alloc; + size_t new_alloc; + size_t prev_octets; + size_t octets; + + for (slot = 0; slot < blocking_children_alloc; slot++) { + if (NULL == blocking_children[slot]) + return slot; + if (blocking_children[slot]->reusable) { + blocking_children[slot]->reusable = FALSE; + return slot; + } + } + + prev_alloc = blocking_children_alloc; + prev_octets = prev_alloc * each; + new_alloc = blocking_children_alloc + 4; + octets = new_alloc * each; + blocking_children = erealloc_zero(blocking_children, octets, + prev_octets); + blocking_children_alloc = new_alloc; + + return prev_alloc; +} + + +int +queue_blocking_request( + blocking_work_req rtype, + void * req, + size_t reqsize, + blocking_work_callback done_func, + void * context + ) +{ + static u_int intres_slot = UINT_MAX; + u_int child_slot; + blocking_child * c; + blocking_pipe_header req_hdr; + + req_hdr.octets = sizeof(req_hdr) + reqsize; + req_hdr.magic_sig = BLOCKING_REQ_MAGIC; + req_hdr.rtype = rtype; + req_hdr.done_func = done_func; + req_hdr.context = context; + + child_slot = UINT_MAX; + if (worker_per_query || UINT_MAX == intres_slot || + blocking_children[intres_slot]->reusable) + child_slot = available_blocking_child_slot(); + if (!worker_per_query) { + if (UINT_MAX == intres_slot) + intres_slot = child_slot; + else + child_slot = intres_slot; + if (0 == intres_req_pending) + intres_timeout_req(0); + } + intres_req_pending++; + INSIST(UINT_MAX != child_slot); + c = blocking_children[child_slot]; + if (NULL == c) { + c = emalloc_zero(sizeof(*c)); +#ifdef WORK_FORK + c->req_read_pipe = -1; + c->req_write_pipe = -1; +#endif +#ifdef WORK_PIPE + c->resp_read_pipe = -1; + c->resp_write_pipe = -1; +#endif + blocking_children[child_slot] = c; + } + req_hdr.child_idx = child_slot; + + return send_blocking_req_internal(c, &req_hdr, req); +} + + +int queue_blocking_response( + blocking_child * c, + blocking_pipe_header * resp, + size_t respsize, + const blocking_pipe_header * req + ) +{ + resp->octets = respsize; + resp->magic_sig = BLOCKING_RESP_MAGIC; + resp->rtype = req->rtype; + resp->context = req->context; + resp->done_func = req->done_func; + + return send_blocking_resp_internal(c, resp); +} + + +void +process_blocking_resp( + blocking_child * c + ) +{ + blocking_pipe_header * resp; + void * data; + + /* + * On Windows send_blocking_resp_internal() may signal the + * blocking_response_ready event multiple times while we're + * processing a response, so always consume all available + * responses before returning to test the event again. + */ +#ifdef WORK_THREAD + do { +#endif + resp = receive_blocking_resp_internal(c); + if (NULL != resp) { + DEBUG_REQUIRE(BLOCKING_RESP_MAGIC == + resp->magic_sig); + data = (char *)resp + sizeof(*resp); + intres_req_pending--; + (*resp->done_func)(resp->rtype, resp->context, + resp->octets - sizeof(*resp), + data); + free(resp); + } +#ifdef WORK_THREAD + } while (NULL != resp); +#endif + if (!worker_per_query && 0 == intres_req_pending) + intres_timeout_req(CHILD_MAX_IDLE); + else if (worker_per_query) + req_child_exit(c); +} + + +/* + * blocking_child_common runs as a forked child or a thread + */ +int +blocking_child_common( + blocking_child *c + ) +{ + int say_bye; + blocking_pipe_header *req; + + say_bye = FALSE; + while (!say_bye) { + req = receive_blocking_req_internal(c); + if (NULL == req) { + say_bye = TRUE; + break; + } + + DEBUG_REQUIRE(BLOCKING_REQ_MAGIC == req->magic_sig); + + switch (req->rtype) { + case BLOCKING_GETADDRINFO: + if (blocking_getaddrinfo(c, req)) + say_bye = TRUE; + break; + + case BLOCKING_GETNAMEINFO: + if (blocking_getnameinfo(c, req)) + say_bye = TRUE; + break; + + default: + msyslog(LOG_ERR, "unknown req %d to blocking worker", req->rtype); + say_bye = TRUE; + } + + free(req); + } + + return 0; +} + + +/* + * worker_idle_timer_fired() + * + * The parent starts this timer when the last pending response has been + * received from the child, making it idle, and clears the timer when a + * request is dispatched to the child. Once the timer expires, the + * child is sent packing. + * + * This is called when worker_idle_timer is nonzero and less than or + * equal to current_time. + */ +void +worker_idle_timer_fired(void) +{ + u_int idx; + blocking_child * c; + + DEBUG_REQUIRE(0 == intres_req_pending); + + intres_timeout_req(0); + for (idx = 0; idx < blocking_children_alloc; idx++) { + c = blocking_children[idx]; + if (NULL == c) + continue; + req_child_exit(c); + } +} + + +#else /* !WORKER follows */ +int ntp_worker_nonempty_compilation_unit; +#endif diff --git a/libntp/numtoa.c b/libntp/numtoa.c index 36a7c5819a4cf..5efbe942e3b4e 100644 --- a/libntp/numtoa.c +++ b/libntp/numtoa.c @@ -31,3 +31,29 @@ numtoa( (u_long)netnum & 0xff); return buf; } + + +/* Convert a refid & stratum to a string */ +const char * +refid_str( + u_int32 refid, + int stratum + ) +{ + char * text; + size_t tlen; + + if (stratum > 1) + return numtoa(refid); + + LIB_GETBUF(text); + text[0] = '.'; + memcpy(&text[1], &refid, sizeof(refid)); + text[1 + sizeof(refid)] = '\0'; + tlen = strlen(text); + text[tlen] = '.'; + text[tlen + 1] = '\0'; + + return text; +} + diff --git a/libntp/numtohost.c b/libntp/numtohost.c index b3d458ee06136..6b250d602de03 100644 --- a/libntp/numtohost.c +++ b/libntp/numtohost.c @@ -37,8 +37,7 @@ numtohost( return numtoa(netnum); LIB_GETBUF(bp); - - bp[LIB_BUFLENGTH-1] = '\0'; - (void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1); + strlcpy(bp, hp->h_name, LIB_BUFLENGTH); + return bp; } diff --git a/libntp/octtoint.c b/libntp/octtoint.c index f792b2bd61849..d189e40c494d1 100644 --- a/libntp/octtoint.c +++ b/libntp/octtoint.c @@ -2,6 +2,7 @@ * octtoint - convert an ascii string in octal to an unsigned * long, with error checking */ +#include <config.h> #include <stdio.h> #include <ctype.h> diff --git a/libntp/prettydate.c b/libntp/prettydate.c index 1503a2ce87e30..f121297161997 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -1,6 +1,7 @@ /* * prettydate - convert a time stamp to something readable */ +#include <config.h> #include <stdio.h> #include "ntp_fp.h" @@ -8,180 +9,194 @@ #include "lib_strbuf.h" #include "ntp_stdlib.h" #include "ntp_assert.h" +#include "ntp_calendar.h" + +#if SIZEOF_TIME_T < 4 +# error sizeof(time_t) < 4 -- this will not work! +#endif static char *common_prettydate(l_fp *, int); -const char *months[] = { +const char * const months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -static const char *days[] = { +const char * const daynames[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; /* Helper function to handle possible wraparound of the ntp epoch. + * + * Works by periodic extension of the ntp time stamp in the UN*X epoch. + * If the 'time_t' is 32 bit, use solar cycle warping to get the value + * in a suitable range. Also uses solar cycle warping to work around + * really buggy implementations of 'gmtime()' / 'localtime()' that + * cannot work with a negative time value, that is, times before + * 1970-01-01. (MSVCRT...) + * + * Apart from that we're assuming that the localtime/gmtime library + * functions have been updated so that they work... + * + * An explanation: The julian calendar repeats ever 28 years, because + * it's the LCM of 7 and 1461, the week and leap year cycles. This is + * called a 'solar cycle'. The gregorian calendar does the same as + * long as no centennial year (divisible by 100, but not 400) goes in + * the way. So between 1901 and 2099 (inclusive) we can warp time + * stamps by 28 years to make them suitable for localtime() and + * gmtime() if we have trouble. Of course this will play hubbubb with + * the DST zone switches, so we should do it only if necessary; but as + * we NEED a proper conversion to dates via gmtime() we should try to + * cope with as many idiosyncrasies as possible. + * + */ - Works by periodic extension of the ntp time stamp in the NTP epoch. If the - 'time_t' is 32 bit, use solar cycle warping to get the value in a suitable - range. Also uses solar cycle warping to work around really buggy - implementations of 'gmtime()' / 'localtime()' that cannot work with a - negative time value, that is, times before 1970-01-01. (MSVCRT...) - - Apart from that we're assuming that the localtime/gmtime library functions - have been updated so that they work... -*/ - - -/* solar cycle in secs, unsigned secs and years. And the cycle limits. -** -** And an explanation. The julian calendar repeats ever 28 years, because it's -** the LCM of 7 and 4, the week and leap year cycles. This is called a 'solar -** cycle'. The gregorian calendar does the same as long as no centennial year -** (divisible by 100, but not 400) goes in the way. So between 1901 and 2099 -** (inclusive) we can warp time stamps by 28 years to make them suitable for -** localtime() and gmtime() if we have trouble. Of course this will play -** hubbubb with the DST zone switches, so we should do it only if necessary; -** but as we NEED a proper conversion to dates via gmtime() we should try to -** cope with as many idiosyncrasies as possible. -*/ +/* + * solar cycle in unsigned secs and years, and the cycle limits. + */ #define SOLAR_CYCLE_SECS 0x34AADC80UL /* 7*1461*86400*/ #define SOLAR_CYCLE_YEARS 28 #define MINFOLD -3 -#define MAXFOLD 3 +#define MAXFOLD 3 -struct tm * -ntp2unix_tm( - u_long ntp, int local - ) +static struct tm * +get_struct_tm( + const vint64 *stamp, + int local) { - struct tm *tm; - int32 folds = 0; - time_t t = time(NULL); - u_int32 dwlo = (int32)t; /* might expand for SIZEOF_TIME_T < 4 */ -#if ( SIZEOF_TIME_T > 4 ) - int32 dwhi = (int32)(t >> 16 >> 16);/* double shift: avoid warnings */ -#else - /* - * Get the correct sign extension in the high part. - * (now >> 32) may not work correctly on every 32 bit - * system, e.g. it yields garbage under Win32/VC6. - */ - int32 dwhi = (int32)(t >> 31); -#endif - - /* Shift NTP to UN*X epoch, then unfold around currrent time. It's - * important to use a 32 bit max signed value -- LONG_MAX is 64 bit on - * a 64-bit system, and it will give wrong results. - */ - M_ADD(dwhi, dwlo, 0, ((1UL << 31)-1)); /* 32-bit max signed */ - if ((ntp -= JAN_1970) > dwlo) - --dwhi; - dwlo = ntp; - -# if SIZEOF_TIME_T < 4 -# error sizeof(time_t) < 4 -- this will not work! -# elif SIZEOF_TIME_T == 4 + struct tm *tm = NULL; + int32 folds = 0; + time_t ts; + +#ifdef HAVE_INT64 + + int64 tl; + ts = tl = stamp->q_s; /* - ** If the result will not fit into a 'time_t' we have to warp solar - ** cycles. That's implemented by looped addition / subtraction with - ** M_ADD and M_SUB to avoid implicit 64 bit operations, especially - ** division. As he number of warps is rather limited there's no big - ** performance loss here. - ** - ** note: unless the high word doesn't match the sign-extended low word, - ** the combination will not fit into time_t. That's what we use for - ** loop control here... - */ - while (dwhi != ((int32)dwlo >> 31)) { - if (dwhi < 0 && --folds >= MINFOLD) - M_ADD(dwhi, dwlo, 0, SOLAR_CYCLE_SECS); - else if (dwhi >= 0 && ++folds <= MAXFOLD) - M_SUB(dwhi, dwlo, 0, SOLAR_CYCLE_SECS); - else - return NULL; + * If there is chance of truncation, try to fix it. Let the + * compiler find out if this can happen at all. + */ + while (ts != tl) { /* truncation? */ + if (tl < 0) { + if (--folds < MINFOLD) + return NULL; + tl += SOLAR_CYCLE_SECS; + } else { + if (++folds > MAXFOLD) + return NULL; + tl -= SOLAR_CYCLE_SECS; + } + ts = tl; /* next try... */ } +#else -# else - - /* everything fine -- no reduction needed for the next thousand years */ + /* + * since we do not have 64-bit scalars, it's not likely we have + * 64-bit time_t. Assume 32 bits and properly reduce the value. + */ + u_int32 hi, lo; -# endif + hi = stamp->D_s.hi; + lo = stamp->D_s.lo; - /* combine hi/lo to make time stamp */ - t = ((time_t)dwhi << 16 << 16) | dwlo; /* double shift: avoid warnings */ + while ((hi && ~hi) || ((hi ^ lo) & 0x80000000u)) { + if (M_ISNEG(hi, lo)) { + if (--folds < MINFOLD) + return NULL; + M_ADD(hi, lo, 0, SOLAR_CYCLE_SECS); + } else { + if (++folds > MAXFOLD) + return NULL; + M_SUB(hi, lo, 0, SOLAR_CYCLE_SECS); + } + } + ts = (int32)lo; -# ifdef _MSC_VER /* make this an autoconf option? */ +#endif /* - ** The MSDN says that the (Microsoft) Windoze versions of 'gmtime()' - ** and 'localtime()' will bark on time stamps < 0. Better to fix it - ** immediately. - */ - while (t < 0) { - if (--folds < MINFOLD) - return NULL; - t += SOLAR_CYCLE_SECS; - } - -# endif /* Microsoft specific */ - - /* 't' should be a suitable value by now. Just go ahead. */ - while ( (tm = (*(local ? localtime : gmtime))(&t)) == 0) - /* seems there are some other pathological implementations of - ** 'gmtime()' and 'localtime()' somewhere out there. No matter - ** if we have 32-bit or 64-bit 'time_t', try to fix this by - ** solar cycle warping again... - */ - if (t < 0) { + * 'ts' should be a suitable value by now. Just go ahead, but + * with care: + * + * There are some pathological implementations of 'gmtime()' + * and 'localtime()' out there. No matter if we have 32-bit or + * 64-bit 'time_t', try to fix this by solar cycle warping + * again... + * + * At least the MSDN says that the (Microsoft) Windoze + * versions of 'gmtime()' and 'localtime()' will bark on time + * stamps < 0. + */ + while ((tm = (*(local ? localtime : gmtime))(&ts)) == NULL) + if (ts < 0) { if (--folds < MINFOLD) return NULL; - t += SOLAR_CYCLE_SECS; - } else { - if ((++folds > MAXFOLD) || ((t -= SOLAR_CYCLE_SECS) < 0)) - return NULL; /* That's truely pathological! */ - } - /* 'tm' surely not NULL here... */ + ts += SOLAR_CYCLE_SECS; + } else if (ts >= SOLAR_CYCLE_SECS) { + if (++folds > MAXFOLD) + return NULL; + ts -= SOLAR_CYCLE_SECS; + } else + return NULL; /* That's truly pathological! */ + + /* 'tm' surely not NULL here! */ NTP_INSIST(tm != NULL); if (folds != 0) { tm->tm_year += folds * SOLAR_CYCLE_YEARS; if (tm->tm_year <= 0 || tm->tm_year >= 200) return NULL; /* left warp range... can't help here! */ } + return tm; } - static char * common_prettydate( l_fp *ts, int local ) { - char *bp; - struct tm *tm; - u_long sec; - u_long msec; + static const char* pfmt[2] = { + "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03u", + "%08lx.%08lx [%s, %s %2d %4d %2d:%02d:%02d.%03u UTC]" + }; + + char *bp; + struct tm *tm; + u_int msec; + u_int32 ntps; + vint64 sec; LIB_GETBUF(bp); - - sec = ts->l_ui; - msec = ts->l_uf / 4294967; /* fract / (2 ** 32 / 1000) */ - tm = ntp2unix_tm(sec, local); - if (!tm) - snprintf(bp, LIB_BUFLENGTH, - "%08lx.%08lx --- --- -- ---- --:--:--", - (u_long)ts->l_ui, (u_long)ts->l_uf); - else - snprintf(bp, LIB_BUFLENGTH, - "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03lu", + /* get & fix milliseconds */ + ntps = ts->l_ui; + msec = ts->l_uf / 4294967; /* fract / (2 ** 32 / 1000) */ + if (msec >= 1000u) { + msec -= 1000u; + ntps++; + } + sec = ntpcal_ntp_to_time(ntps, NULL); + tm = get_struct_tm(&sec, local); + if (!tm) { + /* + * get a replacement, but always in UTC, using + * ntpcal_time_to_date() + */ + struct calendar jd; + ntpcal_time_to_date(&jd, &sec); + snprintf(bp, LIB_BUFLENGTH, pfmt[local != 0], (u_long)ts->l_ui, (u_long)ts->l_uf, - days[tm->tm_wday], months[tm->tm_mon], + daynames[jd.weekday], months[jd.month-1], + jd.monthday, jd.year, jd.hour, + jd.minute, jd.second, msec); + } else + snprintf(bp, LIB_BUFLENGTH, pfmt[0], + (u_long)ts->l_ui, (u_long)ts->l_uf, + daynames[tm->tm_wday], months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec, msec); - return bp; } @@ -202,3 +217,15 @@ gmprettydate( { return common_prettydate(ts, 0); } + + +struct tm * +ntp2unix_tm( + u_int32 ntp, int local + ) +{ + vint64 vl; + vl = ntpcal_ntp_to_time(ntp, NULL); + return get_struct_tm(&vl, local); +} + diff --git a/libntp/recvbuff.c b/libntp/recvbuff.c index 9a7d6caf4333e..83a9ee193a3b0 100644 --- a/libntp/recvbuff.c +++ b/libntp/recvbuff.c @@ -3,34 +3,27 @@ #endif #include <stdio.h> -#include "ntp_machine.h" + #include "ntp_assert.h" -#include "ntp_fp.h" #include "ntp_syslog.h" #include "ntp_stdlib.h" -#include "ntp_io.h" #include "ntp_lists.h" #include "recvbuff.h" #include "iosignal.h" - -#ifdef DEBUG -static void uninit_recvbuff(void); -#endif - /* * Memory allocation */ -static u_long volatile full_recvbufs; /* number of recvbufs on fulllist */ -static u_long volatile free_recvbufs; /* number of recvbufs on freelist */ +static u_long volatile full_recvbufs; /* recvbufs on full_recv_fifo */ +static u_long volatile free_recvbufs; /* recvbufs on free_recv_list */ static u_long volatile total_recvbufs; /* total recvbufs currently in use */ static u_long volatile lowater_adds; /* number of times we have added memory */ static u_long volatile buffer_shortfall;/* number of missed free receive buffers between replenishments */ -static ISC_LIST(recvbuf_t) full_recv_list; /* Currently used recv buffers */ -static recvbuf_t * free_recv_list; /* Currently unused buffers */ +static DECL_FIFO_ANCHOR(recvbuf_t) full_recv_fifo; +static recvbuf_t * free_recv_list; #if defined(SYS_WINNT) @@ -43,10 +36,15 @@ static CRITICAL_SECTION RecvLock; # define LOCK() EnterCriticalSection(&RecvLock) # define UNLOCK() LeaveCriticalSection(&RecvLock) #else -# define LOCK() -# define UNLOCK() +# define LOCK() do {} while (FALSE) +# define UNLOCK() do {} while (FALSE) #endif +#ifdef DEBUG +static void uninit_recvbuff(void); +#endif + + u_long free_recvbuffs (void) { @@ -74,7 +72,7 @@ lowater_additions(void) static inline void initialise_buffer(recvbuf_t *buff) { - memset(buff, 0, sizeof(*buff)); + ZERO(*buff); } static void @@ -87,7 +85,7 @@ create_buffers(int nbufs) buffer_shortfall = 0; #ifndef DEBUG - bufp = emalloc(abuf * sizeof(*bufp)); + bufp = emalloc_zero(abuf * sizeof(*bufp)); #endif for (i = 0; i < abuf; i++) { @@ -97,10 +95,9 @@ create_buffers(int nbufs) * free()d during ntpd shutdown on DEBUG builds to * keep them out of heap leak reports. */ - bufp = emalloc(sizeof(*bufp)); + bufp = emalloc_zero(sizeof(*bufp)); #endif - memset(bufp, 0, sizeof(*bufp)); - LINK_SLIST(free_recv_list, bufp, link.next); + LINK_SLIST(free_recv_list, bufp, link); bufp++; free_recvbufs++; total_recvbufs++; @@ -115,7 +112,6 @@ init_recvbuff(int nbufs) /* * Init buffer free list and stat counters */ - ISC_LIST_INIT(full_recv_list); free_recvbufs = total_recvbufs = 0; full_recvbufs = lowater_adds = 0; @@ -137,16 +133,19 @@ uninit_recvbuff(void) { recvbuf_t *rbunlinked; - while ((rbunlinked = ISC_LIST_HEAD(full_recv_list)) != NULL) { - ISC_LIST_DEQUEUE_TYPE(full_recv_list, rbunlinked, link, recvbuf_t); + for (;;) { + UNLINK_FIFO(rbunlinked, full_recv_fifo, link); + if (rbunlinked == NULL) + break; free(rbunlinked); } - do { - UNLINK_HEAD_SLIST(rbunlinked, free_recv_list, link.next); - if (rbunlinked != NULL) - free(rbunlinked); - } while (rbunlinked != NULL); + for (;;) { + UNLINK_HEAD_SLIST(rbunlinked, free_recv_list, link); + if (rbunlinked == NULL) + break; + free(rbunlinked); + } } #endif /* DEBUG */ @@ -163,10 +162,10 @@ freerecvbuf(recvbuf_t *rb) } LOCK(); - (rb->used)--; + rb->used--; if (rb->used != 0) msyslog(LOG_ERR, "******** freerecvbuff non-zero usage: %d *******", rb->used); - LINK_SLIST(free_recv_list, rb, link.next); + LINK_SLIST(free_recv_list, rb, link); free_recvbufs++; UNLOCK(); } @@ -180,29 +179,32 @@ add_full_recv_buffer(recvbuf_t *rb) return; } LOCK(); - ISC_LINK_INIT(rb, link); - ISC_LIST_APPEND(full_recv_list, rb, link); + LINK_FIFO(full_recv_fifo, rb, link); full_recvbufs++; UNLOCK(); } + recvbuf_t * get_free_recv_buffer(void) { recvbuf_t *buffer; LOCK(); - UNLINK_HEAD_SLIST(buffer, free_recv_list, link.next); + UNLINK_HEAD_SLIST(buffer, free_recv_list, link); if (buffer != NULL) { free_recvbufs--; initialise_buffer(buffer); - (buffer->used)++; - } else + buffer->used++; + } else { buffer_shortfall++; + } UNLOCK(); - return (buffer); + + return buffer; } + #ifdef HAVE_IO_COMPLETION_PORT recvbuf_t * get_free_recv_buffer_alloc(void) @@ -219,10 +221,12 @@ get_free_recv_buffer_alloc(void) } #endif + recvbuf_t * get_full_recv_buffer(void) { - recvbuf_t *rbuf; + recvbuf_t * rbuf; + LOCK(); #ifdef HAVE_SIGNALED_IO @@ -245,26 +249,78 @@ get_full_recv_buffer(void) /* * try to grab a full buffer */ - rbuf = ISC_LIST_HEAD(full_recv_list); - if (rbuf != NULL) { - ISC_LIST_DEQUEUE_TYPE(full_recv_list, rbuf, link, recvbuf_t); - --full_recvbufs; - } else - /* - * Make sure we reset the full count to 0 - */ - full_recvbufs = 0; + UNLINK_FIFO(rbuf, full_recv_fifo, link); + if (rbuf != NULL) + full_recvbufs--; UNLOCK(); - return (rbuf); + + return rbuf; } + +/* + * purge_recv_buffers_for_fd() - purges any previously-received input + * from a given file descriptor. + */ +void +purge_recv_buffers_for_fd( + SOCKET fd + ) +{ + recvbuf_t *rbufp; + recvbuf_t *next; + recvbuf_t *punlinked; + + LOCK(); + + for (rbufp = HEAD_FIFO(full_recv_fifo); + rbufp != NULL; + rbufp = next) { + next = rbufp->link; + if (rbufp->fd == fd) { + UNLINK_MID_FIFO(punlinked, full_recv_fifo, + rbufp, link, recvbuf_t); + INSIST(punlinked == rbufp); + full_recvbufs--; + freerecvbuf(rbufp); + } + } + + UNLOCK(); +} + + /* * Checks to see if there are buffers to process */ isc_boolean_t has_full_recv_buffer(void) { - if (ISC_LIST_HEAD(full_recv_list) != NULL) + if (HEAD_FIFO(full_recv_fifo) != NULL) return (ISC_TRUE); else return (ISC_FALSE); } + + +#ifdef NTP_DEBUG_LISTS_H +void +check_gen_fifo_consistency(void *fifo) +{ + gen_fifo *pf; + gen_node *pthis; + gen_node **pptail; + + pf = fifo; + REQUIRE((NULL == pf->phead && NULL == pf->pptail) || + (NULL != pf->phead && NULL != pf->pptail)); + + pptail = &pf->phead; + for (pthis = pf->phead; + pthis != NULL; + pthis = pthis->link) + if (NULL != pthis->link) + pptail = &pthis->link; + + REQUIRE(NULL == pf->pptail || pptail == pf->pptail); +} +#endif /* NTP_DEBUG_LISTS_H */ diff --git a/libntp/refnumtoa.c b/libntp/refnumtoa.c index c52bc28b6389c..e6ca55aef8681 100644 --- a/libntp/refnumtoa.c +++ b/libntp/refnumtoa.c @@ -1,36 +1,36 @@ /* * refnumtoa - return asciized refclock addresses stored in local array space */ +#include <config.h> #include <stdio.h> #include "ntp_net.h" #include "lib_strbuf.h" #include "ntp_stdlib.h" -char * +const char * refnumtoa( sockaddr_u *num ) { - register u_int32 netnum; - register char *buf; - register const char *rclock; + u_int32 netnum; + char *buf; + const char *rclock; - LIB_GETBUF(buf); - - if (ISREFCLOCKADR(num)) { - netnum = SRCADR(num); - rclock = clockname((int)((u_long)netnum >> 8) & 0xff); + if (!ISREFCLOCKADR(num)) + return socktoa(num); - if (rclock != NULL) - snprintf(buf, LIB_BUFLENGTH, "%s(%lu)", - rclock, (u_long)netnum & 0xff); - else - snprintf(buf, LIB_BUFLENGTH, "REFCLK(%lu,%lu)", - ((u_long)netnum >> 8) & 0xff, - (u_long)netnum & 0xff); + LIB_GETBUF(buf); + netnum = SRCADR(num); + rclock = clockname((int)((u_long)netnum >> 8) & 0xff); - } + if (rclock != NULL) + snprintf(buf, LIB_BUFLENGTH, "%s(%lu)", + rclock, (u_long)netnum & 0xff); + else + snprintf(buf, LIB_BUFLENGTH, "REFCLK(%lu,%lu)", + ((u_long)netnum >> 8) & 0xff, + (u_long)netnum & 0xff); return buf; } diff --git a/libntp/snprintf.c b/libntp/snprintf.c index 7588b8483a0a6..2b6a37473e1f2 100644 --- a/libntp/snprintf.c +++ b/libntp/snprintf.c @@ -1,62 +1,2132 @@ +/* + * Modified by Dave Hart for integration into NTP 4.2.7 <hart@ntp.org> + * + * Changed in a backwards-incompatible way to separate HAVE_SNPRINTF + * from HW_WANT_RPL_SNPRINTF, etc. for each of the four replaced + * functions. + * + * Changed to honor hw_force_rpl_snprintf=yes, etc. This is used by NTP + * to test rpl_snprintf() and rpl_vsnprintf() on platforms which provide + * C99-compliant implementations. + */ + +/* $Id: snprintf.c,v 1.9 2008/01/20 14:02:00 holger Exp $ */ + +/* + * Copyright (c) 1995 Patrick Powell. + * + * This code is based on code written by Patrick Powell <papowell@astart.com>. + * It may be used for any purpose as long as this notice remains intact on all + * source code distributions. + */ + +/* + * Copyright (c) 2008 Holger Weiss. + * + * This version of the code is maintained by Holger Weiss <holger@jhweiss.de>. + * My changes to the code may freely be used, modified and/or redistributed for + * any purpose. It would be nice if additions and fixes to this file (including + * trivial code cleanups) would be sent back in order to let me include them in + * the version available at <http://www.jhweiss.de/software/snprintf.html>. + * However, this is not a requirement for using or redistributing (possibly + * modified) versions of this file, nor is leaving this notice intact mandatory. + */ + +/* + * History + * + * 2008-01-20 Holger Weiss <holger@jhweiss.de> for C99-snprintf 1.1: + * + * Fixed the detection of infinite floating point values on IRIX (and + * possibly other systems) and applied another few minor cleanups. + * + * 2008-01-06 Holger Weiss <holger@jhweiss.de> for C99-snprintf 1.0: + * + * Added a lot of new features, fixed many bugs, and incorporated various + * improvements done by Andrew Tridgell <tridge@samba.org>, Russ Allbery + * <rra@stanford.edu>, Hrvoje Niksic <hniksic@xemacs.org>, Damien Miller + * <djm@mindrot.org>, and others for the Samba, INN, Wget, and OpenSSH + * projects. The additions include: support the "e", "E", "g", "G", and + * "F" conversion specifiers (and use conversion style "f" or "F" for the + * still unsupported "a" and "A" specifiers); support the "hh", "ll", "j", + * "t", and "z" length modifiers; support the "#" flag and the (non-C99) + * "'" flag; use localeconv(3) (if available) to get both the current + * locale's decimal point character and the separator between groups of + * digits; fix the handling of various corner cases of field width and + * precision specifications; fix various floating point conversion bugs; + * handle infinite and NaN floating point values; don't attempt to write to + * the output buffer (which may be NULL) if a size of zero was specified; + * check for integer overflow of the field width, precision, and return + * values and during the floating point conversion; use the OUTCHAR() macro + * instead of a function for better performance; provide asprintf(3) and + * vasprintf(3) functions; add new test cases. The replacement functions + * have been renamed to use an "rpl_" prefix, the function calls in the + * main project (and in this file) must be redefined accordingly for each + * replacement function which is needed (by using Autoconf or other means). + * Various other minor improvements have been applied and the coding style + * was cleaned up for consistency. + * + * 2007-07-23 Holger Weiss <holger@jhweiss.de> for Mutt 1.5.13: + * + * C99 compliant snprintf(3) and vsnprintf(3) functions return the number + * of characters that would have been written to a sufficiently sized + * buffer (excluding the '\0'). The original code simply returned the + * length of the resulting output string, so that's been fixed. + * + * 1998-03-05 Michael Elkins <me@mutt.org> for Mutt 0.90.8: + * + * The original code assumed that both snprintf(3) and vsnprintf(3) were + * missing. Some systems only have snprintf(3) but not vsnprintf(3), so + * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. + * + * 1998-01-27 Thomas Roessler <roessler@does-not-exist.org> for Mutt 0.89i: + * + * The PGP code was using unsigned hexadecimal formats. Unfortunately, + * unsigned formats simply didn't work. + * + * 1997-10-22 Brandon Long <blong@fiction.net> for Mutt 0.87.1: + * + * Ok, added some minimal floating point support, which means this probably + * requires libm on most operating systems. Don't yet support the exponent + * (e,E) and sigfig (g,G). Also, fmtint() was pretty badly broken, it just + * wasn't being exercised in ways which showed it, so that's been fixed. + * Also, formatted the code to Mutt conventions, and removed dead code left + * over from the original. Also, there is now a builtin-test, run with: + * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm && ./snprintf + * + * 2996-09-15 Brandon Long <blong@fiction.net> for Mutt 0.43: + * + * This was ugly. It is still ugly. I opted out of floating point + * numbers, but the formatter understands just about everything from the + * normal C string format, at least as far as I can tell from the Solaris + * 2.5 printf(3S) man page. + */ + +/* + * ToDo + * + * - Add wide character support. + * - Add support for "%a" and "%A" conversions. + * - Create test routines which predefine the expected results. Our test cases + * usually expose bugs in system implementations rather than in ours :-) + */ + +/* + * Usage + * + * 1) The following preprocessor macros should be defined to 1 if the feature or + * file in question is available on the target system (by using Autoconf or + * other means), though basic functionality should be available as long as + * HAVE_STDARG_H and HAVE_STDLIB_H are defined correctly: + * + * HW_WANT_RPL_VSNPRINTF + * HW_WANT_RPL_SNPRINTF + * HW_WANT_RPL_VASPRINTF + * HW_WANT_RPL_ASPRINTF + * HAVE_VSNPRINTF // define to 1 #if HW_WANT_RPL_VSNPRINTF + * HAVE_SNPRINTF // define to 1 #if HW_WANT_RPL_SNPRINTF + * HAVE_VASPRINTF // define to 1 #if HW_WANT_RPL_VASPRINTF + * HAVE_ASPRINTF // define to 1 #if HW_WANT_RPL_ASPRINTF + * HAVE_STDARG_H + * HAVE_STDDEF_H + * HAVE_STDINT_H + * HAVE_STDLIB_H + * HAVE_INTTYPES_H + * HAVE_LOCALE_H + * HAVE_LOCALECONV + * HAVE_LCONV_DECIMAL_POINT + * HAVE_LCONV_THOUSANDS_SEP + * HAVE_LONG_DOUBLE + * HAVE_LONG_LONG_INT + * HAVE_UNSIGNED_LONG_LONG_INT + * HAVE_INTMAX_T + * HAVE_UINTMAX_T + * HAVE_UINTPTR_T + * HAVE_PTRDIFF_T + * HAVE_VA_COPY + * HAVE___VA_COPY + * + * 2) The calls to the functions which should be replaced must be redefined + * throughout the project files (by using Autoconf or other means): + * + * #if HW_WANT_RPL_VSNPRINTF + * #define vsnprintf rpl_vsnprintf + * #endif + * #if HW_WANT_RPL_SNPRINTF + * #define snprintf rpl_snprintf + * #endif + * #if HW_WANT_RPL_VASPRINTF + * #define vasprintf rpl_vasprintf + * #endif + * #if HW_WANT_RPL_ASPRINTF + * #define asprintf rpl_asprintf + * #endif + * + * 3) The required replacement functions should be declared in some header file + * included throughout the project files: + * + * #if HAVE_CONFIG_H + * #include <config.h> + * #endif + * #if HAVE_STDARG_H + * #include <stdarg.h> + * #if HW_WANT_RPL_VSNPRINTF + * int rpl_vsnprintf(char *, size_t, const char *, va_list); + * #endif + * #if HW_WANT_RPL_SNPRINTF + * int rpl_snprintf(char *, size_t, const char *, ...); + * #endif + * #if HW_WANT_RPL_VASPRINTF + * int rpl_vasprintf(char **, const char *, va_list); + * #endif + * #if HW_WANT_RPL_ASPRINTF + * int rpl_asprintf(char **, const char *, ...); + * #endif + * #endif + * + * Autoconf macros for handling step 1 and step 2 are available at + * <http://www.jhweiss.de/software/snprintf.html>. + */ + +#if HAVE_CONFIG_H #include <config.h> +#endif /* HAVE_CONFIG_H */ -#if !HAVE_SNPRINTF -#include <sys/types.h> +#if TEST_SNPRINTF +#include <math.h> /* For pow(3), NAN, and INFINITY. */ +#include <string.h> /* For strcmp(3). */ +#if defined(__NetBSD__) || \ + defined(__FreeBSD__) || \ + defined(__OpenBSD__) || \ + defined(__NeXT__) || \ + defined(__bsd__) +#define OS_BSD 1 +#elif defined(sgi) || defined(__sgi) +#ifndef __c99 +#define __c99 /* Force C99 mode to get <stdint.h> included on IRIX 6.5.30. */ +#endif /* !defined(__c99) */ +#define OS_IRIX 1 +#define OS_SYSV 1 +#elif defined(__svr4__) +#define OS_SYSV 1 +#elif defined(__linux__) +#define OS_LINUX 1 +#endif /* defined(__NetBSD__) || defined(__FreeBSD__) || [...] */ +#if HAVE_CONFIG_H /* Undefine definitions possibly done in config.h. */ +#ifdef HAVE_SNPRINTF +#undef HAVE_SNPRINTF +#endif /* defined(HAVE_SNPRINTF) */ +#ifdef HAVE_VSNPRINTF +#undef HAVE_VSNPRINTF +#endif /* defined(HAVE_VSNPRINTF) */ +#ifdef HAVE_ASPRINTF +#undef HAVE_ASPRINTF +#endif /* defined(HAVE_ASPRINTF) */ +#ifdef HAVE_VASPRINTF +#undef HAVE_VASPRINTF +#endif /* defined(HAVE_VASPRINTF) */ +#ifdef snprintf +#undef snprintf +#endif /* defined(snprintf) */ +#ifdef vsnprintf +#undef vsnprintf +#endif /* defined(vsnprintf) */ +#ifdef asprintf +#undef asprintf +#endif /* defined(asprintf) */ +#ifdef vasprintf +#undef vasprintf +#endif /* defined(vasprintf) */ +#else /* By default, we assume a modern system for testing. */ +#ifndef HAVE_STDARG_H +#define HAVE_STDARG_H 1 +#endif /* HAVE_STDARG_H */ +#ifndef HAVE_STDDEF_H +#define HAVE_STDDEF_H 1 +#endif /* HAVE_STDDEF_H */ +#ifndef HAVE_STDINT_H +#define HAVE_STDINT_H 1 +#endif /* HAVE_STDINT_H */ +#ifndef HAVE_STDLIB_H +#define HAVE_STDLIB_H 1 +#endif /* HAVE_STDLIB_H */ +#ifndef HAVE_INTTYPES_H +#define HAVE_INTTYPES_H 1 +#endif /* HAVE_INTTYPES_H */ +#ifndef HAVE_LOCALE_H +#define HAVE_LOCALE_H 1 +#endif /* HAVE_LOCALE_H */ +#ifndef HAVE_LOCALECONV +#define HAVE_LOCALECONV 1 +#endif /* !defined(HAVE_LOCALECONV) */ +#ifndef HAVE_LCONV_DECIMAL_POINT +#define HAVE_LCONV_DECIMAL_POINT 1 +#endif /* HAVE_LCONV_DECIMAL_POINT */ +#ifndef HAVE_LCONV_THOUSANDS_SEP +#define HAVE_LCONV_THOUSANDS_SEP 1 +#endif /* HAVE_LCONV_THOUSANDS_SEP */ +#ifndef HAVE_LONG_DOUBLE +#define HAVE_LONG_DOUBLE 1 +#endif /* !defined(HAVE_LONG_DOUBLE) */ +#ifndef HAVE_LONG_LONG_INT +#define HAVE_LONG_LONG_INT 1 +#endif /* !defined(HAVE_LONG_LONG_INT) */ +#ifndef HAVE_UNSIGNED_LONG_LONG_INT +#define HAVE_UNSIGNED_LONG_LONG_INT 1 +#endif /* !defined(HAVE_UNSIGNED_LONG_LONG_INT) */ +#ifndef HAVE_INTMAX_T +#define HAVE_INTMAX_T 1 +#endif /* !defined(HAVE_INTMAX_T) */ +#ifndef HAVE_UINTMAX_T +#define HAVE_UINTMAX_T 1 +#endif /* !defined(HAVE_UINTMAX_T) */ +#ifndef HAVE_UINTPTR_T +#define HAVE_UINTPTR_T 1 +#endif /* !defined(HAVE_UINTPTR_T) */ +#ifndef HAVE_PTRDIFF_T +#define HAVE_PTRDIFF_T 1 +#endif /* !defined(HAVE_PTRDIFF_T) */ +#ifndef HAVE_VA_COPY +#define HAVE_VA_COPY 1 +#endif /* !defined(HAVE_VA_COPY) */ +#ifndef HAVE___VA_COPY +#define HAVE___VA_COPY 1 +#endif /* !defined(HAVE___VA_COPY) */ +#endif /* HAVE_CONFIG_H */ +#define snprintf rpl_snprintf +#define vsnprintf rpl_vsnprintf +#define asprintf rpl_asprintf +#define vasprintf rpl_vasprintf +#endif /* TEST_SNPRINTF */ -#ifdef __STDC__ +#if HW_WANT_RPL_SNPRINTF || HW_WANT_RPL_VSNPRINTF || HW_WANT_RPL_ASPRINTF || HW_WANT_RPL_VASPRINTF +#include <stdio.h> /* For NULL, size_t, vsnprintf(3), and vasprintf(3). */ +#ifdef VA_START +#undef VA_START +#endif /* defined(VA_START) */ +#ifdef VA_SHIFT +#undef VA_SHIFT +#endif /* defined(VA_SHIFT) */ +#if HAVE_STDARG_H #include <stdarg.h> -#else +#define VA_START(ap, last) va_start(ap, last) +#define VA_SHIFT(ap, value, type) /* No-op for ANSI C. */ +#else /* Assume <varargs.h> is available. */ #include <varargs.h> -#endif -#include <stdio.h> +#define VA_START(ap, last) va_start(ap) /* "last" is ignored. */ +#define VA_SHIFT(ap, value, type) value = va_arg(ap, type) +#endif /* HAVE_STDARG_H */ + +#if HW_WANT_RPL_VASPRINTF +#if HAVE_STDLIB_H +#include <stdlib.h> /* For malloc(3). */ +#endif /* HAVE_STDLIB_H */ +#ifdef VA_COPY +#undef VA_COPY +#endif /* defined(VA_COPY) */ +#ifdef VA_END_COPY +#undef VA_END_COPY +#endif /* defined(VA_END_COPY) */ +#if HAVE_VA_COPY +#define VA_COPY(dest, src) va_copy(dest, src) +#define VA_END_COPY(ap) va_end(ap) +#elif HAVE___VA_COPY +#define VA_COPY(dest, src) __va_copy(dest, src) +#define VA_END_COPY(ap) va_end(ap) +#else +#define VA_COPY(dest, src) (void)mymemcpy(&dest, &src, sizeof(va_list)) +#define VA_END_COPY(ap) /* No-op. */ +#define NEED_MYMEMCPY 1 +static void *mymemcpy(void *, void *, size_t); +#endif /* HAVE_VA_COPY */ +#endif /* HW_WANT_RPL_VASPRINTF */ -#include "l_stdlib.h" +#if HW_WANT_RPL_VSNPRINTF +#include <errno.h> /* For ERANGE and errno. */ +#include <limits.h> /* For *_MAX. */ +#if HAVE_INTTYPES_H +#include <inttypes.h> /* For intmax_t (if not defined in <stdint.h>). */ +#endif /* HAVE_INTTYPES_H */ +#if HAVE_LOCALE_H +#include <locale.h> /* For localeconv(3). */ +#endif /* HAVE_LOCALE_H */ +#if HAVE_STDDEF_H +#include <stddef.h> /* For ptrdiff_t. */ +#endif /* HAVE_STDDEF_H */ +#if HAVE_STDINT_H +#include <stdint.h> /* For intmax_t. */ +#endif /* HAVE_STDINT_H */ -#ifdef __STDC__ -int snprintf(char *str, size_t n, const char *fmt, ...) +/* Support for unsigned long long int. We may also need ULLONG_MAX. */ +#ifndef ULONG_MAX /* We may need ULONG_MAX as a fallback. */ +#ifdef UINT_MAX +#define ULONG_MAX UINT_MAX #else -int snprintf(str, n, fmt, va_alist) - char *str; - size_t n; - const char *fmt; - va_dcl -#endif +#define ULONG_MAX INT_MAX +#endif /* defined(UINT_MAX) */ +#endif /* !defined(ULONG_MAX) */ +#ifdef ULLONG +#undef ULLONG +#endif /* defined(ULLONG) */ +#if HAVE_UNSIGNED_LONG_LONG_INT +#define ULLONG unsigned long long int +#ifndef ULLONG_MAX +#define ULLONG_MAX ULONG_MAX +#endif /* !defined(ULLONG_MAX) */ +#else +#define ULLONG unsigned long int +#ifdef ULLONG_MAX +#undef ULLONG_MAX +#endif /* defined(ULLONG_MAX) */ +#define ULLONG_MAX ULONG_MAX +#endif /* HAVE_LONG_LONG_INT */ + +/* Support for uintmax_t. We also need UINTMAX_MAX. */ +#ifdef UINTMAX_T +#undef UINTMAX_T +#endif /* defined(UINTMAX_T) */ +#if HAVE_UINTMAX_T || defined(uintmax_t) +#define UINTMAX_T uintmax_t +#ifndef UINTMAX_MAX +#define UINTMAX_MAX ULLONG_MAX +#endif /* !defined(UINTMAX_MAX) */ +#else +#define UINTMAX_T ULLONG +#ifdef UINTMAX_MAX +#undef UINTMAX_MAX +#endif /* defined(UINTMAX_MAX) */ +#define UINTMAX_MAX ULLONG_MAX +#endif /* HAVE_UINTMAX_T || defined(uintmax_t) */ + +/* Support for long double. */ +#ifndef LDOUBLE +#if HAVE_LONG_DOUBLE +#define LDOUBLE long double +#else +#define LDOUBLE double +#endif /* HAVE_LONG_DOUBLE */ +#endif /* !defined(LDOUBLE) */ + +/* Support for long long int. */ +#ifndef LLONG +#if HAVE_LONG_LONG_INT +#define LLONG long long int +#else +#define LLONG long int +#endif /* HAVE_LONG_LONG_INT */ +#endif /* !defined(LLONG) */ + +/* Support for intmax_t. */ +#ifndef INTMAX_T +#if HAVE_INTMAX_T || defined(intmax_t) +#define INTMAX_T intmax_t +#else +#define INTMAX_T LLONG +#endif /* HAVE_INTMAX_T || defined(intmax_t) */ +#endif /* !defined(INTMAX_T) */ + +/* Support for uintptr_t. */ +#ifndef UINTPTR_T +#if HAVE_UINTPTR_T || defined(uintptr_t) +#define UINTPTR_T uintptr_t +#else +#define UINTPTR_T unsigned long int +#endif /* HAVE_UINTPTR_T || defined(uintptr_t) */ +#endif /* !defined(UINTPTR_T) */ + +/* Support for ptrdiff_t. */ +#ifndef PTRDIFF_T +#if HAVE_PTRDIFF_T || defined(ptrdiff_t) +#define PTRDIFF_T ptrdiff_t +#else +#define PTRDIFF_T long int +#endif /* HAVE_PTRDIFF_T || defined(ptrdiff_t) */ +#endif /* !defined(PTRDIFF_T) */ + +/* + * We need an unsigned integer type corresponding to ptrdiff_t (cf. C99: + * 7.19.6.1, 7). However, we'll simply use PTRDIFF_T and convert it to an + * unsigned type if necessary. This should work just fine in practice. + */ +#ifndef UPTRDIFF_T +#define UPTRDIFF_T PTRDIFF_T +#endif /* !defined(UPTRDIFF_T) */ + +/* + * We need a signed integer type corresponding to size_t (cf. C99: 7.19.6.1, 7). + * However, we'll simply use size_t and convert it to a signed type if + * necessary. This should work just fine in practice. + */ +#ifndef SSIZE_T +#define SSIZE_T size_t +#endif /* !defined(SSIZE_T) */ + +/* Either ERANGE or E2BIG should be available everywhere. */ +#ifndef ERANGE +#define ERANGE E2BIG +#endif /* !defined(ERANGE) */ +#ifndef EOVERFLOW +#define EOVERFLOW ERANGE +#endif /* !defined(EOVERFLOW) */ + +/* + * Buffer size to hold the octal string representation of UINT128_MAX without + * nul-termination ("3777777777777777777777777777777777777777777"). + */ +#ifdef MAX_CONVERT_LENGTH +#undef MAX_CONVERT_LENGTH +#endif /* defined(MAX_CONVERT_LENGTH) */ +#define MAX_CONVERT_LENGTH 43 + +/* Format read states. */ +#define PRINT_S_DEFAULT 0 +#define PRINT_S_FLAGS 1 +#define PRINT_S_WIDTH 2 +#define PRINT_S_DOT 3 +#define PRINT_S_PRECISION 4 +#define PRINT_S_MOD 5 +#define PRINT_S_CONV 6 + +/* Format flags. */ +#define PRINT_F_MINUS (1 << 0) +#define PRINT_F_PLUS (1 << 1) +#define PRINT_F_SPACE (1 << 2) +#define PRINT_F_NUM (1 << 3) +#define PRINT_F_ZERO (1 << 4) +#define PRINT_F_QUOTE (1 << 5) +#define PRINT_F_UP (1 << 6) +#define PRINT_F_UNSIGNED (1 << 7) +#define PRINT_F_TYPE_G (1 << 8) +#define PRINT_F_TYPE_E (1 << 9) + +/* Conversion flags. */ +#define PRINT_C_CHAR 1 +#define PRINT_C_SHORT 2 +#define PRINT_C_LONG 3 +#define PRINT_C_LLONG 4 +#define PRINT_C_LDOUBLE 5 +#define PRINT_C_SIZE 6 +#define PRINT_C_PTRDIFF 7 +#define PRINT_C_INTMAX 8 + +#ifndef MAX +#define MAX(x, y) ((x >= y) ? x : y) +#endif /* !defined(MAX) */ +#ifndef CHARTOINT +#define CHARTOINT(ch) (ch - '0') +#endif /* !defined(CHARTOINT) */ +#ifndef ISDIGIT +#define ISDIGIT(ch) ('0' <= (unsigned char)ch && (unsigned char)ch <= '9') +#endif /* !defined(ISDIGIT) */ +#ifndef ISNAN +#define ISNAN(x) (x != x) +#endif /* !defined(ISNAN) */ +#ifndef ISINF +#define ISINF(x) (x != 0.0 && x + x == x) +#endif /* !defined(ISINF) */ + +#ifdef OUTCHAR +#undef OUTCHAR +#endif /* defined(OUTCHAR) */ +#define OUTCHAR(str, len, size, ch) \ +do { \ + if (len + 1 < size) \ + str[len] = ch; \ + (len)++; \ +} while (/* CONSTCOND */ 0) + +static void fmtstr(char *, size_t *, size_t, const char *, int, int, int); +static void fmtint(char *, size_t *, size_t, INTMAX_T, int, int, int, int); +static void fmtflt(char *, size_t *, size_t, LDOUBLE, int, int, int, int *); +static void printsep(char *, size_t *, size_t); +static int getnumsep(int); +static int getexponent(LDOUBLE); +static int convert(UINTMAX_T, char *, size_t, int, int); +static UINTMAX_T cast(LDOUBLE); +static UINTMAX_T myround(LDOUBLE); +static LDOUBLE mypow10(int); + +int +rpl_vsnprintf(char *str, size_t size, const char *format, va_list args); + +int +rpl_vsnprintf(char *str, size_t size, const char *format, va_list args) +{ + LDOUBLE fvalue; + INTMAX_T value; + unsigned char cvalue; + const char *strvalue; + INTMAX_T *intmaxptr; + PTRDIFF_T *ptrdiffptr; + SSIZE_T *sizeptr; + LLONG *llongptr; + long int *longptr; + int *intptr; + short int *shortptr; + signed char *charptr; + size_t len = 0; + int overflow = 0; + int base = 0; + int cflags = 0; + int flags = 0; + int width = 0; + int precision = -1; + int state = PRINT_S_DEFAULT; + char ch = *format++; + + /* + * C99 says: "If `n' is zero, nothing is written, and `s' may be a null + * pointer." (7.19.6.5, 2) We're forgiving and allow a NULL pointer + * even if a size larger than zero was specified. At least NetBSD's + * snprintf(3) does the same, as well as other versions of this file. + * (Though some of these versions will write to a non-NULL buffer even + * if a size of zero was specified, which violates the standard.) + */ + if (str == NULL && size != 0) + size = 0; + + while (ch != '\0') + switch (state) { + case PRINT_S_DEFAULT: + if (ch == '%') + state = PRINT_S_FLAGS; + else + OUTCHAR(str, len, size, ch); + ch = *format++; + break; + case PRINT_S_FLAGS: + switch (ch) { + case '-': + flags |= PRINT_F_MINUS; + ch = *format++; + break; + case '+': + flags |= PRINT_F_PLUS; + ch = *format++; + break; + case ' ': + flags |= PRINT_F_SPACE; + ch = *format++; + break; + case '#': + flags |= PRINT_F_NUM; + ch = *format++; + break; + case '0': + flags |= PRINT_F_ZERO; + ch = *format++; + break; + case '\'': /* SUSv2 flag (not in C99). */ + flags |= PRINT_F_QUOTE; + ch = *format++; + break; + default: + state = PRINT_S_WIDTH; + break; + } + break; + case PRINT_S_WIDTH: + if (ISDIGIT(ch)) { + ch = CHARTOINT(ch); + if (width > (INT_MAX - ch) / 10) { + overflow = 1; + goto out; + } + width = 10 * width + ch; + ch = *format++; + } else if (ch == '*') { + /* + * C99 says: "A negative field width argument is + * taken as a `-' flag followed by a positive + * field width." (7.19.6.1, 5) + */ + if ((width = va_arg(args, int)) < 0) { + flags |= PRINT_F_MINUS; + width = -width; + } + ch = *format++; + state = PRINT_S_DOT; + } else + state = PRINT_S_DOT; + break; + case PRINT_S_DOT: + if (ch == '.') { + state = PRINT_S_PRECISION; + ch = *format++; + } else + state = PRINT_S_MOD; + break; + case PRINT_S_PRECISION: + if (precision == -1) + precision = 0; + if (ISDIGIT(ch)) { + ch = CHARTOINT(ch); + if (precision > (INT_MAX - ch) / 10) { + overflow = 1; + goto out; + } + precision = 10 * precision + ch; + ch = *format++; + } else if (ch == '*') { + /* + * C99 says: "A negative precision argument is + * taken as if the precision were omitted." + * (7.19.6.1, 5) + */ + if ((precision = va_arg(args, int)) < 0) + precision = -1; + ch = *format++; + state = PRINT_S_MOD; + } else + state = PRINT_S_MOD; + break; + case PRINT_S_MOD: + switch (ch) { + case 'h': + ch = *format++; + if (ch == 'h') { /* It's a char. */ + ch = *format++; + cflags = PRINT_C_CHAR; + } else + cflags = PRINT_C_SHORT; + break; + case 'l': + ch = *format++; + if (ch == 'l') { /* It's a long long. */ + ch = *format++; + cflags = PRINT_C_LLONG; + } else + cflags = PRINT_C_LONG; + break; + case 'L': + cflags = PRINT_C_LDOUBLE; + ch = *format++; + break; + case 'j': + cflags = PRINT_C_INTMAX; + ch = *format++; + break; + case 't': + cflags = PRINT_C_PTRDIFF; + ch = *format++; + break; + case 'z': + cflags = PRINT_C_SIZE; + ch = *format++; + break; + } + state = PRINT_S_CONV; + break; + case PRINT_S_CONV: + switch (ch) { + case 'd': + /* FALLTHROUGH */ + case 'i': + switch (cflags) { + case PRINT_C_CHAR: + value = (signed char)va_arg(args, int); + break; + case PRINT_C_SHORT: + value = (short int)va_arg(args, int); + break; + case PRINT_C_LONG: + value = va_arg(args, long int); + break; + case PRINT_C_LLONG: + value = va_arg(args, LLONG); + break; + case PRINT_C_SIZE: + value = va_arg(args, SSIZE_T); + break; + case PRINT_C_INTMAX: + value = va_arg(args, INTMAX_T); + break; + case PRINT_C_PTRDIFF: + value = va_arg(args, PTRDIFF_T); + break; + default: + value = va_arg(args, int); + break; + } + fmtint(str, &len, size, value, 10, width, + precision, flags); + break; + case 'X': + flags |= PRINT_F_UP; + /* FALLTHROUGH */ + case 'x': + base = 16; + /* FALLTHROUGH */ + case 'o': + if (base == 0) + base = 8; + /* FALLTHROUGH */ + case 'u': + if (base == 0) + base = 10; + flags |= PRINT_F_UNSIGNED; + switch (cflags) { + case PRINT_C_CHAR: + value = (unsigned char)va_arg(args, + unsigned int); + break; + case PRINT_C_SHORT: + value = (unsigned short int)va_arg(args, + unsigned int); + break; + case PRINT_C_LONG: + value = va_arg(args, unsigned long int); + break; + case PRINT_C_LLONG: + value = va_arg(args, ULLONG); + break; + case PRINT_C_SIZE: + value = va_arg(args, size_t); + break; + case PRINT_C_INTMAX: + value = va_arg(args, UINTMAX_T); + break; + case PRINT_C_PTRDIFF: + value = va_arg(args, UPTRDIFF_T); + break; + default: + value = va_arg(args, unsigned int); + break; + } + fmtint(str, &len, size, value, base, width, + precision, flags); + break; + case 'A': + /* Not yet supported, we'll use "%F". */ + /* FALLTHROUGH */ + case 'F': + flags |= PRINT_F_UP; + /* FALLTHROUGH */ + case 'a': + /* Not yet supported, we'll use "%f". */ + /* FALLTHROUGH */ + case 'f': + if (cflags == PRINT_C_LDOUBLE) + fvalue = va_arg(args, LDOUBLE); + else + fvalue = va_arg(args, double); + fmtflt(str, &len, size, fvalue, width, + precision, flags, &overflow); + if (overflow) + goto out; + break; + case 'E': + flags |= PRINT_F_UP; + /* FALLTHROUGH */ + case 'e': + flags |= PRINT_F_TYPE_E; + if (cflags == PRINT_C_LDOUBLE) + fvalue = va_arg(args, LDOUBLE); + else + fvalue = va_arg(args, double); + fmtflt(str, &len, size, fvalue, width, + precision, flags, &overflow); + if (overflow) + goto out; + break; + case 'G': + flags |= PRINT_F_UP; + /* FALLTHROUGH */ + case 'g': + flags |= PRINT_F_TYPE_G; + if (cflags == PRINT_C_LDOUBLE) + fvalue = va_arg(args, LDOUBLE); + else + fvalue = va_arg(args, double); + /* + * If the precision is zero, it is treated as + * one (cf. C99: 7.19.6.1, 8). + */ + if (precision == 0) + precision = 1; + fmtflt(str, &len, size, fvalue, width, + precision, flags, &overflow); + if (overflow) + goto out; + break; + case 'c': + cvalue = va_arg(args, int); + OUTCHAR(str, len, size, cvalue); + break; + case 's': + strvalue = va_arg(args, char *); + fmtstr(str, &len, size, strvalue, width, + precision, flags); + break; + case 'p': + /* + * C99 says: "The value of the pointer is + * converted to a sequence of printing + * characters, in an implementation-defined + * manner." (C99: 7.19.6.1, 8) + */ + if ((strvalue = va_arg(args, void *)) == NULL) + /* + * We use the glibc format. BSD prints + * "0x0", SysV "0". + */ + fmtstr(str, &len, size, "(nil)", width, + -1, flags); + else { + /* + * We use the BSD/glibc format. SysV + * omits the "0x" prefix (which we emit + * using the PRINT_F_NUM flag). + */ + flags |= PRINT_F_NUM; + flags |= PRINT_F_UNSIGNED; + fmtint(str, &len, size, + (UINTPTR_T)strvalue, 16, width, + precision, flags); + } + break; + case 'n': + switch (cflags) { + case PRINT_C_CHAR: + charptr = va_arg(args, signed char *); + *charptr = len; + break; + case PRINT_C_SHORT: + shortptr = va_arg(args, short int *); + *shortptr = len; + break; + case PRINT_C_LONG: + longptr = va_arg(args, long int *); + *longptr = len; + break; + case PRINT_C_LLONG: + llongptr = va_arg(args, LLONG *); + *llongptr = len; + break; + case PRINT_C_SIZE: + /* + * C99 says that with the "z" length + * modifier, "a following `n' conversion + * specifier applies to a pointer to a + * signed integer type corresponding to + * size_t argument." (7.19.6.1, 7) + */ + sizeptr = va_arg(args, SSIZE_T *); + *sizeptr = len; + break; + case PRINT_C_INTMAX: + intmaxptr = va_arg(args, INTMAX_T *); + *intmaxptr = len; + break; + case PRINT_C_PTRDIFF: + ptrdiffptr = va_arg(args, PTRDIFF_T *); + *ptrdiffptr = len; + break; + default: + intptr = va_arg(args, int *); + *intptr = len; + break; + } + break; + case '%': /* Print a "%" character verbatim. */ + OUTCHAR(str, len, size, ch); + break; + default: /* Skip other characters. */ + break; + } + ch = *format++; + state = PRINT_S_DEFAULT; + base = cflags = flags = width = 0; + precision = -1; + break; + } +out: + if (len < size) + str[len] = '\0'; + else if (size > 0) + str[size - 1] = '\0'; + + if (overflow || len >= INT_MAX) { + errno = overflow ? EOVERFLOW : ERANGE; + return -1; + } + return (int)len; +} + +static void +fmtstr(char *str, size_t *len, size_t size, const char *value, int width, + int precision, int flags) +{ + int padlen, strln; /* Amount to pad. */ + int noprecision = (precision == -1); + + if (value == NULL) /* We're forgiving. */ + value = "(null)"; + + /* If a precision was specified, don't read the string past it. */ + for (strln = 0; value[strln] != '\0' && + (noprecision || strln < precision); strln++) + continue; + + if ((padlen = width - strln) < 0) + padlen = 0; + if (flags & PRINT_F_MINUS) /* Left justify. */ + padlen = -padlen; + + while (padlen > 0) { /* Leading spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen--; + } + while (*value != '\0' && (noprecision || precision-- > 0)) { + OUTCHAR(str, *len, size, *value); + value++; + } + while (padlen < 0) { /* Trailing spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen++; + } +} + +static void +fmtint(char *str, size_t *len, size_t size, INTMAX_T value, int base, int width, + int precision, int flags) +{ + UINTMAX_T uvalue; + char iconvert[MAX_CONVERT_LENGTH]; + char sign = 0; + char hexprefix = 0; + int spadlen = 0; /* Amount to space pad. */ + int zpadlen = 0; /* Amount to zero pad. */ + int pos; + int separators = (flags & PRINT_F_QUOTE); + int noprecision = (precision == -1); + + if (flags & PRINT_F_UNSIGNED) + uvalue = value; + else { + uvalue = (value >= 0) ? value : -value; + if (value < 0) + sign = '-'; + else if (flags & PRINT_F_PLUS) /* Do a sign. */ + sign = '+'; + else if (flags & PRINT_F_SPACE) + sign = ' '; + } + + pos = convert(uvalue, iconvert, sizeof(iconvert), base, + flags & PRINT_F_UP); + + if (flags & PRINT_F_NUM && uvalue != 0) { + /* + * C99 says: "The result is converted to an `alternative form'. + * For `o' conversion, it increases the precision, if and only + * if necessary, to force the first digit of the result to be a + * zero (if the value and precision are both 0, a single 0 is + * printed). For `x' (or `X') conversion, a nonzero result has + * `0x' (or `0X') prefixed to it." (7.19.6.1, 6) + */ + switch (base) { + case 8: + if (precision <= pos) + precision = pos + 1; + break; + case 16: + hexprefix = (flags & PRINT_F_UP) ? 'X' : 'x'; + break; + } + } + + if (separators) /* Get the number of group separators we'll print. */ + separators = getnumsep(pos); + + zpadlen = precision - pos - separators; + spadlen = width /* Minimum field width. */ + - separators /* Number of separators. */ + - MAX(precision, pos) /* Number of integer digits. */ + - ((sign != 0) ? 1 : 0) /* Will we print a sign? */ + - ((hexprefix != 0) ? 2 : 0); /* Will we print a prefix? */ + + if (zpadlen < 0) + zpadlen = 0; + if (spadlen < 0) + spadlen = 0; + + /* + * C99 says: "If the `0' and `-' flags both appear, the `0' flag is + * ignored. For `d', `i', `o', `u', `x', and `X' conversions, if a + * precision is specified, the `0' flag is ignored." (7.19.6.1, 6) + */ + if (flags & PRINT_F_MINUS) /* Left justify. */ + spadlen = -spadlen; + else if (flags & PRINT_F_ZERO && noprecision) { + zpadlen += spadlen; + spadlen = 0; + } + while (spadlen > 0) { /* Leading spaces. */ + OUTCHAR(str, *len, size, ' '); + spadlen--; + } + if (sign != 0) /* Sign. */ + OUTCHAR(str, *len, size, sign); + if (hexprefix != 0) { /* A "0x" or "0X" prefix. */ + OUTCHAR(str, *len, size, '0'); + OUTCHAR(str, *len, size, hexprefix); + } + while (zpadlen > 0) { /* Leading zeros. */ + OUTCHAR(str, *len, size, '0'); + zpadlen--; + } + while (pos > 0) { /* The actual digits. */ + pos--; + OUTCHAR(str, *len, size, iconvert[pos]); + if (separators > 0 && pos > 0 && pos % 3 == 0) + printsep(str, len, size); + } + while (spadlen < 0) { /* Trailing spaces. */ + OUTCHAR(str, *len, size, ' '); + spadlen++; + } +} + +static void +fmtflt(char *str, size_t *len, size_t size, LDOUBLE fvalue, int width, + int precision, int flags, int *overflow) +{ + LDOUBLE ufvalue; + UINTMAX_T intpart; + UINTMAX_T fracpart; + UINTMAX_T mask; + const char *infnan = NULL; + char iconvert[MAX_CONVERT_LENGTH]; + char fconvert[MAX_CONVERT_LENGTH]; + char econvert[4]; /* "e-12" (without nul-termination). */ + char esign = 0; + char sign = 0; + int leadfraczeros = 0; + int exponent = 0; + int emitpoint = 0; + int omitzeros = 0; + int omitcount = 0; + int padlen = 0; + int epos = 0; + int fpos = 0; + int ipos = 0; + int separators = (flags & PRINT_F_QUOTE); + int estyle = (flags & PRINT_F_TYPE_E); +#if HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT + struct lconv *lc = localeconv(); +#endif /* HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT */ + + /* + * AIX' man page says the default is 0, but C99 and at least Solaris' + * and NetBSD's man pages say the default is 6, and sprintf(3) on AIX + * defaults to 6. + */ + if (precision == -1) + precision = 6; + + if (fvalue < 0.0) + sign = '-'; + else if (flags & PRINT_F_PLUS) /* Do a sign. */ + sign = '+'; + else if (flags & PRINT_F_SPACE) + sign = ' '; + + if (ISNAN(fvalue)) + infnan = (flags & PRINT_F_UP) ? "NAN" : "nan"; + else if (ISINF(fvalue)) + infnan = (flags & PRINT_F_UP) ? "INF" : "inf"; + + if (infnan != NULL) { + if (sign != 0) + iconvert[ipos++] = sign; + while (*infnan != '\0') + iconvert[ipos++] = *infnan++; + fmtstr(str, len, size, iconvert, width, ipos, flags); + return; + } + + /* "%e" (or "%E") or "%g" (or "%G") conversion. */ + if (flags & PRINT_F_TYPE_E || flags & PRINT_F_TYPE_G) { + if (flags & PRINT_F_TYPE_G) { + /* + * For "%g" (and "%G") conversions, the precision + * specifies the number of significant digits, which + * includes the digits in the integer part. The + * conversion will or will not be using "e-style" (like + * "%e" or "%E" conversions) depending on the precision + * and on the exponent. However, the exponent can be + * affected by rounding the converted value, so we'll + * leave this decision for later. Until then, we'll + * assume that we're going to do an "e-style" conversion + * (in order to get the exponent calculated). For + * "e-style", the precision must be decremented by one. + */ + precision--; + /* + * For "%g" (and "%G") conversions, trailing zeros are + * removed from the fractional portion of the result + * unless the "#" flag was specified. + */ + if (!(flags & PRINT_F_NUM)) + omitzeros = 1; + } + exponent = getexponent(fvalue); + estyle = 1; + } + +again: + /* + * Sorry, we only support 9, 19, or 38 digits (that is, the number of + * digits of the 32-bit, the 64-bit, or the 128-bit UINTMAX_MAX value + * minus one) past the decimal point due to our conversion method. + */ + switch (sizeof(UINTMAX_T)) { + case 16: + if (precision > 38) + precision = 38; + break; + case 8: + if (precision > 19) + precision = 19; + break; + default: + if (precision > 9) + precision = 9; + break; + } + + ufvalue = (fvalue >= 0.0) ? fvalue : -fvalue; + if (estyle) /* We want exactly one integer digit. */ + ufvalue /= mypow10(exponent); + + if ((intpart = cast(ufvalue)) == UINTMAX_MAX) { + *overflow = 1; + return; + } + + /* + * Factor of ten with the number of digits needed for the fractional + * part. For example, if the precision is 3, the mask will be 1000. + */ + mask = mypow10(precision); + /* + * We "cheat" by converting the fractional part to integer by + * multiplying by a factor of ten. + */ + if ((fracpart = myround(mask * (ufvalue - intpart))) >= mask) { + /* + * For example, ufvalue = 2.99962, intpart = 2, and mask = 1000 + * (because precision = 3). Now, myround(1000 * 0.99962) will + * return 1000. So, the integer part must be incremented by one + * and the fractional part must be set to zero. + */ + intpart++; + fracpart = 0; + if (estyle && intpart == 10) { + /* + * The value was rounded up to ten, but we only want one + * integer digit if using "e-style". So, the integer + * part must be set to one and the exponent must be + * incremented by one. + */ + intpart = 1; + exponent++; + } + } + + /* + * Now that we know the real exponent, we can check whether or not to + * use "e-style" for "%g" (and "%G") conversions. If we don't need + * "e-style", the precision must be adjusted and the integer and + * fractional parts must be recalculated from the original value. + * + * C99 says: "Let P equal the precision if nonzero, 6 if the precision + * is omitted, or 1 if the precision is zero. Then, if a conversion + * with style `E' would have an exponent of X: + * + * - if P > X >= -4, the conversion is with style `f' (or `F') and + * precision P - (X + 1). + * + * - otherwise, the conversion is with style `e' (or `E') and precision + * P - 1." (7.19.6.1, 8) + * + * Note that we had decremented the precision by one. + */ + if (flags & PRINT_F_TYPE_G && estyle && + precision + 1 > exponent && exponent >= -4) { + precision -= exponent; + estyle = 0; + goto again; + } + + if (estyle) { + if (exponent < 0) { + exponent = -exponent; + esign = '-'; + } else + esign = '+'; + + /* + * Convert the exponent. The sizeof(econvert) is 4. So, the + * econvert buffer can hold e.g. "e+99" and "e-99". We don't + * support an exponent which contains more than two digits. + * Therefore, the following stores are safe. + */ + epos = convert(exponent, econvert, 2, 10, 0); + /* + * C99 says: "The exponent always contains at least two digits, + * and only as many more digits as necessary to represent the + * exponent." (7.19.6.1, 8) + */ + if (epos == 1) + econvert[epos++] = '0'; + econvert[epos++] = esign; + econvert[epos++] = (flags & PRINT_F_UP) ? 'E' : 'e'; + } + + /* Convert the integer part and the fractional part. */ + ipos = convert(intpart, iconvert, sizeof(iconvert), 10, 0); + if (fracpart != 0) /* convert() would return 1 if fracpart == 0. */ + fpos = convert(fracpart, fconvert, sizeof(fconvert), 10, 0); + + leadfraczeros = precision - fpos; + + if (omitzeros) { + if (fpos > 0) /* Omit trailing fractional part zeros. */ + while (omitcount < fpos && fconvert[omitcount] == '0') + omitcount++; + else { /* The fractional part is zero, omit it completely. */ + omitcount = precision; + leadfraczeros = 0; + } + precision -= omitcount; + } + + /* + * Print a decimal point if either the fractional part is non-zero + * and/or the "#" flag was specified. + */ + if (precision > 0 || flags & PRINT_F_NUM) + emitpoint = 1; + if (separators) /* Get the number of group separators we'll print. */ + separators = getnumsep(ipos); + + padlen = width /* Minimum field width. */ + - ipos /* Number of integer digits. */ + - epos /* Number of exponent characters. */ + - precision /* Number of fractional digits. */ + - separators /* Number of group separators. */ + - (emitpoint ? 1 : 0) /* Will we print a decimal point? */ + - ((sign != 0) ? 1 : 0); /* Will we print a sign character? */ + + if (padlen < 0) + padlen = 0; + + /* + * C99 says: "If the `0' and `-' flags both appear, the `0' flag is + * ignored." (7.19.6.1, 6) + */ + if (flags & PRINT_F_MINUS) /* Left justifty. */ + padlen = -padlen; + else if (flags & PRINT_F_ZERO && padlen > 0) { + if (sign != 0) { /* Sign. */ + OUTCHAR(str, *len, size, sign); + sign = 0; + } + while (padlen > 0) { /* Leading zeros. */ + OUTCHAR(str, *len, size, '0'); + padlen--; + } + } + while (padlen > 0) { /* Leading spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen--; + } + if (sign != 0) /* Sign. */ + OUTCHAR(str, *len, size, sign); + while (ipos > 0) { /* Integer part. */ + ipos--; + OUTCHAR(str, *len, size, iconvert[ipos]); + if (separators > 0 && ipos > 0 && ipos % 3 == 0) + printsep(str, len, size); + } + if (emitpoint) { /* Decimal point. */ +#if HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT + if (lc->decimal_point != NULL && *lc->decimal_point != '\0') + OUTCHAR(str, *len, size, *lc->decimal_point); + else /* We'll always print some decimal point character. */ +#endif /* HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT */ + OUTCHAR(str, *len, size, '.'); + } + while (leadfraczeros > 0) { /* Leading fractional part zeros. */ + OUTCHAR(str, *len, size, '0'); + leadfraczeros--; + } + while (fpos > omitcount) { /* The remaining fractional part. */ + fpos--; + OUTCHAR(str, *len, size, fconvert[fpos]); + } + while (epos > 0) { /* Exponent. */ + epos--; + OUTCHAR(str, *len, size, econvert[epos]); + } + while (padlen < 0) { /* Trailing spaces. */ + OUTCHAR(str, *len, size, ' '); + padlen++; + } +} + +static void +printsep(char *str, size_t *len, size_t size) +{ +#if HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP + struct lconv *lc = localeconv(); + int i; + + if (lc->thousands_sep != NULL) + for (i = 0; lc->thousands_sep[i] != '\0'; i++) + OUTCHAR(str, *len, size, lc->thousands_sep[i]); + else +#endif /* HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP */ + OUTCHAR(str, *len, size, ','); +} + +static int +getnumsep(int digits) +{ + int separators = (digits - ((digits % 3 == 0) ? 1 : 0)) / 3; +#if HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP + int strln; + struct lconv *lc = localeconv(); + + /* We support an arbitrary separator length (including zero). */ + if (lc->thousands_sep != NULL) { + for (strln = 0; lc->thousands_sep[strln] != '\0'; strln++) + continue; + separators *= strln; + } +#endif /* HAVE_LOCALECONV && HAVE_LCONV_THOUSANDS_SEP */ + return separators; +} + +static int +getexponent(LDOUBLE value) +{ + LDOUBLE tmp = (value >= 0.0) ? value : -value; + int exponent = 0; + + /* + * We check for 99 > exponent > -99 in order to work around possible + * endless loops which could happen (at least) in the second loop (at + * least) if we're called with an infinite value. However, we checked + * for infinity before calling this function using our ISINF() macro, so + * this might be somewhat paranoid. + */ + while (tmp < 1.0 && tmp > 0.0 && --exponent > -99) + tmp *= 10; + while (tmp >= 10.0 && ++exponent < 99) + tmp /= 10; + + return exponent; +} + +static int +convert(UINTMAX_T value, char *buf, size_t size, int base, int caps) +{ + const char *digits = caps ? "0123456789ABCDEF" : "0123456789abcdef"; + size_t pos = 0; + + /* We return an unterminated buffer with the digits in reverse order. */ + do { + buf[pos++] = digits[value % base]; + value /= base; + } while (value != 0 && pos < size); + + return (int)pos; +} + +static UINTMAX_T +cast(LDOUBLE value) +{ + UINTMAX_T result; + + /* + * We check for ">=" and not for ">" because if UINTMAX_MAX cannot be + * represented exactly as an LDOUBLE value (but is less than LDBL_MAX), + * it may be increased to the nearest higher representable value for the + * comparison (cf. C99: 6.3.1.4, 2). It might then equal the LDOUBLE + * value although converting the latter to UINTMAX_T would overflow. + */ + if (value >= UINTMAX_MAX) + return UINTMAX_MAX; + + result = value; + /* + * At least on NetBSD/sparc64 3.0.2 and 4.99.30, casting long double to + * an integer type converts e.g. 1.9 to 2 instead of 1 (which violates + * the standard). Sigh. + */ + return (result <= value) ? result : result - 1; +} + +static UINTMAX_T +myround(LDOUBLE value) +{ + UINTMAX_T intpart = cast(value); + + return ((value -= intpart) < 0.5) ? intpart : intpart + 1; +} + +static LDOUBLE +mypow10(int exponent) +{ + LDOUBLE result = 1; + + while (exponent > 0) { + result *= 10; + exponent--; + } + while (exponent < 0) { + result /= 10; + exponent++; + } + return result; +} +#endif /* HW_WANT_RPL_VSNPRINTF */ + +#if HW_WANT_RPL_VASPRINTF +#if NEED_MYMEMCPY +void * +mymemcpy(void *dst, void *src, size_t len) +{ + const char *from = src; + char *to = dst; + + /* No need for optimization, we use this only to replace va_copy(3). */ + while (len-- > 0) + *to++ = *from++; + return dst; +} +#endif /* NEED_MYMEMCPY */ + +int +rpl_vasprintf(char **ret, const char *format, va_list ap); + +int +rpl_vasprintf(char **ret, const char *format, va_list ap) +{ + size_t size; + int len; + va_list aq; + + VA_COPY(aq, ap); + len = vsnprintf(NULL, 0, format, aq); + VA_END_COPY(aq); + if (len < 0 || (*ret = malloc(size = len + 1)) == NULL) + return -1; + return vsnprintf(*ret, size, format, ap); +} +#endif /* HW_WANT_RPL_VASPRINTF */ + +#if HW_WANT_RPL_SNPRINTF +#if HAVE_STDARG_H +int +rpl_snprintf(char *str, size_t size, const char *format, ...); + +int +rpl_snprintf(char *str, size_t size, const char *format, ...) +#else +int +rpl_snprintf(va_alist) va_dcl +#endif /* HAVE_STDARG_H */ { +#if !HAVE_STDARG_H + char *str; + size_t size; + char *format; +#endif /* HAVE_STDARG_H */ va_list ap; - int rval; -#ifdef VSPRINTF_CHARSTAR - char *rp; -#endif -#ifdef __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif -#ifdef VSPRINTF_CHARSTAR - rp = vsprintf(str, fmt, ap); + int len; + + VA_START(ap, format); + VA_SHIFT(ap, str, char *); + VA_SHIFT(ap, size, size_t); + VA_SHIFT(ap, format, const char *); + len = vsnprintf(str, size, format, ap); va_end(ap); - return (strlen(rp)); + return len; +} +#endif /* HW_WANT_RPL_SNPRINTF */ + +#if HW_WANT_RPL_ASPRINTF +#if HAVE_STDARG_H +int +rpl_asprintf(char **ret, const char *format, ...); + +int +rpl_asprintf(char **ret, const char *format, ...) #else - rval = vsprintf(str, fmt, ap); +int +rpl_asprintf(va_alist) va_dcl +#endif /* HAVE_STDARG_H */ +{ +#if !HAVE_STDARG_H + char **ret; + char *format; +#endif /* HAVE_STDARG_H */ + va_list ap; + int len; + + VA_START(ap, format); + VA_SHIFT(ap, ret, char **); + VA_SHIFT(ap, format, const char *); + len = vasprintf(ret, format, ap); va_end(ap); - return (rval); -#endif + return len; } +#endif /* HW_WANT_RPL_ASPRINTF */ +#else /* Dummy declaration to avoid empty translation unit warnings. */ +int main(void); +#endif /* HW_WANT_RPL_SNPRINTF || HW_WANT_RPL_VSNPRINTF || HW_WANT_RPL_ASPRINTF || [...] */ +#if TEST_SNPRINTF int -vsnprintf( - char *str, - size_t n, - const char *fmt, - va_list ap - ) +main(void) { -#ifdef VSPRINTF_CHARSTAR - return (strlen(vsprintf(str, fmt, ap))); -#else - return (vsprintf(str, fmt, ap)); -#endif + const char *float_fmt[] = { + /* "%E" and "%e" formats. */ +#if HAVE_LONG_LONG_INT && !OS_BSD && !OS_IRIX + "%.16e", + "%22.16e", + "%022.16e", + "%-22.16e", + "%#+'022.16e", +#endif /* HAVE_LONG_LONG_INT && !OS_BSD && !OS_IRIX */ + "foo|%#+0123.9E|bar", + "%-123.9e", + "%123.9e", + "%+23.9e", + "%+05.8e", + "%-05.8e", + "%05.8e", + "%+5.8e", + "%-5.8e", + "% 5.8e", + "%5.8e", + "%+4.9e", +#if !OS_LINUX /* glibc sometimes gets these wrong. */ + "%+#010.0e", + "%#10.1e", + "%10.5e", + "% 10.5e", + "%5.0e", + "%5.e", + "%#5.0e", + "%#5.e", + "%3.2e", + "%3.1e", + "%-1.5e", + "%1.5e", + "%01.3e", + "%1.e", + "%.1e", + "%#.0e", + "%+.0e", + "% .0e", + "%.0e", + "%#.e", + "%+.e", + "% .e", + "%.e", + "%4e", + "%e", + "%E", +#endif /* !OS_LINUX */ + /* "%F" and "%f" formats. */ +#if !OS_BSD && !OS_IRIX + "% '022f", + "%+'022f", + "%-'22f", + "%'22f", +#if HAVE_LONG_LONG_INT + "%.16f", + "%22.16f", + "%022.16f", + "%-22.16f", + "%#+'022.16f", +#endif /* HAVE_LONG_LONG_INT */ +#endif /* !OS_BSD && !OS_IRIX */ + "foo|%#+0123.9F|bar", + "%-123.9f", + "%123.9f", + "%+23.9f", + "%+#010.0f", + "%#10.1f", + "%10.5f", + "% 10.5f", + "%+05.8f", + "%-05.8f", + "%05.8f", + "%+5.8f", + "%-5.8f", + "% 5.8f", + "%5.8f", + "%5.0f", + "%5.f", + "%#5.0f", + "%#5.f", + "%+4.9f", + "%3.2f", + "%3.1f", + "%-1.5f", + "%1.5f", + "%01.3f", + "%1.f", + "%.1f", + "%#.0f", + "%+.0f", + "% .0f", + "%.0f", + "%#.f", + "%+.f", + "% .f", + "%.f", + "%4f", + "%f", + "%F", + /* "%G" and "%g" formats. */ +#if !OS_BSD && !OS_IRIX && !OS_LINUX + "% '022g", + "%+'022g", + "%-'22g", + "%'22g", +#if HAVE_LONG_LONG_INT + "%.16g", + "%22.16g", + "%022.16g", + "%-22.16g", + "%#+'022.16g", +#endif /* HAVE_LONG_LONG_INT */ +#endif /* !OS_BSD && !OS_IRIX && !OS_LINUX */ + "foo|%#+0123.9G|bar", + "%-123.9g", + "%123.9g", + "%+23.9g", + "%+05.8g", + "%-05.8g", + "%05.8g", + "%+5.8g", + "%-5.8g", + "% 5.8g", + "%5.8g", + "%+4.9g", +#if !OS_LINUX /* glibc sometimes gets these wrong. */ + "%+#010.0g", + "%#10.1g", + "%10.5g", + "% 10.5g", + "%5.0g", + "%5.g", + "%#5.0g", + "%#5.g", + "%3.2g", + "%3.1g", + "%-1.5g", + "%1.5g", + "%01.3g", + "%1.g", + "%.1g", + "%#.0g", + "%+.0g", + "% .0g", + "%.0g", + "%#.g", + "%+.g", + "% .g", + "%.g", + "%4g", + "%g", + "%G", +#endif /* !OS_LINUX */ + NULL + }; + double float_val[] = { + -4.136, + -134.52, + -5.04030201, + -3410.01234, + -999999.999999, + -913450.29876, + -913450.2, + -91345.2, + -9134.2, + -913.2, + -91.2, + -9.2, + -9.9, + 4.136, + 134.52, + 5.04030201, + 3410.01234, + 999999.999999, + 913450.29876, + 913450.2, + 91345.2, + 9134.2, + 913.2, + 91.2, + 9.2, + 9.9, + 9.96, + 9.996, + 9.9996, + 9.99996, + 9.999996, + 9.9999996, + 9.99999996, + 0.99999996, + 0.99999999, + 0.09999999, + 0.00999999, + 0.00099999, + 0.00009999, + 0.00000999, + 0.00000099, + 0.00000009, + 0.00000001, + 0.0000001, + 0.000001, + 0.00001, + 0.0001, + 0.001, + 0.01, + 0.1, + 1.0, + 1.5, + -1.5, + -1.0, + -0.1, +#if !OS_BSD /* BSD sometimes gets these wrong. */ +#ifdef INFINITY + INFINITY, + -INFINITY, +#endif /* defined(INFINITY) */ +#ifdef NAN + NAN, +#endif /* defined(NAN) */ +#endif /* !OS_BSD */ + 0 + }; + const char *long_fmt[] = { + "foo|%0123ld|bar", +#if !OS_IRIX + "% '0123ld", + "%+'0123ld", + "%-'123ld", + "%'123ld", +#endif /* !OS_IRiX */ + "%123.9ld", + "% 123.9ld", + "%+123.9ld", + "%-123.9ld", + "%0123ld", + "% 0123ld", + "%+0123ld", + "%-0123ld", + "%10.5ld", + "% 10.5ld", + "%+10.5ld", + "%-10.5ld", + "%010ld", + "% 010ld", + "%+010ld", + "%-010ld", + "%4.2ld", + "% 4.2ld", + "%+4.2ld", + "%-4.2ld", + "%04ld", + "% 04ld", + "%+04ld", + "%-04ld", + "%5.5ld", + "%+22.33ld", + "%01.3ld", + "%1.5ld", + "%-1.5ld", + "%44ld", + "%4ld", + "%4.0ld", + "%4.ld", + "%.44ld", + "%.4ld", + "%.0ld", + "%.ld", + "%ld", + NULL + }; + long int long_val[] = { +#ifdef LONG_MAX + LONG_MAX, +#endif /* LONG_MAX */ +#ifdef LONG_MIN + LONG_MIN, +#endif /* LONG_MIN */ + -91340, + 91340, + 341, + 134, + 0203, + -1, + 1, + 0 + }; + const char *ulong_fmt[] = { + /* "%u" formats. */ + "foo|%0123lu|bar", +#if !OS_IRIX + "% '0123lu", + "%+'0123lu", + "%-'123lu", + "%'123lu", +#endif /* !OS_IRiX */ + "%123.9lu", + "% 123.9lu", + "%+123.9lu", + "%-123.9lu", + "%0123lu", + "% 0123lu", + "%+0123lu", + "%-0123lu", + "%5.5lu", + "%+22.33lu", + "%01.3lu", + "%1.5lu", + "%-1.5lu", + "%44lu", + "%lu", + /* "%o" formats. */ + "foo|%#0123lo|bar", + "%#123.9lo", + "%# 123.9lo", + "%#+123.9lo", + "%#-123.9lo", + "%#0123lo", + "%# 0123lo", + "%#+0123lo", + "%#-0123lo", + "%#5.5lo", + "%#+22.33lo", + "%#01.3lo", + "%#1.5lo", + "%#-1.5lo", + "%#44lo", + "%#lo", + "%123.9lo", + "% 123.9lo", + "%+123.9lo", + "%-123.9lo", + "%0123lo", + "% 0123lo", + "%+0123lo", + "%-0123lo", + "%5.5lo", + "%+22.33lo", + "%01.3lo", + "%1.5lo", + "%-1.5lo", + "%44lo", + "%lo", + /* "%X" and "%x" formats. */ + "foo|%#0123lX|bar", + "%#123.9lx", + "%# 123.9lx", + "%#+123.9lx", + "%#-123.9lx", + "%#0123lx", + "%# 0123lx", + "%#+0123lx", + "%#-0123lx", + "%#5.5lx", + "%#+22.33lx", + "%#01.3lx", + "%#1.5lx", + "%#-1.5lx", + "%#44lx", + "%#lx", + "%#lX", + "%123.9lx", + "% 123.9lx", + "%+123.9lx", + "%-123.9lx", + "%0123lx", + "% 0123lx", + "%+0123lx", + "%-0123lx", + "%5.5lx", + "%+22.33lx", + "%01.3lx", + "%1.5lx", + "%-1.5lx", + "%44lx", + "%lx", + "%lX", + NULL + }; + unsigned long int ulong_val[] = { +#ifdef ULONG_MAX + ULONG_MAX, +#endif /* ULONG_MAX */ + 91340, + 341, + 134, + 0203, + 1, + 0 + }; + const char *llong_fmt[] = { + "foo|%0123lld|bar", + "%123.9lld", + "% 123.9lld", + "%+123.9lld", + "%-123.9lld", + "%0123lld", + "% 0123lld", + "%+0123lld", + "%-0123lld", + "%5.5lld", + "%+22.33lld", + "%01.3lld", + "%1.5lld", + "%-1.5lld", + "%44lld", + "%lld", + NULL + }; + LLONG llong_val[] = { +#ifdef LLONG_MAX + LLONG_MAX, +#endif /* LLONG_MAX */ +#ifdef LLONG_MIN + LLONG_MIN, +#endif /* LLONG_MIN */ + -91340, + 91340, + 341, + 134, + 0203, + -1, + 1, + 0 + }; + const char *string_fmt[] = { + "foo|%10.10s|bar", + "%-10.10s", + "%10.10s", + "%10.5s", + "%5.10s", + "%10.1s", + "%1.10s", + "%10.0s", + "%0.10s", + "%-42.5s", + "%2.s", + "%.10s", + "%.1s", + "%.0s", + "%.s", + "%4s", + "%s", + NULL + }; + const char *string_val[] = { + "Hello", + "Hello, world!", + "Sound check: One, two, three.", + "This string is a little longer than the other strings.", + "1", + "", + NULL + }; +#if !OS_SYSV /* SysV uses a different format than we do. */ + const char *pointer_fmt[] = { + "foo|%p|bar", + "%42p", + "%p", + NULL + }; + const char *pointer_val[] = { + *pointer_fmt, + *string_fmt, + *string_val, + NULL + }; +#endif /* !OS_SYSV */ + char buf1[1024], buf2[1024]; + double value, digits = 9.123456789012345678901234567890123456789; + int i, j, r1, r2, failed = 0, num = 0; + +/* + * Use -DTEST_NILS in order to also test the conversion of nil values. Might + * segfault on systems which don't support converting a NULL pointer with "%s" + * and lets some test cases fail against BSD and glibc due to bugs in their + * implementations. + */ +#ifndef TEST_NILS +#define TEST_NILS 0 +#elif TEST_NILS +#undef TEST_NILS +#define TEST_NILS 1 +#endif /* !defined(TEST_NILS) */ +#ifdef TEST +#undef TEST +#endif /* defined(TEST) */ +#define TEST(fmt, val) \ +do { \ + for (i = 0; fmt[i] != NULL; i++) \ + for (j = 0; j == 0 || val[j - TEST_NILS] != 0; j++) { \ + r1 = sprintf(buf1, fmt[i], val[j]); \ + r2 = snprintf(buf2, sizeof(buf2), fmt[i], val[j]); \ + if (strcmp(buf1, buf2) != 0 || r1 != r2) { \ + (void)printf("Results don't match, " \ + "format string: %s\n" \ + "\t sprintf(3): [%s] (%d)\n" \ + "\tsnprintf(3): [%s] (%d)\n", \ + fmt[i], buf1, r1, buf2, r2); \ + failed++; \ + } \ + num++; \ + } \ +} while (/* CONSTCOND */ 0) + +#if HAVE_LOCALE_H + (void)setlocale(LC_ALL, ""); +#endif /* HAVE_LOCALE_H */ + + (void)puts("Testing our snprintf(3) against your system's sprintf(3)."); + TEST(float_fmt, float_val); + TEST(long_fmt, long_val); + TEST(ulong_fmt, ulong_val); + TEST(llong_fmt, llong_val); + TEST(string_fmt, string_val); +#if !OS_SYSV /* SysV uses a different format than we do. */ + TEST(pointer_fmt, pointer_val); +#endif /* !OS_SYSV */ + (void)printf("Result: %d out of %d tests failed.\n", failed, num); + + (void)fputs("Checking how many digits we support: ", stdout); + for (i = 0; i < 100; i++) { + value = pow(10, i) * digits; + (void)sprintf(buf1, "%.1f", value); + (void)snprintf(buf2, sizeof(buf2), "%.1f", value); + if (strcmp(buf1, buf2) != 0) { + (void)printf("apparently %d.\n", i); + break; + } + } + return (failed == 0) ? 0 : 1; } -#else -int snprintf_bs; -#endif +#endif /* TEST_SNPRINTF */ + +/* vim: set joinspaces textwidth=80: */ diff --git a/libntp/socket.c b/libntp/socket.c new file mode 100644 index 0000000000000..de678c6340b4c --- /dev/null +++ b/libntp/socket.c @@ -0,0 +1,218 @@ +/* + * socket.c - low-level socket operations + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> + +#include "ntp.h" +#include "ntp_io.h" +#include "ntp_net.h" +#include "ntp_debug.h" + +/* + * Windows C runtime ioctl() can't deal properly with sockets, + * map to ioctlsocket for this source file. + */ +#ifdef SYS_WINNT +#define ioctl(fd, opt, val) ioctlsocket(fd, opt, (u_long *)(val)) +#endif + +/* + * on Unix systems the stdio library typically + * makes use of file descriptors in the lower + * integer range. stdio usually will make use + * of the file descriptors in the range of + * [0..FOPEN_MAX) + * in order to keep this range clean, for socket + * file descriptors we attempt to move them above + * FOPEN_MAX. This is not as easy as it sounds as + * FOPEN_MAX changes from implementation to implementation + * and may exceed to current file decriptor limits. + * We are using following strategy: + * - keep a current socket fd boundary initialized with + * max(0, min(GETDTABLESIZE() - FD_CHUNK, FOPEN_MAX)) + * - attempt to move the descriptor to the boundary or + * above. + * - if that fails and boundary > 0 set boundary + * to min(0, socket_fd_boundary - FD_CHUNK) + * -> retry + * if failure and boundary == 0 return old fd + * - on success close old fd return new fd + * + * effects: + * - fds will be moved above the socket fd boundary + * if at all possible. + * - the socket boundary will be reduced until + * allocation is possible or 0 is reached - at this + * point the algrithm will be disabled + */ +SOCKET +move_fd( + SOCKET fd + ) +{ +#if !defined(SYS_WINNT) && defined(F_DUPFD) +#ifndef FD_CHUNK +#define FD_CHUNK 10 +#endif +#ifndef FOPEN_MAX +#define FOPEN_MAX 20 +#endif +/* + * number of fds we would like to have for + * stdio FILE* available. + * we can pick a "low" number as our use of + * FILE* is limited to log files and temporarily + * to data and config files. Except for log files + * we don't keep the other FILE* open beyond the + * scope of the function that opened it. + */ +#ifndef FD_PREFERRED_SOCKBOUNDARY +#define FD_PREFERRED_SOCKBOUNDARY 48 +#endif + + static SOCKET socket_boundary = -1; + SOCKET newfd; + + NTP_REQUIRE((int)fd >= 0); + + /* + * check whether boundary has be set up + * already + */ + if (socket_boundary == -1) { + socket_boundary = max(0, min(GETDTABLESIZE() - FD_CHUNK, + min(FOPEN_MAX, FD_PREFERRED_SOCKBOUNDARY))); + TRACE(1, ("move_fd: estimated max descriptors: %d, " + "initial socket boundary: %d\n", + GETDTABLESIZE(), socket_boundary)); + } + + /* + * Leave a space for stdio to work in. potentially moving the + * socket_boundary lower until allocation succeeds. + */ + do { + if (fd >= 0 && fd < socket_boundary) { + /* inside reserved range: attempt to move fd */ + newfd = fcntl(fd, F_DUPFD, socket_boundary); + + if (newfd != -1) { + /* success: drop the old one - return the new one */ + close(fd); + return newfd; + } + } else { + /* outside reserved range: no work - return the original one */ + return fd; + } + socket_boundary = max(0, socket_boundary - FD_CHUNK); + TRACE(1, ("move_fd: selecting new socket boundary: %d\n", + socket_boundary)); + } while (socket_boundary > 0); +#else + NTP_REQUIRE((int)fd >= 0); +#endif /* !defined(SYS_WINNT) && defined(F_DUPFD) */ + return fd; +} + + +/* + * make_socket_nonblocking() - set up descriptor to be non blocking + */ +void +make_socket_nonblocking( + SOCKET fd + ) +{ + /* + * set non-blocking, + */ + +#ifdef USE_FIONBIO + /* in vxWorks we use FIONBIO, but the others are defined for old + * systems, so all hell breaks loose if we leave them defined + */ +#undef O_NONBLOCK +#undef FNDELAY +#undef O_NDELAY +#endif + +#if defined(O_NONBLOCK) /* POSIX */ + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + msyslog(LOG_ERR, + "fcntl(O_NONBLOCK) fails on fd #%d: %m", fd); + exit(1); + } +#elif defined(FNDELAY) + if (fcntl(fd, F_SETFL, FNDELAY) < 0) { + msyslog(LOG_ERR, "fcntl(FNDELAY) fails on fd #%d: %m", + fd); + exit(1); + } +#elif defined(O_NDELAY) /* generally the same as FNDELAY */ + if (fcntl(fd, F_SETFL, O_NDELAY) < 0) { + msyslog(LOG_ERR, "fcntl(O_NDELAY) fails on fd #%d: %m", + fd); + exit(1); + } +#elif defined(FIONBIO) + { + int on = 1; + + if (ioctl(fd, FIONBIO, &on) < 0) { + msyslog(LOG_ERR, + "ioctl(FIONBIO) fails on fd #%d: %m", + fd); + exit(1); + } + } +#elif defined(FIOSNBIO) + if (ioctl(fd, FIOSNBIO, &on) < 0) { + msyslog(LOG_ERR, + "ioctl(FIOSNBIO) fails on fd #%d: %m", fd); + exit(1); + } +#else +# include "Bletch: Need non-blocking I/O!" +#endif +} + +#if 0 + +/* The following subroutines should probably be moved here */ + +static SOCKET +open_socket( + sockaddr_u * addr, + int bcast, + int turn_off_reuse, + endpt * interf + ) +void +sendpkt( + sockaddr_u * dest, + struct interface * ep, + int ttl, + struct pkt * pkt, + int len + ) + +static inline int +read_refclock_packet(SOCKET fd, struct refclockio *rp, l_fp ts) + +static inline int +read_network_packet( + SOCKET fd, + struct interface * itf, + l_fp ts + ) + +void +kill_asyncio(int startfd) + +#endif /* 0 */ diff --git a/libntp/socktoa.c b/libntp/socktoa.c index 62e4537266f0f..98abe7c420360 100644 --- a/libntp/socktoa.c +++ b/libntp/socktoa.c @@ -1,5 +1,5 @@ /* - * socktoa - return a numeric host name from a sockaddr_storage structure + * socktoa.c socktoa(), sockporttoa(), and sock_hash() */ #ifdef HAVE_CONFIG_H @@ -14,49 +14,157 @@ #include <netinet/in.h> #endif -#include <arpa/inet.h> - -#ifdef ISC_PLATFORM_NEEDNTOP -#include <isc/net.h> -#endif - #include <stdio.h> +#include <arpa/inet.h> +#include <isc/result.h> +#include <isc/netaddr.h> +#include <isc/sockaddr.h> #include "ntp_fp.h" #include "lib_strbuf.h" #include "ntp_stdlib.h" #include "ntp.h" -char * +/* + * socktoa - return a numeric host name from a sockaddr_storage structure + */ +const char * socktoa( const sockaddr_u *sock ) { - register char *buffer; + int saved_errno; + char * res; + char * addr; + u_long scope; - LIB_GETBUF(buffer); + saved_errno = socket_errno(); + LIB_GETBUF(res); - if (NULL == sock) - strncpy(buffer, "(null)", LIB_BUFLENGTH); - else { + if (NULL == sock) { + strlcpy(res, "(null)", LIB_BUFLENGTH); + } else { switch(AF(sock)) { case AF_INET: case AF_UNSPEC: - inet_ntop(AF_INET, PSOCK_ADDR4(sock), buffer, + inet_ntop(AF_INET, PSOCK_ADDR4(sock), res, LIB_BUFLENGTH); break; case AF_INET6: - inet_ntop(AF_INET6, PSOCK_ADDR6(sock), buffer, + inet_ntop(AF_INET6, PSOCK_ADDR6(sock), res, LIB_BUFLENGTH); + scope = SCOPE_VAR(sock); + if (0 != scope && !strchr(res, '%')) { + addr = res; + LIB_GETBUF(res); + snprintf(res, LIB_BUFLENGTH, "%s%%%lu", + addr, scope); + res[LIB_BUFLENGTH - 1] = '\0'; + } break; default: - snprintf(buffer, LIB_BUFLENGTH, + snprintf(res, LIB_BUFLENGTH, "(socktoa unknown family %d)", AF(sock)); } } - return buffer; + errno = saved_errno; + + return res; +} + + +const char * +sockporttoa( + const sockaddr_u *sock + ) +{ + int saved_errno; + const char * atext; + char * buf; + + saved_errno = socket_errno(); + atext = socktoa(sock); + LIB_GETBUF(buf); + snprintf(buf, LIB_BUFLENGTH, + (IS_IPV6(sock)) + ? "[%s]:%hu" + : "%s:%hu", + atext, SRCPORT(sock)); + errno = saved_errno; + + return buf; +} + + +/* + * sock_hash - hash a sockaddr_u structure + */ +u_short +sock_hash( + const sockaddr_u *addr + ) +{ + u_int hashVal; + u_int j; + size_t len; + const u_char *pch; + + hashVal = 0; + len = 0; + + /* + * We can't just hash the whole thing because there are hidden + * fields in sockaddr_in6 that might be filled in by recvfrom(), + * so just use the family, port and address. + */ + pch = (const void *)&AF(addr); + hashVal = 37 * hashVal + *pch; + if (sizeof(AF(addr)) > 1) { + pch++; + hashVal = 37 * hashVal + *pch; + } + switch(AF(addr)) { + case AF_INET: + pch = (const void *)&SOCK_ADDR4(addr); + len = sizeof(SOCK_ADDR4(addr)); + break; + + case AF_INET6: + pch = (const void *)&SOCK_ADDR6(addr); + len = sizeof(SOCK_ADDR6(addr)); + break; + } + + for (j = 0; j < len ; j++) + hashVal = 37 * hashVal + pch[j]; + + return (u_short)(hashVal & USHRT_MAX); +} + + +int +sockaddr_masktoprefixlen( + const sockaddr_u * psa + ) +{ + isc_netaddr_t isc_na; + isc_sockaddr_t isc_sa; + u_int pfxlen; + isc_result_t result; + int rc; + + ZERO(isc_sa); + memcpy(&isc_sa.type, psa, + min(sizeof(isc_sa.type), sizeof(*psa))); + isc_netaddr_fromsockaddr(&isc_na, &isc_sa); + result = isc_netaddr_masktoprefixlen(&isc_na, &pfxlen); + rc = (ISC_R_SUCCESS == result) + ? (int)pfxlen + : -1; + + return rc; } diff --git a/libntp/socktohost.c b/libntp/socktohost.c index 05bbdd64344cd..c61e57148a658 100644 --- a/libntp/socktohost.c +++ b/libntp/socktohost.c @@ -1,6 +1,7 @@ /* * socktoa - return a numeric host name from a sockaddr_storage structure */ +#include <config.h> #include <sys/types.h> #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> @@ -17,19 +18,93 @@ #include "lib_strbuf.h" #include "ntp_stdlib.h" #include "ntp.h" +#include "ntp_debug.h" -char * +const char * socktohost( const sockaddr_u *sock ) { - register char *buffer; + const char svc[] = "ntp"; + char * pbuf; + char * pliar; + int gni_flags; + struct addrinfo hints; + struct addrinfo * alist; + struct addrinfo * ai; + sockaddr_u addr; + size_t octets; + int a_info; - LIB_GETBUF(buffer); - if (getnameinfo(&sock->sa, SOCKLEN(sock), buffer, - LIB_BUFLENGTH, NULL, 0, 0)) - return stoa(sock); + /* reverse the address to purported DNS name */ + LIB_GETBUF(pbuf); + gni_flags = NI_DGRAM | NI_NAMEREQD; + if (getnameinfo(&sock->sa, SOCKLEN(sock), pbuf, LIB_BUFLENGTH, + NULL, 0, gni_flags)) + return stoa(sock); /* use address */ - return buffer; + TRACE(1, ("%s reversed to %s\n", stoa(sock), pbuf)); + + /* + * Resolve the reversed name and make sure the reversed address + * is among the results. + */ + ZERO(hints); + hints.ai_family = AF(sock); + hints.ai_protocol = IPPROTO_UDP; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = 0; + alist = NULL; + + a_info = getaddrinfo(pbuf, svc, &hints, &alist); + if (a_info == EAI_NONAME +#ifdef EAI_NODATA + || a_info == EAI_NODATA +#endif + ) { + hints.ai_flags = AI_CANONNAME; +#ifdef AI_ADDRCONFIG + hints.ai_flags |= AI_ADDRCONFIG; +#endif + a_info = getaddrinfo(pbuf, svc, &hints, &alist); + } +#ifdef AI_ADDRCONFIG + /* Some older implementations don't like AI_ADDRCONFIG. */ + if (a_info == EAI_BADFLAGS) { + hints.ai_flags &= ~AI_ADDRCONFIG; + a_info = getaddrinfo(pbuf, svc, &hints, &alist); + } +#endif + if (a_info) + goto forward_fail; + + NTP_INSIST(alist != NULL); + + for (ai = alist; ai != NULL; ai = ai->ai_next) { + /* + * Make a convenience sockaddr_u copy from ai->ai_addr + * because casting from sockaddr * to sockaddr_u * is + * risking alignment problems on platforms where + * sockaddr_u has stricter alignment than sockaddr, + * such as sparc. + */ + ZERO_SOCK(&addr); + octets = min(sizeof(addr), ai->ai_addrlen); + memcpy(&addr, ai->ai_addr, octets); + if (SOCK_EQ(sock, &addr)) + break; + } + freeaddrinfo(alist); + + if (ai != NULL) + return pbuf; /* forward check passed */ + + forward_fail: + 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); + + return pliar; } diff --git a/libntp/ssl_init.c b/libntp/ssl_init.c index 9e11e5f2cc617..7f1e9a096b209 100644 --- a/libntp/ssl_init.c +++ b/libntp/ssl_init.c @@ -16,19 +16,35 @@ #include "openssl/err.h" #include "openssl/evp.h" +void atexit_ssl_cleanup(void); int ssl_init_done; void ssl_init(void) { + init_lib(); + if (ssl_init_done) return; ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); + atexit(&atexit_ssl_cleanup); - ssl_init_done = 1; + ssl_init_done = TRUE; +} + + +void +atexit_ssl_cleanup(void) +{ + if (!ssl_init_done) + return; + + ssl_init_done = FALSE; + EVP_cleanup(); + ERR_free_strings(); } @@ -38,10 +54,10 @@ ssl_check_version(void) if ((SSLeay() ^ OPENSSL_VERSION_NUMBER) & ~0xff0L) { msyslog(LOG_WARNING, "OpenSSL version mismatch. Built against %lx, you have %lx", - OPENSSL_VERSION_NUMBER, SSLeay()); + (u_long)OPENSSL_VERSION_NUMBER, SSLeay()); fprintf(stderr, "OpenSSL version mismatch. Built against %lx, you have %lx\n", - OPENSSL_VERSION_NUMBER, SSLeay()); + (u_long)OPENSSL_VERSION_NUMBER, SSLeay()); } INIT_SSL(); @@ -61,10 +77,10 @@ keytype_from_text( size_t *pdigest_len ) { - const u_long max_digest_len = MAX_MAC_LEN - sizeof(keyid_t); int key_type; u_int digest_len; #ifdef OPENSSL + const u_long max_digest_len = MAX_MAC_LEN - sizeof(keyid_t); u_char digest[EVP_MAX_MD_SIZE]; char * upcased; char * pch; @@ -78,7 +94,7 @@ keytype_from_text( */ INIT_SSL(); LIB_GETBUF(upcased); - strncpy(upcased, text, LIB_BUFLENGTH); + strlcpy(upcased, text, LIB_BUFLENGTH); for (pch = upcased; '\0' != *pch; pch++) *pch = (char)toupper(*pch); key_type = OBJ_sn2nid(upcased); @@ -96,13 +112,13 @@ keytype_from_text( #ifdef OPENSSL EVP_DigestInit(&ctx, EVP_get_digestbynid(key_type)); EVP_DigestFinal(&ctx, digest, &digest_len); - if (digest_len + sizeof(keyid_t) > MAX_MAC_LEN) { + if (digest_len > max_digest_len) { fprintf(stderr, "key type %s %u octet digests are too big, max %lu\n", keytype_name(key_type), digest_len, max_digest_len); msyslog(LOG_ERR, - "key type %s %u octet digests are too big, max %lu\n", + "key type %s %u octet digests are too big, max %lu", keytype_name(key_type), digest_len, max_digest_len); return 0; diff --git a/libntp/statestr.c b/libntp/statestr.c index a143fcd3fc9c4..cd98eb3951a33 100644 --- a/libntp/statestr.c +++ b/libntp/statestr.c @@ -12,20 +12,23 @@ #include "ntp_refclock.h" #include "ntp_control.h" #include "ntp_string.h" +#ifdef KERNEL_PLL +# include "ntp_syscall.h" +#endif + /* * Structure for turning various constants into a readable string. */ struct codestring { int code; - const char *string; + const char * const string; }; /* * Leap status (leap) */ -static -struct codestring leap_codes[] = { +static const struct codestring leap_codes[] = { { LEAP_NOWARNING, "leap_none" }, { LEAP_ADDSECOND, "leap_add_sec" }, { LEAP_DELSECOND, "leap_del_sec" }, @@ -36,8 +39,7 @@ struct codestring leap_codes[] = { /* * Clock source status (sync) */ -static -struct codestring sync_codes[] = { +static const struct codestring sync_codes[] = { { CTL_SST_TS_UNSPEC, "sync_unspec" }, { CTL_SST_TS_ATOM, "sync_pps" }, { CTL_SST_TS_LF, "sync_lf_radio" }, @@ -54,8 +56,7 @@ struct codestring sync_codes[] = { /* * Peer selection status (sel) */ -static -struct codestring select_codes[] = { +static const struct codestring select_codes[] = { { CTL_PST_SEL_REJECT, "sel_reject" }, { CTL_PST_SEL_SANE, "sel_falsetick" }, { CTL_PST_SEL_CORRECT, "sel_excess" }, @@ -70,8 +71,7 @@ struct codestring select_codes[] = { /* * Clock status (clk) */ -static -struct codestring clock_codes[] = { +static const struct codestring clock_codes[] = { { CTL_CLK_OKAY, "clk_unspec" }, { CTL_CLK_NOREPLY, "clk_no_reply" }, { CTL_CLK_BADFORMAT, "clk_bad_format" }, @@ -87,8 +87,7 @@ struct codestring clock_codes[] = { /* * Flash bits -- see ntpq.c tstflags & tstflagnames */ -static -struct codestring flash_codes[] = { +static const struct codestring flash_codes[] = { { TEST1, "pkt_dup" }, { TEST2, "pkt_bogus" }, { TEST3, "pkt_unsync" }, @@ -110,8 +109,7 @@ struct codestring flash_codes[] = { /* * System events (sys) */ -static -struct codestring sys_codes[] = { +static const struct codestring sys_codes[] = { { EVNT_UNSPEC, "unspecified" }, { EVNT_NSET, "freq_not_set" }, { EVNT_FSET, "freq_set" }, @@ -128,15 +126,13 @@ struct codestring sys_codes[] = { { EVNT_KERN, "kern" }, { EVNT_TAI, "TAI" }, { EVNT_LEAPVAL, "stale_leapsecond_values" }, - { EVNT_CLKHOP, "clockhop" }, { -1, "" } }; /* * Peer events (peer) */ -static -struct codestring peer_codes[] = { +static const struct codestring peer_codes[] = { { PEVNT_MOBIL & ~PEER_EVENT, "mobilize" }, { PEVNT_DEMOBIL & ~PEER_EVENT, "demobilize" }, { PEVNT_UNREACH & ~PEER_EVENT, "unreachable" }, @@ -152,16 +148,55 @@ struct codestring peer_codes[] = { { PEVNT_POPCORN & ~PEER_EVENT, "popcorn" }, { PEVNT_XLEAVE & ~PEER_EVENT, "interleave_mode" }, { PEVNT_XERR & ~PEER_EVENT, "interleave_error" }, - { PEVNT_TAI & ~PEER_EVENT, "TAI" }, { -1, "" } }; -#ifdef OPENSSL +/* + * Peer status bits + */ +static const struct codestring peer_st_bits[] = { + { CTL_PST_CONFIG, "conf" }, + { CTL_PST_AUTHENABLE, "authenb" }, + { CTL_PST_AUTHENTIC, "auth" }, + { CTL_PST_REACH, "reach" }, + { CTL_PST_BCAST, "bcast" }, + /* not used with getcode(), no terminating entry needed */ +}; + +/* + * Restriction match bits + */ +static const struct codestring res_match_bits[] = { + { RESM_NTPONLY, "ntpport" }, + { RESM_INTERFACE, "interface" }, + { RESM_SOURCE, "source" }, + /* not used with getcode(), no terminating entry needed */ +}; + +/* + * Restriction access bits + */ +static const struct codestring res_access_bits[] = { + { RES_IGNORE, "ignore" }, + { RES_DONTSERVE, "noserve" }, + { RES_DONTTRUST, "notrust" }, + { RES_NOQUERY, "noquery" }, + { RES_NOMODIFY, "nomodify" }, + { RES_NOPEER, "nopeer" }, + { RES_NOTRAP, "notrap" }, + { RES_LPTRAP, "lptrap" }, + { RES_LIMITED, "limited" }, + { RES_VERSION, "version" }, + { RES_KOD, "kod" }, + { RES_FLAKE, "flake" }, + /* not used with getcode(), no terminating entry needed */ +}; + +#ifdef AUTOKEY /* * Crypto events (cryp) */ -static -struct codestring crypto_codes[] = { +static const struct codestring crypto_codes[] = { { XEVNT_OK & ~CRPT_EVENT, "success" }, { XEVNT_LEN & ~CRPT_EVENT, "bad_field_format_or_length" }, { XEVNT_TSP & ~CRPT_EVENT, "bad_timestamp" }, @@ -180,29 +215,90 @@ struct codestring crypto_codes[] = { { XEVNT_ERR & ~CRPT_EVENT, "protocol_error" }, { -1, "" } }; -#endif /* OPENSSL */ +#endif /* AUTOKEY */ + +#ifdef KERNEL_PLL +/* + * kernel discipline status bits + */ +static const struct codestring k_st_bits[] = { +# ifdef STA_PLL + { STA_PLL, "pll" }, +# endif +# ifdef STA_PPSFREQ + { STA_PPSFREQ, "ppsfreq" }, +# endif +# ifdef STA_PPSTIME + { STA_PPSTIME, "ppstime" }, +# endif +# ifdef STA_FLL + { STA_FLL, "fll" }, +# endif +# ifdef STA_INS + { STA_INS, "ins" }, +# endif +# ifdef STA_DEL + { STA_DEL, "del" }, +# endif +# ifdef STA_UNSYNC + { STA_UNSYNC, "unsync" }, +# endif +# ifdef STA_FREQHOLD + { STA_FREQHOLD, "freqhold" }, +# endif +# ifdef STA_PPSSIGNAL + { STA_PPSSIGNAL, "ppssignal" }, +# endif +# ifdef STA_PPSJITTER + { STA_PPSJITTER, "ppsjitter" }, +# endif +# ifdef STA_PPSWANDER + { STA_PPSWANDER, "ppswander" }, +# endif +# ifdef STA_PPSERROR + { STA_PPSERROR, "ppserror" }, +# endif +# ifdef STA_CLOCKERR + { STA_CLOCKERR, "clockerr" }, +# endif +# ifdef STA_NANO + { STA_NANO, "nano" }, +# endif +# ifdef STA_MODE + { STA_MODE, "mode=fll" }, +# endif +# ifdef STA_CLK + { STA_CLK, "src=B" }, +# endif + /* not used with getcode(), no terminating entry needed */ +}; +#endif /* KERNEL_PLL */ /* Forwards */ -static const char *getcode (int, struct codestring *); -static const char *getevents (int); +static const char * getcode(int, const struct codestring *); +static const char * getevents(int); +static const char * peer_st_flags(u_char pst); /* * getcode - return string corresponding to code */ static const char * getcode( - int code, - struct codestring *codetab + int code, + const struct codestring * codetab ) { - static char buf[30]; + char * buf; while (codetab->code != -1) { if (codetab->code == code) return codetab->string; codetab++; } - snprintf(buf, sizeof(buf), "%s_%d", codetab->string, code); + + LIB_GETBUF(buf); + snprintf(buf, LIB_BUFLENGTH, "%s_%d", codetab->string, code); + return buf; } @@ -214,14 +310,123 @@ getevents( int cnt ) { - static char buf[20]; + char * buf; if (cnt == 0) return "no events"; - snprintf(buf, sizeof(buf), "%d event%s", cnt, (cnt==1) ? "" : - "s"); + + LIB_GETBUF(buf); + snprintf(buf, LIB_BUFLENGTH, "%d event%s", cnt, + (1 == cnt) + ? "" + : "s"); + + return buf; +} + + +/* + * decode_bitflags() + * + * returns a human-readable string with a keyword from tab for each bit + * set in bits, separating multiple entries with text of sep2. + */ +static const char * +decode_bitflags( + int bits, + const char * sep2, + const struct codestring * tab, + size_t tab_ct + ) +{ + const char * sep; + char * buf; + char * pch; + char * lim; + size_t b; + int rc; + int saved_errno; /* for use in DPRINTF with %m */ + + saved_errno = errno; + LIB_GETBUF(buf); + pch = buf; + lim = buf + LIB_BUFLENGTH; + sep = ""; + + for (b = 0; b < tab_ct; b++) { + if (tab[b].code & bits) { + rc = snprintf(pch, (lim - pch), "%s%s", sep, + tab[b].string); + if (rc < 0) + goto toosmall; + pch += (u_int)rc; + if (pch >= lim) + goto toosmall; + sep = sep2; + } + } + return buf; + + toosmall: + snprintf(buf, LIB_BUFLENGTH, + "decode_bitflags(%s) can't decode 0x%x in %d bytes", + (tab == peer_st_bits) + ? "peer_st" + : +#ifdef KERNEL_PLL + (tab == k_st_bits) + ? "kern_st" + : +#endif + "", + bits, (int)LIB_BUFLENGTH); + errno = saved_errno; + + return buf; +} + + +static const char * +peer_st_flags( + u_char pst + ) +{ + return decode_bitflags(pst, ", ", peer_st_bits, + COUNTOF(peer_st_bits)); +} + + +const char * +res_match_flags( + u_short mf + ) +{ + return decode_bitflags(mf, " ", res_match_bits, + COUNTOF(res_match_bits)); +} + + +const char * +res_access_flags( + u_short af + ) +{ + return decode_bitflags(af, " ", res_access_bits, + COUNTOF(res_access_bits)); +} + + +#ifdef KERNEL_PLL +const char * +k_st_flags( + u_int32 st + ) +{ + return decode_bitflags(st, " ", k_st_bits, COUNTOF(k_st_bits)); } +#endif /* KERNEL_PLL */ + /* * statustoa - return a descriptive string for a peer status @@ -232,78 +437,43 @@ statustoa( int st ) { - char *cb; - u_char pst; + char * cb; + char * cc; + u_char pst; LIB_GETBUF(cb); switch (type) { - case TYPE_SYS: - strcpy(cb, getcode(CTL_SYS_LI(st), leap_codes)); - strcat(cb, ", "); - strcat(cb, getcode(CTL_SYS_SOURCE(st), sync_codes)); - strcat(cb, ", "); - strcat(cb, getevents(CTL_SYS_NEVNT(st))); - strcat(cb, ", "); - strcat(cb, getcode(CTL_SYS_EVENT(st), sys_codes)); + + case TYPE_SYS: + snprintf(cb, LIB_BUFLENGTH, "%s, %s, %s, %s", + getcode(CTL_SYS_LI(st), leap_codes), + getcode(CTL_SYS_SOURCE(st), sync_codes), + getevents(CTL_SYS_NEVNT(st)), + getcode(CTL_SYS_EVENT(st), sys_codes)); break; - case TYPE_PEER: - - /* - * Handcraft the bits - */ - pst = (u_char) CTL_PEER_STATVAL(st); - if (pst & CTL_PST_CONFIG) - strcpy(cb, "conf"); - if (pst & CTL_PST_AUTHENABLE) { - if (pst & CTL_PST_CONFIG) - strcat(cb, ", authenb"); - else - strcat(cb, "authenb"); - } - if (pst & CTL_PST_AUTHENTIC) { - if (pst & (CTL_PST_CONFIG | CTL_PST_AUTHENABLE)) - strcat(cb, ", auth"); - else - strcat(cb, "auth"); - } - if (pst & CTL_PST_REACH) { - if (pst & (CTL_PST_CONFIG | CTL_PST_AUTHENABLE | - CTL_PST_AUTHENTIC)) - strcat(cb, ", reach"); - else - strcat(cb, "reach"); - } - if (pst & CTL_PST_BCAST) { - if (pst & (CTL_PST_CONFIG | CTL_PST_AUTHENABLE | - CTL_PST_AUTHENTIC | CTL_PST_REACH)) - strcat(cb, ", bcst"); - else - strcat(cb, "bcst"); - } - - /* - * Now the codes - */ - strcat(cb, ", "); - strcat(cb, getcode(pst & 0x7, select_codes)); - strcat(cb, ", "); - strcat(cb, getevents(CTL_PEER_NEVNT(st))); + case TYPE_PEER: + pst = (u_char)CTL_PEER_STATVAL(st); + snprintf(cb, LIB_BUFLENGTH, "%s, %s, %s", + peer_st_flags(pst), + getcode(pst & 0x7, select_codes), + getevents(CTL_PEER_NEVNT(st))); if (CTL_PEER_EVENT(st) != EVNT_UNSPEC) { - strcat(cb, ", "); - strcat(cb, getcode(CTL_PEER_EVENT(st), - peer_codes)); + cc = cb + strlen(cb); + snprintf(cc, LIB_BUFLENGTH - (cc - cb), ", %s", + getcode(CTL_PEER_EVENT(st), + peer_codes)); } break; - case TYPE_CLOCK: - strcat(cb, ", "); - strcat(cb, getevents(CTL_SYS_NEVNT(st))); - strcat(cb, ", "); - strcat(cb, getcode((st) & 0xf, clock_codes)); + case TYPE_CLOCK: + snprintf(cb, LIB_BUFLENGTH, "%s, %s", + getevents(CTL_SYS_NEVNT(st)), + getcode((st) & 0xf, clock_codes)); break; } + return cb; } @@ -314,10 +484,10 @@ eventstr( { if (num & PEER_EVENT) return (getcode(num & ~PEER_EVENT, peer_codes)); -#ifdef OPENSSL +#ifdef AUTOKEY else if (num & CRPT_EVENT) return (getcode(num & ~CRPT_EVENT, crypto_codes)); -#endif /* OPENSSL */ +#endif /* AUTOKEY */ else return (getcode(num, sys_codes)); } diff --git a/libntp/strl_obsd.c b/libntp/strl_obsd.c new file mode 100644 index 0000000000000..cb8d4f35981f6 --- /dev/null +++ b/libntp/strl_obsd.c @@ -0,0 +1,123 @@ +/* + * Why use strlcpy()/strlcat() instead of standard strncpy()/strncat()? + * To reduce likelihood of bugs and avoid wasteful zero fills. See: + * http://www.gratisoft.us/todd/papers/strlcpy.html + */ + +/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. + */ + +#include <config.h> /* + marks local changes */ +#ifdef HAVE_SYS_TYPES_H /* + */ +#include <sys/types.h> +#endif /* + */ +#include <string.h> + +#include "ntp_stdlib.h" /* + strlcpy, strlcat prototypes */ + +#ifndef HAVE_STRLCPY /* + */ +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} +#endif /* + */ + + +/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * + * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. + */ + +/* #include <sys/types.h> */ /* + */ +/* #include <string.h> */ /* + */ + +#ifndef HAVE_STRLCAT /* + */ +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} +#endif /* + */ diff --git a/libntp/strstr.c b/libntp/strstr.c deleted file mode 100644 index a4deb8701d6cc..0000000000000 --- a/libntp/strstr.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <config.h> - -#if !HAVE_STRSTR - -/* - * Amanda, The Advanced Maryland Automatic Network Disk Archiver - * Copyright (c) 1991-1998 University of Maryland at College Park - * All Rights Reserved. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of U.M. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. U.M. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. - * BE LIABLE FOR ANY SPECIAL, 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. - * - * Author: James da Silva, Systems Design and Analysis Group - * Computer Science Department - * University of Maryland at College Park - */ -/* - * $Id$ - * - * replacement for missing ANSI-C strstr function - */ - -char *strstr(a, b) -char *a, *b; -{ - int alen, blen, i; - - alen = strlen(a); - blen = strlen(b); - - for(i=0; i <= alen-blen; i++, a++) - if(strncmp(a, b, blen) == 0) return a; - - return NULL; -} -#else -int strstr_bs; -#endif diff --git a/libntp/syssignal.c b/libntp/syssignal.c index 68099f5fb3f26..5e496a95f26db 100644 --- a/libntp/syssignal.c +++ b/libntp/syssignal.c @@ -9,64 +9,50 @@ #include "ntp_syslog.h" #include "ntp_stdlib.h" +static ctrl_c_fn ctrl_c_hook; +#ifndef SYS_WINNT +RETSIGTYPE sigint_handler(int); +#else +BOOL WINAPI console_event_handler(DWORD); +#endif + + #ifdef HAVE_SIGACTION +# ifdef SA_RESTART +# define Z_SA_RESTART SA_RESTART +# else +# define Z_SA_RESTART 0 +# endif + void signal_no_reset( -#if defined(__STDC__) || defined(HAVE_STDARG_H) int sig, - void (*func) (int) -#else - sig, func -#endif + void (*func)(int) ) -#if defined(__STDC__) || defined(HAVE_STDARG_H) -#else - int sig; - void (*func) (int); -#endif { int n; struct sigaction vec; + struct sigaction ovec; - vec.sa_handler = func; + ZERO(vec); sigemptyset(&vec.sa_mask); -#if 0 -#ifdef SA_RESTART - vec.sa_flags = SA_RESTART; -#else - vec.sa_flags = 0; -#endif -#else - vec.sa_flags = 0; -#endif + vec.sa_handler = func; -#ifdef SA_RESTART -/* Added for PPS clocks on Solaris 7 which get EINTR errors */ + /* Added for PPS clocks on Solaris 7 which get EINTR errors */ # ifdef SIGPOLL - if (sig == SIGPOLL) vec.sa_flags = SA_RESTART; + if (SIGPOLL == sig) + vec.sa_flags = Z_SA_RESTART; # endif # ifdef SIGIO - if (sig == SIGIO) vec.sa_flags = SA_RESTART; + if (SIGIO == sig) + vec.sa_flags = Z_SA_RESTART; # endif -#endif - - while (1) - { - struct sigaction ovec; + do n = sigaction(sig, &vec, &ovec); - if (n == -1 && errno == EINTR) continue; - if (ovec.sa_flags -#ifdef SA_RESTART - && ovec.sa_flags != SA_RESTART -#endif - ) - msyslog(LOG_DEBUG, "signal_no_reset: signal %d had flags %x", - sig, ovec.sa_flags); - break; - } - if (n == -1) { + while (-1 == n && EINTR == errno); + if (-1 == n) { perror("sigaction"); exit(1); } @@ -77,16 +63,16 @@ signal_no_reset( void signal_no_reset( int sig, - RETSIGTYPE (*func) (int) + RETSIGTYPE (*func)(int) ) { struct sigvec sv; int n; - bzero((char *) &sv, sizeof(sv)); + ZERO(sv); sv.sv_handler = func; n = sigvec(sig, &sv, (struct sigvec *)NULL); - if (n == -1) { + if (-1 == n) { perror("sigvec"); exit(1); } @@ -97,13 +83,13 @@ signal_no_reset( void signal_no_reset( int sig, - RETSIGTYPE (*func) (int) + RETSIGTYPE (*func)(int) ) { int n; n = sigset(sig, func); - if (n == -1) { + if (-1 == n) { perror("sigset"); exit(1); } @@ -115,19 +101,88 @@ signal_no_reset( void signal_no_reset( int sig, - RETSIGTYPE (*func) (int) + RETSIGTYPE (*func)(int) ) { -#ifdef SIG_ERR - if (SIG_ERR == signal(sig, func)) { -#else - int n; - n = signal(sig, func); - if (n == -1) { +#ifndef SIG_ERR +# define SIG_ERR (-1) #endif + if (SIG_ERR == signal(sig, func)) { perror("signal"); exit(1); } } #endif + +#ifndef SYS_WINNT +/* + * POSIX implementation of set_ctrl_c_hook() + */ +RETSIGTYPE +sigint_handler( + int signum + ) +{ + UNUSED_ARG(signum); + if (ctrl_c_hook != NULL) + (*ctrl_c_hook)(); +} + +void +set_ctrl_c_hook( + ctrl_c_fn c_hook + ) +{ + RETSIGTYPE (*handler)(int); + + if (NULL == c_hook) { + handler = SIG_DFL; + ctrl_c_hook = NULL; + } else { + handler = &sigint_handler; + ctrl_c_hook = c_hook; + } + signal_no_reset(SIGINT, handler); +} +#else /* SYS_WINNT follows */ +/* + * Windows implementation of set_ctrl_c_hook() + */ +BOOL WINAPI +console_event_handler( + DWORD dwCtrlType + ) +{ + BOOL handled; + + if (CTRL_C_EVENT == dwCtrlType && ctrl_c_hook != NULL) { + (*ctrl_c_hook)(); + handled = TRUE; + } else { + handled = FALSE; + } + + return handled; +} +void +set_ctrl_c_hook( + ctrl_c_fn c_hook + ) +{ + BOOL install; + + if (NULL == c_hook) { + ctrl_c_hook = NULL; + install = FALSE; + } else { + ctrl_c_hook = c_hook; + install = TRUE; + } + if (!SetConsoleCtrlHandler(&console_event_handler, install)) + msyslog(LOG_ERR, "Can't %s console control handler: %m", + (install) + ? "add" + : "remove"); +} +#endif /* SYS_WINNT */ diff --git a/libntp/systime.c b/libntp/systime.c index 0dbf38968c727..f5eabcd1c9fdd 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -4,13 +4,16 @@ * ATTENTION: Get approval from Dave Mills on all changes to this file! * */ -#include "ntp_machine.h" -#include "ntp_fp.h" +#include <config.h> + +#include "ntp.h" #include "ntp_syslog.h" -#include "ntp_unixtime.h" #include "ntp_stdlib.h" #include "ntp_random.h" -#include "ntpd.h" /* for sys_precision */ +#include "iosignal.h" +#include "timevalops.h" +#include "timespecops.h" +#include "ntp_calendar.h" #ifdef HAVE_SYS_PARAM_H # include <sys/param.h> @@ -23,7 +26,9 @@ #endif /* HAVE_UTMPX_H */ -#define FUZZ 500e-6 /* fuzz pivot */ +#ifndef USE_COMPILETIME_PIVOT +# define USE_COMPILETIME_PIVOT 1 +#endif /* * These routines (get_systime, step_systime, adj_systime) implement an @@ -34,24 +39,121 @@ * residues. * * In order to improve the apparent resolution, provide unbiased - * rounding and insure that the readings cannot be predicted, the low- - * order unused portion of the time below the resolution limit is filled - * with an unbiased random fuzz. + * rounding and most importantly ensure that the readings cannot be + * predicted, the low-order unused portion of the time below the minimum + * time to read the clock is filled with an unbiased random fuzz. + * + * The sys_tick variable specifies the system clock tick interval in + * seconds, for stepping clocks, defined as those which return times + * less than MINSTEP greater than the previous reading. For systems that + * use a high-resolution counter such that each clock reading is always + * at least MINSTEP greater than the prior, sys_tick is the time to read + * the system clock. * - * The sys_tick variable secifies the system clock tick interval in - * seconds. For systems that can interpolate between timer interrupts, - * the resolution is presumed much less than the time to read the system - * clock, which is the value of sys_tick after the precision has been - * determined. For those systems that cannot interpolate between timer - * interrupts, sys_tick will be much larger in the order of 10 ms, so the - * fuzz should be that value. For Sunses the tick is not interpolated, but - * the system clock is derived from a 2-MHz oscillator, so the resolution - * is 500 ns and sys_tick is 500 ns. + * The sys_fuzz variable measures the minimum time to read the system + * clock, regardless of its precision. When reading the system clock + * using get_systime() after sys_tick and sys_fuzz have been determined, + * ntpd ensures each unprocessed clock reading is no less than sys_fuzz + * later than the prior unprocessed reading, and then fuzzes the bits + * below sys_fuzz in the timestamp returned, ensuring each of its + * resulting readings is strictly later than the previous. + * + * When slewing the system clock using adj_systime() (with the kernel + * loop discipline unavailable or disabled), adjtime() offsets are + * quantized to sys_tick, if sys_tick is greater than sys_fuzz, which + * is to say if the OS presents a stepping clock. Otherwise, offsets + * are quantized to the microsecond resolution of adjtime()'s timeval + * input. The remaining correction sys_residual is carried into the + * next adjtime() and meanwhile is also factored into get_systime() + * readings. */ -double sys_tick = 0; /* precision (time to read the clock) */ +double sys_tick = 0; /* tick size or time to read (s) */ +double sys_fuzz = 0; /* min. time to read the clock (s) */ +long sys_fuzz_nsec = 0; /* min. time to read the clock (ns) */ +double measured_tick; /* non-overridable sys_tick (s) */ double sys_residual = 0; /* adjustment residue (s) */ +int trunc_os_clock; /* sys_tick > measured_tick */ +time_stepped_callback step_callback; #ifndef SIM +/* perlinger@ntp.org: As 'get_sysime()' does it's own check for clock + * backstepping, this could probably become a local variable in + * 'get_systime()' and the cruft associated with communicating via a + * static value could be removed after the v4.2.8 release. + */ +static int lamport_violated; /* clock was stepped back */ +#endif /* !SIM */ + +#ifdef DEBUG +static int systime_init_done; +# define DONE_SYSTIME_INIT() systime_init_done = TRUE +#else +# define DONE_SYSTIME_INIT() do {} while (FALSE) +#endif + +#ifdef HAVE_SIGNALED_IO +int using_sigio; +#endif + +#ifdef SYS_WINNT +CRITICAL_SECTION get_systime_cs; +#endif + + +void +set_sys_fuzz( + double fuzz_val + ) +{ + sys_fuzz = fuzz_val; + INSIST(sys_fuzz >= 0); + INSIST(sys_fuzz <= 1.0); + sys_fuzz_nsec = (long)(sys_fuzz * 1e9 + 0.5); +} + + +void +init_systime(void) +{ + INIT_GET_SYSTIME_CRITSEC(); + INIT_WIN_PRECISE_TIME(); + DONE_SYSTIME_INIT(); +} + + +#ifndef SIM /* ntpsim.c has get_systime() and friends for sim */ + +static inline void +get_ostime( + struct timespec * tsp + ) +{ + int rc; + long ticks; + +#if defined(HAVE_CLOCK_GETTIME) + rc = clock_gettime(CLOCK_REALTIME, tsp); +#elif defined(HAVE_GETCLOCK) + rc = getclock(TIMEOFDAY, tsp); +#else + struct timeval tv; + + rc = GETTIMEOFDAY(&tv, NULL); + tsp->tv_sec = tv.tv_sec; + tsp->tv_nsec = tv.tv_usec * 1000; +#endif + if (rc < 0) { + msyslog(LOG_ERR, "read system clock failed: %m (%d)", + errno); + exit(1); + } + + if (trunc_os_clock) { + ticks = (long)((tsp->tv_nsec * 1e-9) / sys_tick); + tsp->tv_nsec = (long)(ticks * 1e9 * sys_tick); + } +} + /* * get_systime - return system time in NTP timestamp format. @@ -61,61 +163,110 @@ get_systime( l_fp *now /* system time */ ) { - double dtemp; - -#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) + static struct timespec ts_last; /* last sampled os time */ + static struct timespec ts_prev; /* prior os time */ + static l_fp lfp_prev; /* prior result */ + static double dfuzz_prev; /* prior fuzz */ struct timespec ts; /* seconds and nanoseconds */ + struct timespec ts_min; /* earliest permissible */ + struct timespec ts_lam; /* lamport fictional increment */ + struct timespec ts_prev_log; /* for msyslog only */ + double dfuzz; + double ddelta; + l_fp result; + l_fp lfpfuzz; + l_fp lfpdelta; + + get_ostime(&ts); + DEBUG_REQUIRE(systime_init_done); + ENTER_GET_SYSTIME_CRITSEC(); + + /* First check if here was a Lamport violation, that is, two + * successive calls to 'get_ostime()' resulted in negative + * time difference. Use a few milliseconds of permissible + * tolerance -- being too sharp can hurt here. (This is intented + * for the Win32 target, where the HPC interpolation might + * introduce small steps backward. It should not be an issue on + * systems where get_ostime() results in a true syscall.) + */ + if (cmp_tspec(add_tspec_ns(ts, 50000000), ts_last) < 0) + lamport_violated = 1; + ts_last = ts; /* - * Convert Unix timespec from seconds and nanoseconds to NTP - * seconds and fraction. + * After default_get_precision() has set a nonzero sys_fuzz, + * ensure every reading of the OS clock advances by at least + * sys_fuzz over the prior reading, thereby assuring each + * fuzzed result is strictly later than the prior. Limit the + * necessary fiction to 1 second. */ -# ifdef HAVE_CLOCK_GETTIME - clock_gettime(CLOCK_REALTIME, &ts); -# else - getclock(TIMEOFDAY, &ts); -# endif - now->l_i = (int32)ts.tv_sec + JAN_1970; - dtemp = 0; - if (sys_tick > FUZZ) - dtemp = ntp_random() * 2. / FRAC * sys_tick * 1e9; - else if (sys_tick > 0) - dtemp = ntp_random() * 2. / FRAC; - dtemp = (ts.tv_nsec + dtemp) * 1e-9; - if (dtemp >= 1.) { - dtemp -= 1.; - now->l_i++; - } else if (dtemp < 0) { - dtemp += 1.; - now->l_i--; + if (!USING_SIGIO()) { + ts_min = add_tspec_ns(ts_prev, sys_fuzz_nsec); + if (cmp_tspec(ts, ts_min) < 0) { + ts_lam = sub_tspec(ts_min, ts); + if (ts_lam.tv_sec > 0 && !lamport_violated) { + msyslog(LOG_ERR, + "get_systime Lamport advance exceeds one second (%.9f)", + ts_lam.tv_sec + + 1e-9 * ts_lam.tv_nsec); + exit(1); + } + if (!lamport_violated) + ts = ts_min; + } + ts_prev_log = ts_prev; + ts_prev = ts; + } else { + /* + * Quiet "ts_prev_log.tv_sec may be used uninitialized" + * warning from x86 gcc 4.5.2. + */ + ZERO(ts_prev_log); } - now->l_uf = (u_int32)(dtemp * FRAC); -#else /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ - struct timeval tv; /* seconds and microseconds */ + /* convert from timespec to l_fp fixed-point */ + result = tspec_stamp_to_lfp(ts); /* - * Convert Unix timeval from seconds and microseconds to NTP - * seconds and fraction. + * Add in the fuzz. */ - GETTIMEOFDAY(&tv, NULL); - now->l_i = tv.tv_sec + JAN_1970; - dtemp = 0; - if (sys_tick > FUZZ) - dtemp = ntp_random() * 2. / FRAC * sys_tick * 1e6; - else if (sys_tick > 0) - dtemp = ntp_random() * 2. / FRAC; - dtemp = (tv.tv_usec + dtemp) * 1e-6; - if (dtemp >= 1.) { - dtemp -= 1.; - now->l_i++; - } else if (dtemp < 0) { - dtemp += 1.; - now->l_i--; - } - now->l_uf = (u_int32)(dtemp * FRAC); + dfuzz = ntp_random() * 2. / FRAC * sys_fuzz; + DTOLFP(dfuzz, &lfpfuzz); + L_ADD(&result, &lfpfuzz); -#endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ + /* + * Ensure result is strictly greater than prior result (ignoring + * sys_residual's effect for now) once sys_fuzz has been + * determined. + */ + if (!USING_SIGIO()) { + if (!L_ISZERO(&lfp_prev) && !lamport_violated) { + if (!L_ISGTU(&result, &lfp_prev) && + sys_fuzz > 0.) { + msyslog(LOG_ERR, "ts_prev %s ts_min %s", + tspectoa(ts_prev_log), + tspectoa(ts_min)); + msyslog(LOG_ERR, "ts %s", tspectoa(ts)); + msyslog(LOG_ERR, "sys_fuzz %ld nsec, prior fuzz %.9f", + sys_fuzz_nsec, dfuzz_prev); + msyslog(LOG_ERR, "this fuzz %.9f", + dfuzz); + lfpdelta = lfp_prev; + L_SUB(&lfpdelta, &result); + LFPTOD(&lfpdelta, ddelta); + msyslog(LOG_ERR, + "prev get_systime 0x%x.%08x is %.9f later than 0x%x.%08x", + lfp_prev.l_ui, lfp_prev.l_uf, + ddelta, result.l_ui, result.l_uf); + } + } + lfp_prev = result; + dfuzz_prev = dfuzz; + if (lamport_violated) + lamport_violated = FALSE; + } + LEAVE_GET_SYSTIME_CRITSEC(); + *now = result; } @@ -130,11 +281,24 @@ adj_systime( { struct timeval adjtv; /* new adjustment */ struct timeval oadjtv; /* residual adjustment */ + double quant; /* quantize to multiples of */ double dtemp; long ticks; int isneg = 0; /* + * The Windows port adj_systime() depends on being called each + * second even when there's no additional correction, to allow + * emulation of adjtime() behavior on top of an API that simply + * sets the current rate. This POSIX implementation needs to + * ignore invocations with zero correction, otherwise ongoing + * EVNT_NSET adjtime() can be aborted by a tiny adjtime() + * triggered by sys_residual. + */ + if (0. == now) + return TRUE; + + /* * Most Unix adjtime() implementations adjust the system clock * in microsecond quanta, but some adjust in 10-ms quanta. We * carefully round the adjustment to the nearest quantum, then @@ -147,8 +311,12 @@ adj_systime( } adjtv.tv_sec = (long)dtemp; dtemp -= adjtv.tv_sec; - ticks = (long)(dtemp / sys_tick + .5); - adjtv.tv_usec = (long)(ticks * sys_tick * 1e6); + if (sys_tick > sys_fuzz) + quant = sys_tick; + else + quant = 1e-6; + ticks = (long)(dtemp / quant + .5); + adjtv.tv_usec = (long)(ticks * quant * 1e6); dtemp -= adjtv.tv_usec / 1e6; sys_residual = dtemp; @@ -165,10 +333,10 @@ adj_systime( if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) { if (adjtime(&adjtv, &oadjtv) < 0) { msyslog(LOG_ERR, "adj_systime: %m"); - return (0); + return FALSE; } } - return (1); + return TRUE; } #endif @@ -176,68 +344,90 @@ adj_systime( /* * step_systime - step the system clock. */ + int step_systime( - double now + double step ) { - struct timeval timetv, adjtv, oldtimetv; - int isneg = 0; - double dtemp; -#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) - struct timespec ts; -#endif + time_t pivot; /* for ntp era unfolding */ + struct timeval timetv, tvlast, tvdiff; + struct timespec timets; + struct calendar jd; + l_fp fp_ofs, fp_sys; /* offset and target system time in FP */ - dtemp = sys_residual + now; - if (dtemp < 0) { - isneg = 1; - dtemp = - dtemp; - adjtv.tv_sec = (int32)dtemp; - adjtv.tv_usec = (u_int32)((dtemp - - (double)adjtv.tv_sec) * 1e6 + .5); + /* + * Get pivot time for NTP era unfolding. Since we don't step + * very often, we can afford to do the whole calculation from + * scratch. And we're not in the time-critical path yet. + */ +#if SIZEOF_TIME_T > 4 + /* + * This code makes sure the resulting time stamp for the new + * system time is in the 2^32 seconds starting at 1970-01-01, + * 00:00:00 UTC. + */ + pivot = 0x80000000; +#if USE_COMPILETIME_PIVOT + /* + * Add the compile time minus 10 years to get a possible target + * area of (compile time - 10 years) to (compile time + 126 + * years). This should be sufficient for a given binary of + * NTPD. + */ + if (ntpcal_get_build_date(&jd)) { + jd.year -= 10; + pivot += ntpcal_date_to_time(&jd); } else { - adjtv.tv_sec = (int32)dtemp; - adjtv.tv_usec = (u_int32)((dtemp - - (double)adjtv.tv_sec) * 1e6 + .5); + msyslog(LOG_ERR, + "step-systime: assume 1970-01-01 as build date"); } -#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) -# ifdef HAVE_CLOCK_GETTIME - (void) clock_gettime(CLOCK_REALTIME, &ts); -# else - (void) getclock(TIMEOFDAY, &ts); -# endif - timetv.tv_sec = ts.tv_sec; - timetv.tv_usec = ts.tv_nsec / 1000; -#else /* not HAVE_GETCLOCK */ - (void) GETTIMEOFDAY(&timetv, (struct timezone *)0); -#endif /* not HAVE_GETCLOCK */ - - oldtimetv = timetv; - -#ifdef DEBUG - if (debug) - printf("step_systime: step %.6f residual %.6f\n", now, sys_residual); +#else + UNUSED_LOCAL(jd); +#endif /* USE_COMPILETIME_PIVOT */ +#else + UNUSED_LOCAL(jd); + /* This makes sure the resulting time stamp is on or after + * 1969-12-31/23:59:59 UTC and gives us additional two years, + * from the change of NTP era in 2036 to the UNIX rollover in + * 2038. (Minus one second, but that won't hurt.) We *really* + * need a longer 'time_t' after that! Or a different baseline, + * but that would cause other serious trouble, too. + */ + pivot = 0x7FFFFFFF; #endif - if (isneg) { - timetv.tv_sec -= adjtv.tv_sec; - timetv.tv_usec -= adjtv.tv_usec; - if (timetv.tv_usec < 0) { - timetv.tv_sec--; - timetv.tv_usec += 1000000; - } - } else { - timetv.tv_sec += adjtv.tv_sec; - timetv.tv_usec += adjtv.tv_usec; - if (timetv.tv_usec >= 1000000) { - timetv.tv_sec++; - timetv.tv_usec -= 1000000; - } - } + + /* get the complete jump distance as l_fp */ + DTOLFP(sys_residual, &fp_sys); + DTOLFP(step, &fp_ofs); + L_ADD(&fp_ofs, &fp_sys); + + /* ---> time-critical path starts ---> */ + + /* get the current time as l_fp (without fuzz) and as struct timeval */ + get_ostime(&timets); + fp_sys = tspec_stamp_to_lfp(timets); + tvlast.tv_sec = timets.tv_sec; + tvlast.tv_usec = (timets.tv_nsec + 500) / 1000; + + /* get the target time as l_fp */ + L_ADD(&fp_sys, &fp_ofs); + + /* unfold the new system time */ + timetv = lfp_stamp_to_tval(fp_sys, &pivot); + + /* now set new system time */ if (ntp_set_tod(&timetv, NULL) != 0) { msyslog(LOG_ERR, "step-systime: %m"); - return (0); + return FALSE; } + + /* <--- time-critical path ended with 'ntp_set_tod()' <--- */ + sys_residual = 0; + lamport_violated = (step < 0); + if (step_callback) + (*step_callback)(); #ifdef NEED_HPUX_ADJTIME /* @@ -267,8 +457,8 @@ step_systime( * * This might become even Uglier... */ - if (oldtimetv.tv_sec != timetv.tv_sec) - { + tvdiff = abs_tval(sub_tval(timetv, tvlast)); + if (tvdiff.tv_sec > 0) { #ifdef HAVE_UTMP_H struct utmp ut; #endif @@ -277,24 +467,29 @@ step_systime( #endif #ifdef HAVE_UTMP_H - memset((char *)&ut, 0, sizeof(ut)); + ZERO(ut); #endif #ifdef HAVE_UTMPX_H - memset((char *)&utx, 0, sizeof(utx)); + ZERO(utx); #endif /* UTMP */ #ifdef UPDATE_UTMP # ifdef HAVE_PUTUTLINE +# ifndef _PATH_UTMP +# define _PATH_UTMP UTMP_FILE +# endif + utmpname(_PATH_UTMP); ut.ut_type = OLD_TIME; - (void)strcpy(ut.ut_line, OTIME_MSG); - ut.ut_time = oldtimetv.tv_sec; - pututline(&ut); + strlcpy(ut.ut_line, OTIME_MSG, sizeof(ut.ut_line)); + ut.ut_time = tvlast.tv_sec; setutent(); + pututline(&ut); ut.ut_type = NEW_TIME; - (void)strcpy(ut.ut_line, NTIME_MSG); + strlcpy(ut.ut_line, NTIME_MSG, sizeof(ut.ut_line)); ut.ut_time = timetv.tv_sec; + setutent(); pututline(&ut); endutent(); # else /* not HAVE_PUTUTLINE */ @@ -306,13 +501,14 @@ step_systime( #ifdef UPDATE_UTMPX # ifdef HAVE_PUTUTXLINE utx.ut_type = OLD_TIME; - (void)strcpy(utx.ut_line, OTIME_MSG); - utx.ut_tv = oldtimetv; - pututxline(&utx); + strlcpy(utx.ut_line, OTIME_MSG, sizeof(utx.ut_line)); + utx.ut_tv = tvlast; setutxent(); + pututxline(&utx); utx.ut_type = NEW_TIME; - (void)strcpy(utx.ut_line, NTIME_MSG); + strlcpy(utx.ut_line, NTIME_MSG, sizeof(utx.ut_line)); utx.ut_tv = timetv; + setutxent(); pututxline(&utx); endutxent(); # else /* not HAVE_PUTUTXLINE */ @@ -323,14 +519,19 @@ step_systime( #ifdef UPDATE_WTMP # ifdef HAVE_PUTUTLINE - utmpname(WTMP_FILE); +# ifndef _PATH_WTMP +# define _PATH_WTMP WTMP_FILE +# endif + utmpname(_PATH_WTMP); ut.ut_type = OLD_TIME; - (void)strcpy(ut.ut_line, OTIME_MSG); - ut.ut_time = oldtimetv.tv_sec; + strlcpy(ut.ut_line, OTIME_MSG, sizeof(ut.ut_line)); + ut.ut_time = tvlast.tv_sec; + setutent(); pututline(&ut); ut.ut_type = NEW_TIME; - (void)strcpy(ut.ut_line, NTIME_MSG); + strlcpy(ut.ut_line, NTIME_MSG, sizeof(ut.ut_line)); ut.ut_time = timetv.tv_sec; + setutent(); pututline(&ut); endutent(); # else /* not HAVE_PUTUTLINE */ @@ -342,8 +543,8 @@ step_systime( #ifdef UPDATE_WTMPX # ifdef HAVE_PUTUTXLINE utx.ut_type = OLD_TIME; - utx.ut_tv = oldtimetv; - (void)strcpy(utx.ut_line, OTIME_MSG); + utx.ut_tv = tvlast; + strlcpy(utx.ut_line, OTIME_MSG, sizeof(utx.ut_line)); # ifdef HAVE_UPDWTMPX updwtmpx(WTMPX_FILE, &utx); # else /* not HAVE_UPDWTMPX */ @@ -353,7 +554,7 @@ step_systime( # ifdef HAVE_PUTUTXLINE utx.ut_type = NEW_TIME; utx.ut_tv = timetv; - (void)strcpy(utx.ut_line, NTIME_MSG); + strlcpy(utx.ut_line, NTIME_MSG, sizeof(utx.ut_line)); # ifdef HAVE_UPDWTMPX updwtmpx(WTMPX_FILE, &utx); # else /* not HAVE_UPDWTMPX */ @@ -363,18 +564,7 @@ step_systime( #endif /* UPDATE_WTMPX */ } - return (1); + return TRUE; } -#else /* SIM */ -/* - * Clock routines for the simulator - Harish Nair, with help - */ - - -/* SK: - * The code that used to be here has been moved to ntpsim.c, - * where, IMHO, it rightfully belonged. - */ - -#endif +#endif /* !SIM */ diff --git a/libntp/timetoa.c b/libntp/timetoa.c new file mode 100644 index 0000000000000..c04d34ea06397 --- /dev/null +++ b/libntp/timetoa.c @@ -0,0 +1,109 @@ +/* + * timetoa.c -- time_t related string formatting + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + * + * Printing a 'time_t' has a lot of portability pitfalls, due to it's + * opaque base type. The only requirement imposed by the standard is + * that it must be a numeric type. For all practical purposes it's a + * signed int, and 32 bits are common. + * + * Since the UN*X time epoch will cause a signed integer overflow for + * 32-bit signed int in the year 2038, implementations slowly move to + * 64bit base types for time_t, even in 32-bit environments. + * + * As the printf() family has no standardised type specifier for time_t, + * guessing the right output format specifier is a bit troublesome and + * best done with the help of the preprocessor and "config.h". + */ + +#include "config.h" + +#include <math.h> +#include <stdio.h> + +#include "timetoa.h" +#include "ntp_assert.h" +#include "lib_strbuf.h" + +/* + * Formatting to string needs at max 40 bytes (even with 64 bit time_t), + * so we check LIB_BUFLENGTH is big enough for our purpose. + */ +#if LIB_BUFLENGTH < 40 +# include "GRONK: LIB_BUFLENGTH is not sufficient" +#endif + +/* + * general fractional timestamp formatting + * + * Many pieces of ntpd require a machine with two's complement + * representation of signed integers, so we don't go through the whole + * rigamarole of creating fully portable code here. But we have to stay + * away from signed integer overflow, as this might cause trouble even + * with two's complement representation. + */ +const char * +format_time_fraction( + time_t secs, + long frac, + int prec + ) +{ + char * cp; + u_int prec_u; + u_time secs_u; + u_int u; + long fraclimit; + int notneg; /* flag for non-negative value */ + const char * fmt; + ldiv_t qr; + + DEBUG_REQUIRE(prec != 0); + + LIB_GETBUF(cp); + secs_u = (u_time)secs; + fmt = "-%" UTIME_FORMAT ".%0*ld"; + + /* check if we need signed or unsigned mode */ + notneg = (prec < 0); + prec_u = abs(prec); + /* fraclimit = (long)pow(10, prec_u); */ + for (fraclimit = 10, u = 1; u < prec_u; u++) { + DEBUG_INSIST(fraclimit < fraclimit * 10); + fraclimit *= 10; + } + + /* + * Since conversion to string uses lots of divisions anyway, + * there's no big extra penalty for normalisation. We do it for + * consistency. + */ + if (frac < 0 || frac >= fraclimit) { + qr = ldiv(frac, fraclimit); + if (qr.rem < 0) { + qr.quot--; + qr.rem += fraclimit; + } + secs_u += (time_t)qr.quot; + frac = qr.rem; + } + + /* Get the absolute value of the split representation time. */ + notneg = notneg || ((time_t)secs_u >= 0); + if (notneg) { + fmt++; /* skip '-' */ + } else { + secs_u = ~secs_u; + if (0 == frac) + secs_u++; + else + frac = fraclimit - frac; + } + + /* finally format the data and return the result */ + snprintf(cp, LIB_BUFLENGTH, fmt, secs_u, prec_u, frac); + + return cp; +} diff --git a/libntp/timevalops.c b/libntp/timevalops.c new file mode 100644 index 0000000000000..55f7bb57312bb --- /dev/null +++ b/libntp/timevalops.c @@ -0,0 +1,297 @@ +/* + * timevalops.c -- calculations on 'struct timeval' values + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + */ + +#include <config.h> + +#include "timevalops.h" + +#ifdef USE_TSF_USEC_TABLES +/* + * Tables to calculate time stamp fractions from usecs. The entries + * in these tables are offset into using each of the two low order + * bytes plus the next 4 bits in a usec value (from a struct timeval). + * These are summed to produce the time stamp fraction. + * + * Note that these tables are rounded (not truncated) to the nearest + * low order bit in the fraction. The timestamp computed should be + * +- 1.5 low order bits. + */ + +const u_int32 ustotslo[256] = { + 0x00000000, 0x000010c7, 0x0000218e, 0x00003255, + 0x0000431c, 0x000053e3, 0x000064aa, 0x00007571, + 0x00008638, 0x000096ff, 0x0000a7c6, 0x0000b88d, + 0x0000c954, 0x0000da1b, 0x0000eae2, 0x0000fba9, + 0x00010c6f, 0x00011d36, 0x00012dfd, 0x00013ec4, + 0x00014f8b, 0x00016052, 0x00017119, 0x000181e0, + 0x000192a7, 0x0001a36e, 0x0001b435, 0x0001c4fc, + 0x0001d5c3, 0x0001e68a, 0x0001f751, 0x00020818, + 0x000218df, 0x000229a6, 0x00023a6d, 0x00024b34, + 0x00025bfb, 0x00026cc2, 0x00027d89, 0x00028e50, + 0x00029f17, 0x0002afde, 0x0002c0a5, 0x0002d16c, + 0x0002e233, 0x0002f2fa, 0x000303c0, 0x00031487, + 0x0003254e, 0x00033615, 0x000346dc, 0x000357a3, + 0x0003686a, 0x00037931, 0x000389f8, 0x00039abf, + 0x0003ab86, 0x0003bc4d, 0x0003cd14, 0x0003dddb, + 0x0003eea2, 0x0003ff69, 0x00041030, 0x000420f7, + 0x000431be, 0x00044285, 0x0004534c, 0x00046413, + 0x000474da, 0x000485a1, 0x00049668, 0x0004a72f, + 0x0004b7f6, 0x0004c8bd, 0x0004d984, 0x0004ea4b, + 0x0004fb12, 0x00050bd8, 0x00051c9f, 0x00052d66, + 0x00053e2d, 0x00054ef4, 0x00055fbb, 0x00057082, + 0x00058149, 0x00059210, 0x0005a2d7, 0x0005b39e, + 0x0005c465, 0x0005d52c, 0x0005e5f3, 0x0005f6ba, + 0x00060781, 0x00061848, 0x0006290f, 0x000639d6, + 0x00064a9d, 0x00065b64, 0x00066c2b, 0x00067cf2, + 0x00068db9, 0x00069e80, 0x0006af47, 0x0006c00e, + 0x0006d0d5, 0x0006e19c, 0x0006f263, 0x0007032a, + 0x000713f0, 0x000724b7, 0x0007357e, 0x00074645, + 0x0007570c, 0x000767d3, 0x0007789a, 0x00078961, + 0x00079a28, 0x0007aaef, 0x0007bbb6, 0x0007cc7d, + 0x0007dd44, 0x0007ee0b, 0x0007fed2, 0x00080f99, + 0x00082060, 0x00083127, 0x000841ee, 0x000852b5, + 0x0008637c, 0x00087443, 0x0008850a, 0x000895d1, + 0x0008a698, 0x0008b75f, 0x0008c826, 0x0008d8ed, + 0x0008e9b4, 0x0008fa7b, 0x00090b41, 0x00091c08, + 0x00092ccf, 0x00093d96, 0x00094e5d, 0x00095f24, + 0x00096feb, 0x000980b2, 0x00099179, 0x0009a240, + 0x0009b307, 0x0009c3ce, 0x0009d495, 0x0009e55c, + 0x0009f623, 0x000a06ea, 0x000a17b1, 0x000a2878, + 0x000a393f, 0x000a4a06, 0x000a5acd, 0x000a6b94, + 0x000a7c5b, 0x000a8d22, 0x000a9de9, 0x000aaeb0, + 0x000abf77, 0x000ad03e, 0x000ae105, 0x000af1cc, + 0x000b0293, 0x000b1359, 0x000b2420, 0x000b34e7, + 0x000b45ae, 0x000b5675, 0x000b673c, 0x000b7803, + 0x000b88ca, 0x000b9991, 0x000baa58, 0x000bbb1f, + 0x000bcbe6, 0x000bdcad, 0x000bed74, 0x000bfe3b, + 0x000c0f02, 0x000c1fc9, 0x000c3090, 0x000c4157, + 0x000c521e, 0x000c62e5, 0x000c73ac, 0x000c8473, + 0x000c953a, 0x000ca601, 0x000cb6c8, 0x000cc78f, + 0x000cd856, 0x000ce91d, 0x000cf9e4, 0x000d0aaa, + 0x000d1b71, 0x000d2c38, 0x000d3cff, 0x000d4dc6, + 0x000d5e8d, 0x000d6f54, 0x000d801b, 0x000d90e2, + 0x000da1a9, 0x000db270, 0x000dc337, 0x000dd3fe, + 0x000de4c5, 0x000df58c, 0x000e0653, 0x000e171a, + 0x000e27e1, 0x000e38a8, 0x000e496f, 0x000e5a36, + 0x000e6afd, 0x000e7bc4, 0x000e8c8b, 0x000e9d52, + 0x000eae19, 0x000ebee0, 0x000ecfa7, 0x000ee06e, + 0x000ef135, 0x000f01fc, 0x000f12c2, 0x000f2389, + 0x000f3450, 0x000f4517, 0x000f55de, 0x000f66a5, + 0x000f776c, 0x000f8833, 0x000f98fa, 0x000fa9c1, + 0x000fba88, 0x000fcb4f, 0x000fdc16, 0x000fecdd, + 0x000ffda4, 0x00100e6b, 0x00101f32, 0x00102ff9, + 0x001040c0, 0x00105187, 0x0010624e, 0x00107315, + 0x001083dc, 0x001094a3, 0x0010a56a, 0x0010b631 +}; + +const u_int32 ustotsmid[256] = { + 0x00000000, 0x0010c6f8, 0x00218def, 0x003254e7, + 0x00431bdf, 0x0053e2d6, 0x0064a9ce, 0x007570c5, + 0x008637bd, 0x0096feb5, 0x00a7c5ac, 0x00b88ca4, + 0x00c9539c, 0x00da1a93, 0x00eae18b, 0x00fba882, + 0x010c6f7a, 0x011d3672, 0x012dfd69, 0x013ec461, + 0x014f8b59, 0x01605250, 0x01711948, 0x0181e03f, + 0x0192a737, 0x01a36e2f, 0x01b43526, 0x01c4fc1e, + 0x01d5c316, 0x01e68a0d, 0x01f75105, 0x020817fc, + 0x0218def4, 0x0229a5ec, 0x023a6ce3, 0x024b33db, + 0x025bfad3, 0x026cc1ca, 0x027d88c2, 0x028e4fb9, + 0x029f16b1, 0x02afdda9, 0x02c0a4a0, 0x02d16b98, + 0x02e23290, 0x02f2f987, 0x0303c07f, 0x03148777, + 0x03254e6e, 0x03361566, 0x0346dc5d, 0x0357a355, + 0x03686a4d, 0x03793144, 0x0389f83c, 0x039abf34, + 0x03ab862b, 0x03bc4d23, 0x03cd141a, 0x03dddb12, + 0x03eea20a, 0x03ff6901, 0x04102ff9, 0x0420f6f1, + 0x0431bde8, 0x044284e0, 0x04534bd7, 0x046412cf, + 0x0474d9c7, 0x0485a0be, 0x049667b6, 0x04a72eae, + 0x04b7f5a5, 0x04c8bc9d, 0x04d98394, 0x04ea4a8c, + 0x04fb1184, 0x050bd87b, 0x051c9f73, 0x052d666b, + 0x053e2d62, 0x054ef45a, 0x055fbb51, 0x05708249, + 0x05814941, 0x05921038, 0x05a2d730, 0x05b39e28, + 0x05c4651f, 0x05d52c17, 0x05e5f30e, 0x05f6ba06, + 0x060780fe, 0x061847f5, 0x06290eed, 0x0639d5e5, + 0x064a9cdc, 0x065b63d4, 0x066c2acc, 0x067cf1c3, + 0x068db8bb, 0x069e7fb2, 0x06af46aa, 0x06c00da2, + 0x06d0d499, 0x06e19b91, 0x06f26289, 0x07032980, + 0x0713f078, 0x0724b76f, 0x07357e67, 0x0746455f, + 0x07570c56, 0x0767d34e, 0x07789a46, 0x0789613d, + 0x079a2835, 0x07aaef2c, 0x07bbb624, 0x07cc7d1c, + 0x07dd4413, 0x07ee0b0b, 0x07fed203, 0x080f98fa, + 0x08205ff2, 0x083126e9, 0x0841ede1, 0x0852b4d9, + 0x08637bd0, 0x087442c8, 0x088509c0, 0x0895d0b7, + 0x08a697af, 0x08b75ea6, 0x08c8259e, 0x08d8ec96, + 0x08e9b38d, 0x08fa7a85, 0x090b417d, 0x091c0874, + 0x092ccf6c, 0x093d9664, 0x094e5d5b, 0x095f2453, + 0x096feb4a, 0x0980b242, 0x0991793a, 0x09a24031, + 0x09b30729, 0x09c3ce21, 0x09d49518, 0x09e55c10, + 0x09f62307, 0x0a06e9ff, 0x0a17b0f7, 0x0a2877ee, + 0x0a393ee6, 0x0a4a05de, 0x0a5accd5, 0x0a6b93cd, + 0x0a7c5ac4, 0x0a8d21bc, 0x0a9de8b4, 0x0aaeafab, + 0x0abf76a3, 0x0ad03d9b, 0x0ae10492, 0x0af1cb8a, + 0x0b029281, 0x0b135979, 0x0b242071, 0x0b34e768, + 0x0b45ae60, 0x0b567558, 0x0b673c4f, 0x0b780347, + 0x0b88ca3e, 0x0b999136, 0x0baa582e, 0x0bbb1f25, + 0x0bcbe61d, 0x0bdcad15, 0x0bed740c, 0x0bfe3b04, + 0x0c0f01fc, 0x0c1fc8f3, 0x0c308feb, 0x0c4156e2, + 0x0c521dda, 0x0c62e4d2, 0x0c73abc9, 0x0c8472c1, + 0x0c9539b9, 0x0ca600b0, 0x0cb6c7a8, 0x0cc78e9f, + 0x0cd85597, 0x0ce91c8f, 0x0cf9e386, 0x0d0aaa7e, + 0x0d1b7176, 0x0d2c386d, 0x0d3cff65, 0x0d4dc65c, + 0x0d5e8d54, 0x0d6f544c, 0x0d801b43, 0x0d90e23b, + 0x0da1a933, 0x0db2702a, 0x0dc33722, 0x0dd3fe19, + 0x0de4c511, 0x0df58c09, 0x0e065300, 0x0e1719f8, + 0x0e27e0f0, 0x0e38a7e7, 0x0e496edf, 0x0e5a35d6, + 0x0e6afcce, 0x0e7bc3c6, 0x0e8c8abd, 0x0e9d51b5, + 0x0eae18ad, 0x0ebedfa4, 0x0ecfa69c, 0x0ee06d94, + 0x0ef1348b, 0x0f01fb83, 0x0f12c27a, 0x0f238972, + 0x0f34506a, 0x0f451761, 0x0f55de59, 0x0f66a551, + 0x0f776c48, 0x0f883340, 0x0f98fa37, 0x0fa9c12f, + 0x0fba8827, 0x0fcb4f1e, 0x0fdc1616, 0x0fecdd0e, + 0x0ffda405, 0x100e6afd, 0x101f31f4, 0x102ff8ec, + 0x1040bfe4, 0x105186db, 0x10624dd3, 0x107314cb, + 0x1083dbc2, 0x1094a2ba, 0x10a569b1, 0x10b630a9 +}; + +const u_int32 ustotshi[16] = { + 0x00000000, 0x10c6f7a1, 0x218def41, 0x3254e6e2, + 0x431bde83, 0x53e2d624, 0x64a9cdc4, 0x7570c565, + 0x8637bd06, 0x96feb4a6, 0xa7c5ac47, 0xb88ca3e8, + 0xc9539b89, 0xda1a9329, 0xeae18aca, 0xfba8826b +}; + +/* + * Tables to convert from a time stamp fraction to usecs. Note that + * the units of these tables are actually (usec<<3). We carry three + * guard bits so that the result can be properly truncated (or rounded) + * to be correct to the least significant bit. + * + * These tables are rounded. + */ + +const u_int32 tstoushi[256] = { + 0x000000, 0x007a12, 0x00f424, 0x016e36, + 0x01e848, 0x02625a, 0x02dc6c, 0x03567e, + 0x03d090, 0x044aa2, 0x04c4b4, 0x053ec6, + 0x05b8d8, 0x0632ea, 0x06acfc, 0x07270e, + 0x07a120, 0x081b32, 0x089544, 0x090f56, + 0x098968, 0x0a037a, 0x0a7d8c, 0x0af79e, + 0x0b71b0, 0x0bebc2, 0x0c65d4, 0x0cdfe6, + 0x0d59f8, 0x0dd40a, 0x0e4e1c, 0x0ec82e, + 0x0f4240, 0x0fbc52, 0x103664, 0x10b076, + 0x112a88, 0x11a49a, 0x121eac, 0x1298be, + 0x1312d0, 0x138ce2, 0x1406f4, 0x148106, + 0x14fb18, 0x15752a, 0x15ef3c, 0x16694e, + 0x16e360, 0x175d72, 0x17d784, 0x185196, + 0x18cba8, 0x1945ba, 0x19bfcc, 0x1a39de, + 0x1ab3f0, 0x1b2e02, 0x1ba814, 0x1c2226, + 0x1c9c38, 0x1d164a, 0x1d905c, 0x1e0a6e, + 0x1e8480, 0x1efe92, 0x1f78a4, 0x1ff2b6, + 0x206cc8, 0x20e6da, 0x2160ec, 0x21dafe, + 0x225510, 0x22cf22, 0x234934, 0x23c346, + 0x243d58, 0x24b76a, 0x25317c, 0x25ab8e, + 0x2625a0, 0x269fb2, 0x2719c4, 0x2793d6, + 0x280de8, 0x2887fa, 0x29020c, 0x297c1e, + 0x29f630, 0x2a7042, 0x2aea54, 0x2b6466, + 0x2bde78, 0x2c588a, 0x2cd29c, 0x2d4cae, + 0x2dc6c0, 0x2e40d2, 0x2ebae4, 0x2f34f6, + 0x2faf08, 0x30291a, 0x30a32c, 0x311d3e, + 0x319750, 0x321162, 0x328b74, 0x330586, + 0x337f98, 0x33f9aa, 0x3473bc, 0x34edce, + 0x3567e0, 0x35e1f2, 0x365c04, 0x36d616, + 0x375028, 0x37ca3a, 0x38444c, 0x38be5e, + 0x393870, 0x39b282, 0x3a2c94, 0x3aa6a6, + 0x3b20b8, 0x3b9aca, 0x3c14dc, 0x3c8eee, + 0x3d0900, 0x3d8312, 0x3dfd24, 0x3e7736, + 0x3ef148, 0x3f6b5a, 0x3fe56c, 0x405f7e, + 0x40d990, 0x4153a2, 0x41cdb4, 0x4247c6, + 0x42c1d8, 0x433bea, 0x43b5fc, 0x44300e, + 0x44aa20, 0x452432, 0x459e44, 0x461856, + 0x469268, 0x470c7a, 0x47868c, 0x48009e, + 0x487ab0, 0x48f4c2, 0x496ed4, 0x49e8e6, + 0x4a62f8, 0x4add0a, 0x4b571c, 0x4bd12e, + 0x4c4b40, 0x4cc552, 0x4d3f64, 0x4db976, + 0x4e3388, 0x4ead9a, 0x4f27ac, 0x4fa1be, + 0x501bd0, 0x5095e2, 0x510ff4, 0x518a06, + 0x520418, 0x527e2a, 0x52f83c, 0x53724e, + 0x53ec60, 0x546672, 0x54e084, 0x555a96, + 0x55d4a8, 0x564eba, 0x56c8cc, 0x5742de, + 0x57bcf0, 0x583702, 0x58b114, 0x592b26, + 0x59a538, 0x5a1f4a, 0x5a995c, 0x5b136e, + 0x5b8d80, 0x5c0792, 0x5c81a4, 0x5cfbb6, + 0x5d75c8, 0x5defda, 0x5e69ec, 0x5ee3fe, + 0x5f5e10, 0x5fd822, 0x605234, 0x60cc46, + 0x614658, 0x61c06a, 0x623a7c, 0x62b48e, + 0x632ea0, 0x63a8b2, 0x6422c4, 0x649cd6, + 0x6516e8, 0x6590fa, 0x660b0c, 0x66851e, + 0x66ff30, 0x677942, 0x67f354, 0x686d66, + 0x68e778, 0x69618a, 0x69db9c, 0x6a55ae, + 0x6acfc0, 0x6b49d2, 0x6bc3e4, 0x6c3df6, + 0x6cb808, 0x6d321a, 0x6dac2c, 0x6e263e, + 0x6ea050, 0x6f1a62, 0x6f9474, 0x700e86, + 0x708898, 0x7102aa, 0x717cbc, 0x71f6ce, + 0x7270e0, 0x72eaf2, 0x736504, 0x73df16, + 0x745928, 0x74d33a, 0x754d4c, 0x75c75e, + 0x764170, 0x76bb82, 0x773594, 0x77afa6, + 0x7829b8, 0x78a3ca, 0x791ddc, 0x7997ee +}; + +const u_int32 tstousmid[256] = { + 0x0000, 0x007a, 0x00f4, 0x016e, 0x01e8, 0x0262, 0x02dc, 0x0356, + 0x03d1, 0x044b, 0x04c5, 0x053f, 0x05b9, 0x0633, 0x06ad, 0x0727, + 0x07a1, 0x081b, 0x0895, 0x090f, 0x0989, 0x0a03, 0x0a7e, 0x0af8, + 0x0b72, 0x0bec, 0x0c66, 0x0ce0, 0x0d5a, 0x0dd4, 0x0e4e, 0x0ec8, + 0x0f42, 0x0fbc, 0x1036, 0x10b0, 0x112b, 0x11a5, 0x121f, 0x1299, + 0x1313, 0x138d, 0x1407, 0x1481, 0x14fb, 0x1575, 0x15ef, 0x1669, + 0x16e3, 0x175d, 0x17d8, 0x1852, 0x18cc, 0x1946, 0x19c0, 0x1a3a, + 0x1ab4, 0x1b2e, 0x1ba8, 0x1c22, 0x1c9c, 0x1d16, 0x1d90, 0x1e0a, + 0x1e84, 0x1eff, 0x1f79, 0x1ff3, 0x206d, 0x20e7, 0x2161, 0x21db, + 0x2255, 0x22cf, 0x2349, 0x23c3, 0x243d, 0x24b7, 0x2531, 0x25ac, + 0x2626, 0x26a0, 0x271a, 0x2794, 0x280e, 0x2888, 0x2902, 0x297c, + 0x29f6, 0x2a70, 0x2aea, 0x2b64, 0x2bde, 0x2c59, 0x2cd3, 0x2d4d, + 0x2dc7, 0x2e41, 0x2ebb, 0x2f35, 0x2faf, 0x3029, 0x30a3, 0x311d, + 0x3197, 0x3211, 0x328b, 0x3306, 0x3380, 0x33fa, 0x3474, 0x34ee, + 0x3568, 0x35e2, 0x365c, 0x36d6, 0x3750, 0x37ca, 0x3844, 0x38be, + 0x3938, 0x39b3, 0x3a2d, 0x3aa7, 0x3b21, 0x3b9b, 0x3c15, 0x3c8f, + 0x3d09, 0x3d83, 0x3dfd, 0x3e77, 0x3ef1, 0x3f6b, 0x3fe5, 0x405f, + 0x40da, 0x4154, 0x41ce, 0x4248, 0x42c2, 0x433c, 0x43b6, 0x4430, + 0x44aa, 0x4524, 0x459e, 0x4618, 0x4692, 0x470c, 0x4787, 0x4801, + 0x487b, 0x48f5, 0x496f, 0x49e9, 0x4a63, 0x4add, 0x4b57, 0x4bd1, + 0x4c4b, 0x4cc5, 0x4d3f, 0x4db9, 0x4e34, 0x4eae, 0x4f28, 0x4fa2, + 0x501c, 0x5096, 0x5110, 0x518a, 0x5204, 0x527e, 0x52f8, 0x5372, + 0x53ec, 0x5466, 0x54e1, 0x555b, 0x55d5, 0x564f, 0x56c9, 0x5743, + 0x57bd, 0x5837, 0x58b1, 0x592b, 0x59a5, 0x5a1f, 0x5a99, 0x5b13, + 0x5b8d, 0x5c08, 0x5c82, 0x5cfc, 0x5d76, 0x5df0, 0x5e6a, 0x5ee4, + 0x5f5e, 0x5fd8, 0x6052, 0x60cc, 0x6146, 0x61c0, 0x623a, 0x62b5, + 0x632f, 0x63a9, 0x6423, 0x649d, 0x6517, 0x6591, 0x660b, 0x6685, + 0x66ff, 0x6779, 0x67f3, 0x686d, 0x68e7, 0x6962, 0x69dc, 0x6a56, + 0x6ad0, 0x6b4a, 0x6bc4, 0x6c3e, 0x6cb8, 0x6d32, 0x6dac, 0x6e26, + 0x6ea0, 0x6f1a, 0x6f94, 0x700f, 0x7089, 0x7103, 0x717d, 0x71f7, + 0x7271, 0x72eb, 0x7365, 0x73df, 0x7459, 0x74d3, 0x754d, 0x75c7, + 0x7641, 0x76bc, 0x7736, 0x77b0, 0x782a, 0x78a4, 0x791e, 0x7998 +}; + +const u_int32 tstouslo[128] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, + 0x1f, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, + 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, + 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, + 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b, + 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, + 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, + 0x5c, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, + 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x71, + 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79 +}; +#else /* !USE_TSF_USEC_TABLES follows */ +NONEMPTY_TRANSLATION_UNIT +#endif /* !USE_TSF_USEC_TABLES */ +/* -*- EOF -*- */ diff --git a/libntp/tsftomsu.c b/libntp/tsftomsu.c deleted file mode 100644 index 5926aabc77a6e..0000000000000 --- a/libntp/tsftomsu.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * tsftomsu - convert from a time stamp fraction to milliseconds - */ -#include "ntp_fp.h" -#include "ntp_stdlib.h" - -int -tsftomsu( - u_long tsf, - int round - ) -{ - register long val_ui, val_uf; - register long tmp_ui, tmp_uf; - register int i; - - /* - * Essentially, multiply by 10 three times in l_fp form. - * The integral part is the milliseconds. - */ - val_ui = 0; - val_uf = tsf; - for (i = 3; i > 0; i--) { - M_LSHIFT(val_ui, val_uf); - tmp_ui = val_ui; - tmp_uf = val_uf; - M_LSHIFT(val_ui, val_uf); - M_LSHIFT(val_ui, val_uf); - M_ADD(val_ui, val_uf, tmp_ui, tmp_uf); - } - - /* - * Round the value if need be, then return it. - */ - if (round && (val_uf & 0x80000000)) - val_ui++; - return (int)val_ui; -} diff --git a/libntp/tstotv.c b/libntp/tstotv.c deleted file mode 100644 index be4bdd44155dc..0000000000000 --- a/libntp/tstotv.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * tstotv - tables for converting from NTP time stamps to struct timeval - */ - -#include "ntp_types.h" - -/* - * Tables to convert from a time stamp fraction to usecs. Note that - * the units of these tables are actually (usec<<3). We carry three - * guard bits so that the result can be properly truncated (or rounded) - * to be correct to the least significant bit. - * - * These tables are rounded. - */ - -long tstoushi[256] = { - 0x000000, 0x007a12, 0x00f424, 0x016e36, - 0x01e848, 0x02625a, 0x02dc6c, 0x03567e, - 0x03d090, 0x044aa2, 0x04c4b4, 0x053ec6, - 0x05b8d8, 0x0632ea, 0x06acfc, 0x07270e, - 0x07a120, 0x081b32, 0x089544, 0x090f56, - 0x098968, 0x0a037a, 0x0a7d8c, 0x0af79e, - 0x0b71b0, 0x0bebc2, 0x0c65d4, 0x0cdfe6, - 0x0d59f8, 0x0dd40a, 0x0e4e1c, 0x0ec82e, - 0x0f4240, 0x0fbc52, 0x103664, 0x10b076, - 0x112a88, 0x11a49a, 0x121eac, 0x1298be, - 0x1312d0, 0x138ce2, 0x1406f4, 0x148106, - 0x14fb18, 0x15752a, 0x15ef3c, 0x16694e, - 0x16e360, 0x175d72, 0x17d784, 0x185196, - 0x18cba8, 0x1945ba, 0x19bfcc, 0x1a39de, - 0x1ab3f0, 0x1b2e02, 0x1ba814, 0x1c2226, - 0x1c9c38, 0x1d164a, 0x1d905c, 0x1e0a6e, - 0x1e8480, 0x1efe92, 0x1f78a4, 0x1ff2b6, - 0x206cc8, 0x20e6da, 0x2160ec, 0x21dafe, - 0x225510, 0x22cf22, 0x234934, 0x23c346, - 0x243d58, 0x24b76a, 0x25317c, 0x25ab8e, - 0x2625a0, 0x269fb2, 0x2719c4, 0x2793d6, - 0x280de8, 0x2887fa, 0x29020c, 0x297c1e, - 0x29f630, 0x2a7042, 0x2aea54, 0x2b6466, - 0x2bde78, 0x2c588a, 0x2cd29c, 0x2d4cae, - 0x2dc6c0, 0x2e40d2, 0x2ebae4, 0x2f34f6, - 0x2faf08, 0x30291a, 0x30a32c, 0x311d3e, - 0x319750, 0x321162, 0x328b74, 0x330586, - 0x337f98, 0x33f9aa, 0x3473bc, 0x34edce, - 0x3567e0, 0x35e1f2, 0x365c04, 0x36d616, - 0x375028, 0x37ca3a, 0x38444c, 0x38be5e, - 0x393870, 0x39b282, 0x3a2c94, 0x3aa6a6, - 0x3b20b8, 0x3b9aca, 0x3c14dc, 0x3c8eee, - 0x3d0900, 0x3d8312, 0x3dfd24, 0x3e7736, - 0x3ef148, 0x3f6b5a, 0x3fe56c, 0x405f7e, - 0x40d990, 0x4153a2, 0x41cdb4, 0x4247c6, - 0x42c1d8, 0x433bea, 0x43b5fc, 0x44300e, - 0x44aa20, 0x452432, 0x459e44, 0x461856, - 0x469268, 0x470c7a, 0x47868c, 0x48009e, - 0x487ab0, 0x48f4c2, 0x496ed4, 0x49e8e6, - 0x4a62f8, 0x4add0a, 0x4b571c, 0x4bd12e, - 0x4c4b40, 0x4cc552, 0x4d3f64, 0x4db976, - 0x4e3388, 0x4ead9a, 0x4f27ac, 0x4fa1be, - 0x501bd0, 0x5095e2, 0x510ff4, 0x518a06, - 0x520418, 0x527e2a, 0x52f83c, 0x53724e, - 0x53ec60, 0x546672, 0x54e084, 0x555a96, - 0x55d4a8, 0x564eba, 0x56c8cc, 0x5742de, - 0x57bcf0, 0x583702, 0x58b114, 0x592b26, - 0x59a538, 0x5a1f4a, 0x5a995c, 0x5b136e, - 0x5b8d80, 0x5c0792, 0x5c81a4, 0x5cfbb6, - 0x5d75c8, 0x5defda, 0x5e69ec, 0x5ee3fe, - 0x5f5e10, 0x5fd822, 0x605234, 0x60cc46, - 0x614658, 0x61c06a, 0x623a7c, 0x62b48e, - 0x632ea0, 0x63a8b2, 0x6422c4, 0x649cd6, - 0x6516e8, 0x6590fa, 0x660b0c, 0x66851e, - 0x66ff30, 0x677942, 0x67f354, 0x686d66, - 0x68e778, 0x69618a, 0x69db9c, 0x6a55ae, - 0x6acfc0, 0x6b49d2, 0x6bc3e4, 0x6c3df6, - 0x6cb808, 0x6d321a, 0x6dac2c, 0x6e263e, - 0x6ea050, 0x6f1a62, 0x6f9474, 0x700e86, - 0x708898, 0x7102aa, 0x717cbc, 0x71f6ce, - 0x7270e0, 0x72eaf2, 0x736504, 0x73df16, - 0x745928, 0x74d33a, 0x754d4c, 0x75c75e, - 0x764170, 0x76bb82, 0x773594, 0x77afa6, - 0x7829b8, 0x78a3ca, 0x791ddc, 0x7997ee -}; - -long tstousmid[256] = { - 0x0000, 0x007a, 0x00f4, 0x016e, 0x01e8, 0x0262, 0x02dc, 0x0356, - 0x03d1, 0x044b, 0x04c5, 0x053f, 0x05b9, 0x0633, 0x06ad, 0x0727, - 0x07a1, 0x081b, 0x0895, 0x090f, 0x0989, 0x0a03, 0x0a7e, 0x0af8, - 0x0b72, 0x0bec, 0x0c66, 0x0ce0, 0x0d5a, 0x0dd4, 0x0e4e, 0x0ec8, - 0x0f42, 0x0fbc, 0x1036, 0x10b0, 0x112b, 0x11a5, 0x121f, 0x1299, - 0x1313, 0x138d, 0x1407, 0x1481, 0x14fb, 0x1575, 0x15ef, 0x1669, - 0x16e3, 0x175d, 0x17d8, 0x1852, 0x18cc, 0x1946, 0x19c0, 0x1a3a, - 0x1ab4, 0x1b2e, 0x1ba8, 0x1c22, 0x1c9c, 0x1d16, 0x1d90, 0x1e0a, - 0x1e84, 0x1eff, 0x1f79, 0x1ff3, 0x206d, 0x20e7, 0x2161, 0x21db, - 0x2255, 0x22cf, 0x2349, 0x23c3, 0x243d, 0x24b7, 0x2531, 0x25ac, - 0x2626, 0x26a0, 0x271a, 0x2794, 0x280e, 0x2888, 0x2902, 0x297c, - 0x29f6, 0x2a70, 0x2aea, 0x2b64, 0x2bde, 0x2c59, 0x2cd3, 0x2d4d, - 0x2dc7, 0x2e41, 0x2ebb, 0x2f35, 0x2faf, 0x3029, 0x30a3, 0x311d, - 0x3197, 0x3211, 0x328b, 0x3306, 0x3380, 0x33fa, 0x3474, 0x34ee, - 0x3568, 0x35e2, 0x365c, 0x36d6, 0x3750, 0x37ca, 0x3844, 0x38be, - 0x3938, 0x39b3, 0x3a2d, 0x3aa7, 0x3b21, 0x3b9b, 0x3c15, 0x3c8f, - 0x3d09, 0x3d83, 0x3dfd, 0x3e77, 0x3ef1, 0x3f6b, 0x3fe5, 0x405f, - 0x40da, 0x4154, 0x41ce, 0x4248, 0x42c2, 0x433c, 0x43b6, 0x4430, - 0x44aa, 0x4524, 0x459e, 0x4618, 0x4692, 0x470c, 0x4787, 0x4801, - 0x487b, 0x48f5, 0x496f, 0x49e9, 0x4a63, 0x4add, 0x4b57, 0x4bd1, - 0x4c4b, 0x4cc5, 0x4d3f, 0x4db9, 0x4e34, 0x4eae, 0x4f28, 0x4fa2, - 0x501c, 0x5096, 0x5110, 0x518a, 0x5204, 0x527e, 0x52f8, 0x5372, - 0x53ec, 0x5466, 0x54e1, 0x555b, 0x55d5, 0x564f, 0x56c9, 0x5743, - 0x57bd, 0x5837, 0x58b1, 0x592b, 0x59a5, 0x5a1f, 0x5a99, 0x5b13, - 0x5b8d, 0x5c08, 0x5c82, 0x5cfc, 0x5d76, 0x5df0, 0x5e6a, 0x5ee4, - 0x5f5e, 0x5fd8, 0x6052, 0x60cc, 0x6146, 0x61c0, 0x623a, 0x62b5, - 0x632f, 0x63a9, 0x6423, 0x649d, 0x6517, 0x6591, 0x660b, 0x6685, - 0x66ff, 0x6779, 0x67f3, 0x686d, 0x68e7, 0x6962, 0x69dc, 0x6a56, - 0x6ad0, 0x6b4a, 0x6bc4, 0x6c3e, 0x6cb8, 0x6d32, 0x6dac, 0x6e26, - 0x6ea0, 0x6f1a, 0x6f94, 0x700f, 0x7089, 0x7103, 0x717d, 0x71f7, - 0x7271, 0x72eb, 0x7365, 0x73df, 0x7459, 0x74d3, 0x754d, 0x75c7, - 0x7641, 0x76bc, 0x7736, 0x77b0, 0x782a, 0x78a4, 0x791e, 0x7998 -}; - -long tstouslo[128] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, - 0x1f, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, - 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, - 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, - 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, - 0x45, 0x46, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b, - 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, - 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, - 0x5c, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, - 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, - 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x71, - 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79 -}; diff --git a/libntp/tvtots.c b/libntp/tvtots.c deleted file mode 100644 index 0bd2b69114729..0000000000000 --- a/libntp/tvtots.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * tvtots - tables for converting from Unix struct timeval's to - * NTP time stamp format. - */ -#include <sys/types.h> - -#include "ntp_types.h" - -/* - * Tables to calculate time stamp fractions from usecs. The entries - * in these tables are offset into using each of the two low order - * bytes plus the next 4 bits in a usec value (from a struct timeval). - * These are summed to produce the time stamp fraction. - * - * Note that these tables are rounded (not truncated) to the nearest - * low order bit in the fraction. The timestamp computed should be - * +- 1.5 low order bits. - */ - -u_long ustotslo[256] = { - 0x00000000, 0x000010c7, 0x0000218e, 0x00003255, - 0x0000431c, 0x000053e3, 0x000064aa, 0x00007571, - 0x00008638, 0x000096ff, 0x0000a7c6, 0x0000b88d, - 0x0000c954, 0x0000da1b, 0x0000eae2, 0x0000fba9, - 0x00010c6f, 0x00011d36, 0x00012dfd, 0x00013ec4, - 0x00014f8b, 0x00016052, 0x00017119, 0x000181e0, - 0x000192a7, 0x0001a36e, 0x0001b435, 0x0001c4fc, - 0x0001d5c3, 0x0001e68a, 0x0001f751, 0x00020818, - 0x000218df, 0x000229a6, 0x00023a6d, 0x00024b34, - 0x00025bfb, 0x00026cc2, 0x00027d89, 0x00028e50, - 0x00029f17, 0x0002afde, 0x0002c0a5, 0x0002d16c, - 0x0002e233, 0x0002f2fa, 0x000303c0, 0x00031487, - 0x0003254e, 0x00033615, 0x000346dc, 0x000357a3, - 0x0003686a, 0x00037931, 0x000389f8, 0x00039abf, - 0x0003ab86, 0x0003bc4d, 0x0003cd14, 0x0003dddb, - 0x0003eea2, 0x0003ff69, 0x00041030, 0x000420f7, - 0x000431be, 0x00044285, 0x0004534c, 0x00046413, - 0x000474da, 0x000485a1, 0x00049668, 0x0004a72f, - 0x0004b7f6, 0x0004c8bd, 0x0004d984, 0x0004ea4b, - 0x0004fb12, 0x00050bd8, 0x00051c9f, 0x00052d66, - 0x00053e2d, 0x00054ef4, 0x00055fbb, 0x00057082, - 0x00058149, 0x00059210, 0x0005a2d7, 0x0005b39e, - 0x0005c465, 0x0005d52c, 0x0005e5f3, 0x0005f6ba, - 0x00060781, 0x00061848, 0x0006290f, 0x000639d6, - 0x00064a9d, 0x00065b64, 0x00066c2b, 0x00067cf2, - 0x00068db9, 0x00069e80, 0x0006af47, 0x0006c00e, - 0x0006d0d5, 0x0006e19c, 0x0006f263, 0x00070329, - 0x000713f0, 0x000724b7, 0x0007357e, 0x00074645, - 0x0007570c, 0x000767d3, 0x0007789a, 0x00078961, - 0x00079a28, 0x0007aaef, 0x0007bbb6, 0x0007cc7d, - 0x0007dd44, 0x0007ee0b, 0x0007fed2, 0x00080f99, - 0x00082060, 0x00083127, 0x000841ee, 0x000852b5, - 0x0008637c, 0x00087443, 0x0008850a, 0x000895d1, - 0x0008a698, 0x0008b75f, 0x0008c826, 0x0008d8ed, - 0x0008e9b4, 0x0008fa7b, 0x00090b41, 0x00091c08, - 0x00092ccf, 0x00093d96, 0x00094e5d, 0x00095f24, - 0x00096feb, 0x000980b2, 0x00099179, 0x0009a240, - 0x0009b307, 0x0009c3ce, 0x0009d495, 0x0009e55c, - 0x0009f623, 0x000a06ea, 0x000a17b1, 0x000a2878, - 0x000a393f, 0x000a4a06, 0x000a5acd, 0x000a6b94, - 0x000a7c5b, 0x000a8d22, 0x000a9de9, 0x000aaeb0, - 0x000abf77, 0x000ad03e, 0x000ae105, 0x000af1cc, - 0x000b0292, 0x000b1359, 0x000b2420, 0x000b34e7, - 0x000b45ae, 0x000b5675, 0x000b673c, 0x000b7803, - 0x000b88ca, 0x000b9991, 0x000baa58, 0x000bbb1f, - 0x000bcbe6, 0x000bdcad, 0x000bed74, 0x000bfe3b, - 0x000c0f02, 0x000c1fc9, 0x000c3090, 0x000c4157, - 0x000c521e, 0x000c62e5, 0x000c73ac, 0x000c8473, - 0x000c953a, 0x000ca601, 0x000cb6c8, 0x000cc78f, - 0x000cd856, 0x000ce91d, 0x000cf9e4, 0x000d0aaa, - 0x000d1b71, 0x000d2c38, 0x000d3cff, 0x000d4dc6, - 0x000d5e8d, 0x000d6f54, 0x000d801b, 0x000d90e2, - 0x000da1a9, 0x000db270, 0x000dc337, 0x000dd3fe, - 0x000de4c5, 0x000df58c, 0x000e0653, 0x000e171a, - 0x000e27e1, 0x000e38a8, 0x000e496f, 0x000e5a36, - 0x000e6afd, 0x000e7bc4, 0x000e8c8b, 0x000e9d52, - 0x000eae19, 0x000ebee0, 0x000ecfa7, 0x000ee06e, - 0x000ef135, 0x000f01fb, 0x000f12c2, 0x000f2389, - 0x000f3450, 0x000f4517, 0x000f55de, 0x000f66a5, - 0x000f776c, 0x000f8833, 0x000f98fa, 0x000fa9c1, - 0x000fba88, 0x000fcb4f, 0x000fdc16, 0x000fecdd, - 0x000ffda4, 0x00100e6b, 0x00101f32, 0x00102ff9, - 0x001040c0, 0x00105187, 0x0010624e, 0x00107315, - 0x001083dc, 0x001094a3, 0x0010a56a, 0x0010b631, -}; - -u_long ustotsmid[256] = { - 0x00000000, 0x0010c6f8, 0x00218def, 0x003254e7, - 0x00431bde, 0x0053e2d6, 0x0064a9ce, 0x007570c5, - 0x008637bd, 0x0096feb4, 0x00a7c5ac, 0x00b88ca4, - 0x00c9539b, 0x00da1a93, 0x00eae18a, 0x00fba882, - 0x010c6f7a, 0x011d3671, 0x012dfd69, 0x013ec460, - 0x014f8b58, 0x01605250, 0x01711947, 0x0181e03f, - 0x0192a736, 0x01a36e2e, 0x01b43526, 0x01c4fc1d, - 0x01d5c315, 0x01e68a0c, 0x01f75104, 0x020817fc, - 0x0218def3, 0x0229a5eb, 0x023a6ce3, 0x024b33da, - 0x025bfad2, 0x026cc1c9, 0x027d88c1, 0x028e4fb9, - 0x029f16b0, 0x02afdda8, 0x02c0a49f, 0x02d16b97, - 0x02e2328f, 0x02f2f986, 0x0303c07e, 0x03148775, - 0x03254e6d, 0x03361565, 0x0346dc5c, 0x0357a354, - 0x03686a4b, 0x03793143, 0x0389f83b, 0x039abf32, - 0x03ab862a, 0x03bc4d21, 0x03cd1419, 0x03dddb11, - 0x03eea208, 0x03ff6900, 0x04102ff7, 0x0420f6ef, - 0x0431bde7, 0x044284de, 0x04534bd6, 0x046412cd, - 0x0474d9c5, 0x0485a0bd, 0x049667b4, 0x04a72eac, - 0x04b7f5a3, 0x04c8bc9b, 0x04d98393, 0x04ea4a8a, - 0x04fb1182, 0x050bd879, 0x051c9f71, 0x052d6669, - 0x053e2d60, 0x054ef458, 0x055fbb4f, 0x05708247, - 0x0581493f, 0x05921036, 0x05a2d72e, 0x05b39e25, - 0x05c4651d, 0x05d52c15, 0x05e5f30c, 0x05f6ba04, - 0x060780fb, 0x061847f3, 0x06290eeb, 0x0639d5e2, - 0x064a9cda, 0x065b63d2, 0x066c2ac9, 0x067cf1c1, - 0x068db8b8, 0x069e7fb0, 0x06af46a8, 0x06c00d9f, - 0x06d0d497, 0x06e19b8e, 0x06f26286, 0x0703297e, - 0x0713f075, 0x0724b76d, 0x07357e64, 0x0746455c, - 0x07570c54, 0x0767d34b, 0x07789a43, 0x0789613a, - 0x079a2832, 0x07aaef2a, 0x07bbb621, 0x07cc7d19, - 0x07dd4410, 0x07ee0b08, 0x07fed200, 0x080f98f7, - 0x08205fef, 0x083126e6, 0x0841edde, 0x0852b4d6, - 0x08637bcd, 0x087442c5, 0x088509bc, 0x0895d0b4, - 0x08a697ac, 0x08b75ea3, 0x08c8259b, 0x08d8ec92, - 0x08e9b38a, 0x08fa7a82, 0x090b4179, 0x091c0871, - 0x092ccf68, 0x093d9660, 0x094e5d58, 0x095f244f, - 0x096feb47, 0x0980b23e, 0x09917936, 0x09a2402e, - 0x09b30725, 0x09c3ce1d, 0x09d49514, 0x09e55c0c, - 0x09f62304, 0x0a06e9fb, 0x0a17b0f3, 0x0a2877ea, - 0x0a393ee2, 0x0a4a05da, 0x0a5accd1, 0x0a6b93c9, - 0x0a7c5ac1, 0x0a8d21b8, 0x0a9de8b0, 0x0aaeafa7, - 0x0abf769f, 0x0ad03d97, 0x0ae1048e, 0x0af1cb86, - 0x0b02927d, 0x0b135975, 0x0b24206d, 0x0b34e764, - 0x0b45ae5c, 0x0b567553, 0x0b673c4b, 0x0b780343, - 0x0b88ca3a, 0x0b999132, 0x0baa5829, 0x0bbb1f21, - 0x0bcbe619, 0x0bdcad10, 0x0bed7408, 0x0bfe3aff, - 0x0c0f01f7, 0x0c1fc8ef, 0x0c308fe6, 0x0c4156de, - 0x0c521dd5, 0x0c62e4cd, 0x0c73abc5, 0x0c8472bc, - 0x0c9539b4, 0x0ca600ab, 0x0cb6c7a3, 0x0cc78e9b, - 0x0cd85592, 0x0ce91c8a, 0x0cf9e381, 0x0d0aaa79, - 0x0d1b7171, 0x0d2c3868, 0x0d3cff60, 0x0d4dc657, - 0x0d5e8d4f, 0x0d6f5447, 0x0d801b3e, 0x0d90e236, - 0x0da1a92d, 0x0db27025, 0x0dc3371d, 0x0dd3fe14, - 0x0de4c50c, 0x0df58c03, 0x0e0652fb, 0x0e1719f3, - 0x0e27e0ea, 0x0e38a7e2, 0x0e496ed9, 0x0e5a35d1, - 0x0e6afcc9, 0x0e7bc3c0, 0x0e8c8ab8, 0x0e9d51b0, - 0x0eae18a7, 0x0ebedf9f, 0x0ecfa696, 0x0ee06d8e, - 0x0ef13486, 0x0f01fb7d, 0x0f12c275, 0x0f23896c, - 0x0f345064, 0x0f45175c, 0x0f55de53, 0x0f66a54b, - 0x0f776c42, 0x0f88333a, 0x0f98fa32, 0x0fa9c129, - 0x0fba8821, 0x0fcb4f18, 0x0fdc1610, 0x0fecdd08, - 0x0ffda3ff, 0x100e6af7, 0x101f31ee, 0x102ff8e6, - 0x1040bfde, 0x105186d5, 0x10624dcd, 0x107314c4, - 0x1083dbbc, 0x1094a2b4, 0x10a569ab, 0x10b630a3, -}; - -u_long ustotshi[16] = { - 0x00000000, 0x10c6f79a, 0x218def35, 0x3254e6cf, - 0x431bde6a, 0x53e2d604, 0x64a9cd9f, 0x7570c539, - 0x8637bcd3, 0x96feb46e, 0xa7c5ac08, 0xb88ca3a3, - 0xc9539b3d, 0xda1a92d7, 0xeae18a72, 0xfba8820c, -}; diff --git a/libntp/uglydate.c b/libntp/uglydate.c index b2da9c0a6c39e..66b5139096b41 100644 --- a/libntp/uglydate.c +++ b/libntp/uglydate.c @@ -2,6 +2,7 @@ * uglydate - convert a time stamp to something barely readable * The string returned is 37 characters long. */ +#include <config.h> #include <stdio.h> #include "ntp_fp.h" diff --git a/libntp/uinttoa.c b/libntp/uinttoa.c deleted file mode 100644 index ab63926cdc79f..0000000000000 --- a/libntp/uinttoa.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * uinttoa - return an asciized unsigned integer - */ -#include <stdio.h> - -#include "lib_strbuf.h" -#include "ntp_stdlib.h" - -char * -uinttoa( - u_long uval - ) -{ - register char *buf; - - LIB_GETBUF(buf); - snprintf(buf, LIB_BUFLENGTH, "%lu", uval); - - return buf; -} diff --git a/libntp/vint64ops.c b/libntp/vint64ops.c new file mode 100644 index 0000000000000..5adbebbb51d40 --- /dev/null +++ b/libntp/vint64ops.c @@ -0,0 +1,284 @@ +/* + * vint64ops.c - operations on 'vint64' values + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + * ---------------------------------------------------------------------- + * This is an attempt to get the vint64 calculations stuff centralised. + */ + +#include <config.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <errno.h> + +#include "ntp_types.h" +#include "ntp_fp.h" +#include "vint64ops.h" + +/* --------------------------------------------------------------------- + * GCC is rather sticky with its 'const' attribute. We have to do it more + * explicit than with a cast if we want to get rid of a CONST qualifier. + * Greetings from the PASCAL world, where casting was only possible via + * untagged unions... + */ +static inline void* +noconst( + const void* ptr + ) +{ + union { + const void * cp; + void * vp; + } tmp; + tmp.cp = ptr; + return tmp.vp; +} + +/* -------------------------------------------------------------------------*/ + +vint64 +strtouv64( + const char * begp, + char ** endp, + int base + ) +{ + vint64 res; + u_char digit; + int sig, num; + const u_char *src; + + num = sig = 0; + src = (const u_char*)begp; + while (isspace(*src)) + src++; + + if (*src == '-') { + src++; + sig = 1; + } else if (*src == '+') { + src++; + } + + if (base == 0) { + base = 10; + if (*src == '0') { + base = 8; + if (toupper(*++src) == 'X') { + src++; + base = 16; + } + } + } else if (base == 16) { /* remove optional leading '0x' or '0X' */ + if (src[0] == '0' && toupper(src[1]) == 'X') + src += 2; + } else if (base <= 2 || base > 36) { + memset(&res, 0xFF, sizeof(res)); + errno = ERANGE; + return res; + } + + memset(&res, 0, sizeof(res)); + while (*src) { + if (isdigit(*src)) + digit = *src - '0'; + else if (isupper(*src)) + digit = *src - 'A' + 10; + else if (islower(*src)) + digit = *src - 'a' + 10; + else + break; + if (digit >= base) + break; + num = 1; +#if defined(HAVE_INT64) + res.Q_s = res.Q_s * base + digit; +#else + /* res *= base, using 16x16->32 bit + * multiplication. Slow but portable. + */ + { + uint32_t accu; + accu = (uint32_t)res.W_s.ll * base; + res.W_s.ll = (uint16_t)accu; + accu = (accu >> 16) + + (uint32_t)res.W_s.lh * base; + res.W_s.lh = (uint16_t)accu; + /* the upper bits can be done in one step: */ + res.D_s.hi = res.D_s.hi * base + (accu >> 16); + } + M_ADD(res.D_s.hi, res.D_s.lo, 0, digit); +#endif + src++; + } + if (!num) + errno = EINVAL; + if (endp) + *endp = (char*)noconst(src); + if (sig) + M_NEG(res.D_s.hi, res.D_s.lo); + return res; +} + +/* -------------------------------------------------------------------------*/ + +int +icmpv64( + const vint64 * lhs, + const vint64 * rhs + ) +{ + int res; + +#if defined(HAVE_INT64) + res = (lhs->q_s > rhs->q_s) + - (lhs->q_s < rhs->q_s); +#else + res = (lhs->d_s.hi > rhs->d_s.hi) + - (lhs->d_s.hi < rhs->d_s.hi); + if ( ! res ) + res = (lhs->D_s.lo > rhs->D_s.lo) + - (lhs->D_s.lo < rhs->D_s.lo); +#endif + + return res; +} + +/* -------------------------------------------------------------------------*/ + +int +ucmpv64( + const vint64 * lhs, + const vint64 * rhs + ) +{ + int res; + +#if defined(HAVE_INT64) + res = (lhs->Q_s > rhs->Q_s) + - (lhs->Q_s < rhs->Q_s); +#else + res = (lhs->D_s.hi > rhs->D_s.hi) + - (lhs->D_s.hi < rhs->D_s.hi); + if ( ! res ) + res = (lhs->D_s.lo > rhs->D_s.lo) + - (lhs->D_s.lo < rhs->D_s.lo); +#endif + return res; +} + +/* -------------------------------------------------------------------------*/ + +vint64 +addv64( + const vint64 *lhs, + const vint64 *rhs + ) +{ + vint64 res; + +#if defined(HAVE_INT64) + res.Q_s = lhs->Q_s + rhs->Q_s; +#else + res = *lhs; + M_ADD(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo); +#endif + return res; +} + +/* -------------------------------------------------------------------------*/ + +vint64 +subv64( + const vint64 *lhs, + const vint64 *rhs + ) +{ + vint64 res; + +#if defined(HAVE_INT64) + res.Q_s = lhs->Q_s - rhs->Q_s; +#else + res = *lhs; + M_SUB(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo); +#endif + return res; +} + +/* -------------------------------------------------------------------------*/ + +vint64 +addv64i32( + const vint64 * lhs, + int32_t rhs + ) +{ + vint64 res; + + res = *lhs; +#if defined(HAVE_INT64) + res.q_s += rhs; +#else + M_ADD(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs); +#endif + return res; +} + +/* -------------------------------------------------------------------------*/ + +vint64 +subv64i32( + const vint64 * lhs, + int32_t rhs + ) +{ + vint64 res; + + res = *lhs; +#if defined(HAVE_INT64) + res.q_s -= rhs; +#else + M_SUB(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs); +#endif + return res; +} + +/* -------------------------------------------------------------------------*/ + +vint64 +addv64u32( + const vint64 * lhs, + uint32_t rhs + ) +{ + vint64 res; + + res = *lhs; +#if defined(HAVE_INT64) + res.Q_s += rhs; +#else + M_ADD(res.D_s.hi, res.D_s.lo, 0, rhs); +#endif + return res; +} + +/* -------------------------------------------------------------------------*/ + +vint64 +subv64u32( + const vint64 * lhs, + uint32_t rhs + ) +{ + vint64 res; + + res = *lhs; +#if defined(HAVE_INT64) + res.Q_s -= rhs; +#else + M_SUB(res.D_s.hi, res.D_s.lo, 0, rhs); +#endif + return res; +} diff --git a/libntp/work_fork.c b/libntp/work_fork.c new file mode 100644 index 0000000000000..10329e70be8f4 --- /dev/null +++ b/libntp/work_fork.c @@ -0,0 +1,526 @@ +/* + * work_fork.c - fork implementation for blocking worker child. + */ +#include <config.h> +#include "ntp_workimpl.h" + +#ifdef WORK_FORK +#include <stdio.h> +#include <ctype.h> +#include <signal.h> + +#include "iosignal.h" +#include "ntp_stdlib.h" +#include "ntp_malloc.h" +#include "ntp_syslog.h" +#include "ntpd.h" +#include "ntp_io.h" +#include "ntp_assert.h" +#include "ntp_unixtime.h" +#include "ntp_worker.h" + +/* === variables === */ + int worker_process; + addremove_io_fd_func addremove_io_fd; +static volatile int worker_sighup_received; + +/* === function prototypes === */ +static void fork_blocking_child(blocking_child *); +static RETSIGTYPE worker_sighup(int); +static void send_worker_home_atexit(void); +static void cleanup_after_child(blocking_child *); + +/* === functions === */ +/* + * exit_worker() + * + * On some systems _exit() is preferred to exit() for forked children. + * For example, http://netbsd.gw.com/cgi-bin/man-cgi?fork++NetBSD-5.0 + * recommends _exit() to avoid double-flushing C runtime stream buffers + * and also to avoid calling the parent's atexit() routines in the + * child. On those systems WORKER_CHILD_EXIT is _exit. Since _exit + * bypasses CRT cleanup, fflush() files we know might have output + * buffered. + */ +void +exit_worker( + int exitcode + ) +{ + if (syslog_file != NULL) + fflush(syslog_file); + fflush(stdout); + fflush(stderr); + WORKER_CHILD_EXIT (exitcode); /* space before ( required */ +} + + +static RETSIGTYPE +worker_sighup( + int sig + ) +{ + if (SIGHUP == sig) + worker_sighup_received = 1; +} + + +int +worker_sleep( + blocking_child * c, + time_t seconds + ) +{ + u_int sleep_remain; + + sleep_remain = (u_int)seconds; + do { + if (!worker_sighup_received) + sleep_remain = sleep(sleep_remain); + if (worker_sighup_received) { + TRACE(1, ("worker SIGHUP with %us left to sleep", + sleep_remain)); + worker_sighup_received = 0; + return -1; + } + } while (sleep_remain); + + return 0; +} + + +void +interrupt_worker_sleep(void) +{ + u_int idx; + blocking_child * c; + int rc; + + for (idx = 0; idx < blocking_children_alloc; idx++) { + c = blocking_children[idx]; + + if (NULL == c || c->reusable == TRUE) + continue; + + rc = kill(c->pid, SIGHUP); + if (rc < 0) + msyslog(LOG_ERR, + "Unable to signal HUP to wake child pid %d: %m", + c->pid); + } +} + + +/* + * req_child_exit() runs in the parent. + */ +int +req_child_exit( + blocking_child * c + ) +{ + if (-1 != c->req_write_pipe) { + close(c->req_write_pipe); + c->req_write_pipe = -1; + return 0; + } + return -1; +} + + +/* + * cleanup_after_child() runs in parent. + */ +static void +cleanup_after_child( + blocking_child * c + ) +{ + if (-1 != c->req_write_pipe) { + close(c->req_write_pipe); + c->req_write_pipe = -1; + } + if (-1 != c->resp_read_pipe) { + (*addremove_io_fd)(c->resp_read_pipe, c->ispipe, TRUE); + close(c->resp_read_pipe); + c->resp_read_pipe = -1; + } + c->pid = 0; + c->resp_read_ctx = NULL; + DEBUG_INSIST(-1 == c->req_read_pipe); + DEBUG_INSIST(-1 == c->resp_write_pipe); + c->reusable = TRUE; +} + + +static void +send_worker_home_atexit(void) +{ + u_int idx; + blocking_child * c; + + if (worker_process) + return; + + for (idx = 0; idx < blocking_children_alloc; idx++) { + c = blocking_children[idx]; + if (NULL == c) + continue; + req_child_exit(c); + } +} + + +int +send_blocking_req_internal( + blocking_child * c, + blocking_pipe_header * hdr, + void * data + ) +{ + int octets; + int rc; + + DEBUG_REQUIRE(hdr != NULL); + DEBUG_REQUIRE(data != NULL); + DEBUG_REQUIRE(BLOCKING_REQ_MAGIC == hdr->magic_sig); + + if (-1 == c->req_write_pipe) { + fork_blocking_child(c); + DEBUG_INSIST(-1 != c->req_write_pipe); + } + + octets = sizeof(*hdr); + rc = write(c->req_write_pipe, hdr, octets); + + if (rc == octets) { + octets = hdr->octets - sizeof(*hdr); + rc = write(c->req_write_pipe, data, octets); + + if (rc == octets) + return 0; + } + + if (rc < 0) + msyslog(LOG_ERR, + "send_blocking_req_internal: pipe write: %m"); + else + msyslog(LOG_ERR, + "send_blocking_req_internal: short write %d of %d", + rc, octets); + + exit(1); /* otherwise would be return -1 */ +} + + +blocking_pipe_header * +receive_blocking_req_internal( + blocking_child * c + ) +{ + blocking_pipe_header hdr; + blocking_pipe_header * req; + int rc; + long octets; + + DEBUG_REQUIRE(-1 != c->req_read_pipe); + + req = NULL; + + do { + rc = read(c->req_read_pipe, &hdr, sizeof(hdr)); + } while (rc < 0 && EINTR == errno); + + if (rc < 0) { + msyslog(LOG_ERR, + "receive_blocking_req_internal: pipe read %m"); + } else if (0 == rc) { + 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", + rc, (u_long)sizeof(hdr)); + } else { + INSIST(sizeof(hdr) < hdr.octets && hdr.octets < 4 * 1024); + req = emalloc(hdr.octets); + memcpy(req, &hdr, sizeof(*req)); + octets = hdr.octets - sizeof(hdr); + rc = read(c->req_read_pipe, (char *)req + sizeof(*req), + octets); + + if (rc < 0) + msyslog(LOG_ERR, + "receive_blocking_req_internal: pipe data read %m"); + else if (rc != octets) + msyslog(LOG_ERR, + "receive_blocking_req_internal: short read %d of %ld", + rc, octets); + else if (BLOCKING_REQ_MAGIC != req->magic_sig) + msyslog(LOG_ERR, + "receive_blocking_req_internal: packet header mismatch (0x%x)", + req->magic_sig); + else + return req; + } + + if (req != NULL) + free(req); + + return NULL; +} + + +int +send_blocking_resp_internal( + blocking_child * c, + blocking_pipe_header * resp + ) +{ + long octets; + int rc; + + DEBUG_REQUIRE(-1 != c->resp_write_pipe); + + octets = resp->octets; + rc = write(c->resp_write_pipe, resp, octets); + free(resp); + + if (octets == rc) + return 0; + + if (rc < 0) + TRACE(1, ("send_blocking_resp_internal: pipe write %m\n")); + else + TRACE(1, ("send_blocking_resp_internal: short write %d of %ld\n", + rc, octets)); + + return -1; +} + + +blocking_pipe_header * +receive_blocking_resp_internal( + blocking_child * c + ) +{ + blocking_pipe_header hdr; + blocking_pipe_header * resp; + int rc; + long octets; + + DEBUG_REQUIRE(c->resp_read_pipe != -1); + + resp = NULL; + rc = read(c->resp_read_pipe, &hdr, sizeof(hdr)); + + if (rc < 0) { + 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)) { + 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) { + TRACE(1, ("receive_blocking_resp_internal: header mismatch (0x%x)\n", + hdr.magic_sig)); + } else { + INSIST(sizeof(hdr) < hdr.octets && + hdr.octets < 16 * 1024); + resp = emalloc(hdr.octets); + memcpy(resp, &hdr, sizeof(*resp)); + octets = hdr.octets - sizeof(hdr); + rc = read(c->resp_read_pipe, + (char *)resp + sizeof(*resp), + octets); + + if (rc < 0) + TRACE(1, ("receive_blocking_resp_internal: pipe data read %m\n")); + else if (rc < octets) + TRACE(1, ("receive_blocking_resp_internal: short read %d of %ld\n", + rc, octets)); + else + return resp; + } + + cleanup_after_child(c); + + if (resp != NULL) + free(resp); + + return NULL; +} + + +#if defined(HAVE_DROPROOT) && defined(WORK_FORK) +void +fork_deferred_worker(void) +{ + u_int idx; + blocking_child * c; + + REQUIRE(droproot && root_dropped); + + for (idx = 0; idx < blocking_children_alloc; idx++) { + c = blocking_children[idx]; + if (NULL == c) + continue; + if (-1 != c->req_write_pipe && 0 == c->pid) + fork_blocking_child(c); + } +} +#endif + + +static void +fork_blocking_child( + blocking_child * c + ) +{ + static int atexit_installed; + static int blocking_pipes[4] = { -1, -1, -1, -1 }; + int rc; + int was_pipe; + int is_pipe; + int saved_errno; + int childpid; + int keep_fd; + int fd; + + /* + * parent and child communicate via a pair of pipes. + * + * 0 child read request + * 1 parent write request + * 2 parent read response + * 3 child write response + */ + if (-1 == c->req_write_pipe) { + rc = pipe_socketpair(&blocking_pipes[0], &was_pipe); + if (0 != rc) { + saved_errno = errno; + } else { + rc = pipe_socketpair(&blocking_pipes[2], &is_pipe); + if (0 != rc) { + saved_errno = errno; + close(blocking_pipes[0]); + close(blocking_pipes[1]); + } else { + INSIST(was_pipe == is_pipe); + } + } + if (0 != rc) { + errno = saved_errno; + msyslog(LOG_ERR, "unable to create worker pipes: %m"); + exit(1); + } + + /* + * Move the descriptors the parent will keep open out of the + * low descriptors preferred by C runtime buffered FILE *. + */ + c->req_write_pipe = move_fd(blocking_pipes[1]); + c->resp_read_pipe = move_fd(blocking_pipes[2]); + /* + * wake any worker child on orderly shutdown of the + * daemon so that it can notice the broken pipes and + * go away promptly. + */ + if (!atexit_installed) { + atexit(&send_worker_home_atexit); + atexit_installed = TRUE; + } + } + +#ifdef HAVE_DROPROOT + /* defer the fork until after root is dropped */ + if (droproot && !root_dropped) + return; +#endif + if (syslog_file != NULL) + fflush(syslog_file); + fflush(stdout); + fflush(stderr); + + signal_no_reset(SIGCHLD, SIG_IGN); + + childpid = fork(); + if (-1 == childpid) { + msyslog(LOG_ERR, "unable to fork worker: %m"); + exit(1); + } + + if (childpid) { + /* this is the parent */ + TRACE(1, ("forked worker child (pid %d)\n", childpid)); + c->pid = childpid; + c->ispipe = is_pipe; + + /* close the child's pipe descriptors. */ + close(blocking_pipes[0]); + close(blocking_pipes[3]); + + memset(blocking_pipes, -1, sizeof(blocking_pipes)); + + /* wire into I/O loop */ + (*addremove_io_fd)(c->resp_read_pipe, is_pipe, FALSE); + + return; /* parent returns */ + } + + /* + * The parent gets the child pid as the return value of fork(). + * The child must work for it. + */ + c->pid = getpid(); + worker_process = TRUE; + + /* + * In the child, close all files except stdin, stdout, stderr, + * and the two child ends of the pipes. + */ + DEBUG_INSIST(-1 == c->req_read_pipe); + DEBUG_INSIST(-1 == c->resp_write_pipe); + c->req_read_pipe = blocking_pipes[0]; + c->resp_write_pipe = blocking_pipes[3]; + + kill_asyncio(0); + closelog(); + if (syslog_file != NULL) { + fclose(syslog_file); + syslog_file = NULL; + syslogit = TRUE; + } + keep_fd = max(c->req_read_pipe, c->resp_write_pipe); + for (fd = 3; fd < keep_fd; fd++) + if (fd != c->req_read_pipe && + fd != c->resp_write_pipe) + close(fd); + close_all_beyond(keep_fd); + /* + * We get signals from refclock serial I/O on NetBSD in the + * worker if we do not reset SIGIO's handler to the default. + * It is not conditionalized for NetBSD alone because on + * systems where it is not needed, it is harmless, and that + * allows us to handle unknown others with NetBSD behavior. + * [Bug 1386] + */ +#if defined(USE_SIGIO) + signal_no_reset(SIGIO, SIG_DFL); +#elif defined(USE_SIGPOLL) + signal_no_reset(SIGPOLL, SIG_DFL); +#endif + signal_no_reset(SIGHUP, worker_sighup); + init_logging("ntp_intres", 0, FALSE); + setup_logfile(NULL); + + /* + * And now back to the portable code + */ + exit_worker(blocking_child_common(c)); +} + + +#else /* !WORK_FORK follows */ +char work_fork_nonempty_compilation_unit; +#endif diff --git a/libntp/work_thread.c b/libntp/work_thread.c new file mode 100644 index 0000000000000..38d87470f01a7 --- /dev/null +++ b/libntp/work_thread.c @@ -0,0 +1,726 @@ +/* + * work_thread.c - threads implementation for blocking worker child. + */ +#include <config.h> +#include "ntp_workimpl.h" + +#ifdef WORK_THREAD + +#include <stdio.h> +#include <ctype.h> +#include <signal.h> +#ifndef SYS_WINNT +#include <pthread.h> +#endif + +#include "ntp_stdlib.h" +#include "ntp_malloc.h" +#include "ntp_syslog.h" +#include "ntpd.h" +#include "ntp_io.h" +#include "ntp_assert.h" +#include "ntp_unixtime.h" +#include "timespecops.h" +#include "ntp_worker.h" + +#define CHILD_EXIT_REQ ((blocking_pipe_header *)(intptr_t)-1) +#define CHILD_GONE_RESP CHILD_EXIT_REQ +#define WORKITEMS_ALLOC_INC 16 +#define RESPONSES_ALLOC_INC 4 + +#ifndef THREAD_MINSTACKSIZE +#define THREAD_MINSTACKSIZE (64U * 1024) +#endif + +#ifndef DEVOLATILE +#define DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) +#endif + +#ifdef SYS_WINNT +# define thread_exit(c) _endthreadex(c) +# define tickle_sem SetEvent +#else +# define thread_exit(c) pthread_exit((void*)(size_t)(c)) +# define tickle_sem sem_post +#endif + +#ifdef WORK_PIPE +addremove_io_fd_func addremove_io_fd; +#else +addremove_io_semaphore_func addremove_io_semaphore; +#endif + +static void start_blocking_thread(blocking_child *); +static void start_blocking_thread_internal(blocking_child *); +static void prepare_child_sems(blocking_child *); +static int wait_for_sem(sem_ref, struct timespec *); +static void ensure_workitems_empty_slot(blocking_child *); +static void ensure_workresp_empty_slot(blocking_child *); +static int queue_req_pointer(blocking_child *, blocking_pipe_header *); +static void cleanup_after_child(blocking_child *); +#ifdef SYS_WINNT +u_int WINAPI blocking_thread(void *); +#else +void * blocking_thread(void *); +#endif +#ifndef SYS_WINNT +static void block_thread_signals(sigset_t *); +#endif + + +void +exit_worker( + int exitcode + ) +{ + thread_exit(exitcode); /* see #define thread_exit */ +} + + +int +worker_sleep( + blocking_child * c, + time_t seconds + ) +{ + struct timespec until; + int rc; + +# ifdef HAVE_CLOCK_GETTIME + if (0 != clock_gettime(CLOCK_REALTIME, &until)) { + msyslog(LOG_ERR, "worker_sleep: clock_gettime() failed: %m"); + return -1; + } +# else + if (0 != getclock(TIMEOFDAY, &until)) { + msyslog(LOG_ERR, "worker_sleep: getclock() failed: %m"); + return -1; + } +# endif + until.tv_sec += seconds; + do { + rc = wait_for_sem(c->wake_scheduled_sleep, &until); + } while (-1 == rc && EINTR == errno); + if (0 == rc) + return -1; + if (-1 == rc && ETIMEDOUT == errno) + return 0; + msyslog(LOG_ERR, "worker_sleep: sem_timedwait: %m"); + return -1; +} + + +void +interrupt_worker_sleep(void) +{ + u_int idx; + blocking_child * c; + + for (idx = 0; idx < blocking_children_alloc; idx++) { + c = blocking_children[idx]; + if (NULL == c || NULL == c->wake_scheduled_sleep) + continue; + tickle_sem(c->wake_scheduled_sleep); + } +} + + +static void +ensure_workitems_empty_slot( + blocking_child *c + ) +{ + const size_t each = sizeof(blocking_children[0]->workitems[0]); + size_t new_alloc; + size_t old_octets; + size_t new_octets; + void * nonvol_workitems; + + + if (c->workitems != NULL && + NULL == c->workitems[c->next_workitem]) + return; + + new_alloc = c->workitems_alloc + WORKITEMS_ALLOC_INC; + old_octets = c->workitems_alloc * each; + new_octets = new_alloc * each; + nonvol_workitems = DEVOLATILE(void *, c->workitems); + c->workitems = erealloc_zero(nonvol_workitems, new_octets, + old_octets); + if (0 == c->next_workitem) + c->next_workitem = c->workitems_alloc; + c->workitems_alloc = new_alloc; +} + + +static void +ensure_workresp_empty_slot( + blocking_child *c + ) +{ + const size_t each = sizeof(blocking_children[0]->responses[0]); + size_t new_alloc; + size_t old_octets; + size_t new_octets; + void * nonvol_responses; + + if (c->responses != NULL && + NULL == c->responses[c->next_response]) + return; + + new_alloc = c->responses_alloc + RESPONSES_ALLOC_INC; + old_octets = c->responses_alloc * each; + new_octets = new_alloc * each; + nonvol_responses = DEVOLATILE(void *, c->responses); + c->responses = erealloc_zero(nonvol_responses, new_octets, + old_octets); + if (0 == c->next_response) + c->next_response = c->responses_alloc; + c->responses_alloc = new_alloc; +} + + +/* + * queue_req_pointer() - append a work item or idle exit request to + * blocking_workitems[]. + */ +static int +queue_req_pointer( + blocking_child * c, + blocking_pipe_header * hdr + ) +{ + c->workitems[c->next_workitem] = hdr; + c->next_workitem = (1 + c->next_workitem) % c->workitems_alloc; + + /* + * We only want to signal the wakeup event if the child is + * blocking on it, which is indicated by setting the blocking + * event. Wait with zero timeout to test. + */ + /* !!!! if (WAIT_OBJECT_0 == WaitForSingleObject(c->child_is_blocking, 0)) */ + tickle_sem(c->blocking_req_ready); + + return 0; +} + + +int +send_blocking_req_internal( + blocking_child * c, + blocking_pipe_header * hdr, + void * data + ) +{ + blocking_pipe_header * threadcopy; + size_t payload_octets; + + REQUIRE(hdr != NULL); + REQUIRE(data != NULL); + DEBUG_REQUIRE(BLOCKING_REQ_MAGIC == hdr->magic_sig); + + if (hdr->octets <= sizeof(*hdr)) + return 1; /* failure */ + payload_octets = hdr->octets - sizeof(*hdr); + + ensure_workitems_empty_slot(c); + if (NULL == c->thread_ref) { + ensure_workresp_empty_slot(c); + start_blocking_thread(c); + } + + threadcopy = emalloc(hdr->octets); + memcpy(threadcopy, hdr, sizeof(*hdr)); + memcpy((char *)threadcopy + sizeof(*hdr), data, payload_octets); + + return queue_req_pointer(c, threadcopy); +} + + +blocking_pipe_header * +receive_blocking_req_internal( + blocking_child * c + ) +{ + blocking_pipe_header * req; + int rc; + + /* + * Child blocks here when idle. SysV semaphores maintain a + * count and release from sem_wait() only when it reaches 0. + * Windows auto-reset events are simpler, and multiple SetEvent + * calls before any thread waits result in a single wakeup. + * On Windows, the child drains all workitems each wakeup, while + * with SysV semaphores wait_sem() is used before each item. + */ +#ifdef SYS_WINNT + while (NULL == c->workitems[c->next_workeritem]) { + /* !!!! SetEvent(c->child_is_blocking); */ + rc = wait_for_sem(c->blocking_req_ready, NULL); + INSIST(0 == rc); + /* !!!! ResetEvent(c->child_is_blocking); */ + } +#else + do { + rc = wait_for_sem(c->blocking_req_ready, NULL); + } while (-1 == rc && EINTR == errno); + INSIST(0 == rc); +#endif + + req = c->workitems[c->next_workeritem]; + INSIST(NULL != req); + c->workitems[c->next_workeritem] = NULL; + c->next_workeritem = (1 + c->next_workeritem) % + c->workitems_alloc; + + if (CHILD_EXIT_REQ == req) { /* idled out */ + send_blocking_resp_internal(c, CHILD_GONE_RESP); + req = NULL; + } + + return req; +} + + +int +send_blocking_resp_internal( + blocking_child * c, + blocking_pipe_header * resp + ) +{ + ensure_workresp_empty_slot(c); + + c->responses[c->next_response] = resp; + c->next_response = (1 + c->next_response) % c->responses_alloc; + +#ifdef WORK_PIPE + write(c->resp_write_pipe, "", 1); +#else + tickle_sem(c->blocking_response_ready); +#endif + + return 0; +} + + +#ifndef WORK_PIPE +void +handle_blocking_resp_sem( + void * context + ) +{ + HANDLE ready; + blocking_child * c; + u_int idx; + + ready = (HANDLE)context; + c = NULL; + for (idx = 0; idx < blocking_children_alloc; idx++) { + c = blocking_children[idx]; + if (c != NULL && c->thread_ref != NULL && + ready == c->blocking_response_ready) + break; + } + if (idx < blocking_children_alloc) + process_blocking_resp(c); +} +#endif /* !WORK_PIPE */ + + +blocking_pipe_header * +receive_blocking_resp_internal( + blocking_child * c + ) +{ + blocking_pipe_header * removed; +#ifdef WORK_PIPE + int rc; + char scratch[32]; + + do { + rc = read(c->resp_read_pipe, scratch, sizeof(scratch)); + } while (-1 == rc && EINTR == errno); +#endif + removed = c->responses[c->next_workresp]; + if (NULL != removed) { + c->responses[c->next_workresp] = NULL; + c->next_workresp = (1 + c->next_workresp) % + c->responses_alloc; + DEBUG_ENSURE(CHILD_GONE_RESP == removed || + BLOCKING_RESP_MAGIC == removed->magic_sig); + } + if (CHILD_GONE_RESP == removed) { + cleanup_after_child(c); + removed = NULL; + } + + return removed; +} + + +static void +start_blocking_thread( + blocking_child * c + ) +{ + + DEBUG_INSIST(!c->reusable); + + prepare_child_sems(c); + start_blocking_thread_internal(c); +} + + +static void +start_blocking_thread_internal( + blocking_child * c + ) +#ifdef SYS_WINNT +{ + thr_ref blocking_child_thread; + u_int blocking_thread_id; + BOOL resumed; + + (*addremove_io_semaphore)(c->blocking_response_ready, FALSE); + blocking_child_thread = + (HANDLE)_beginthreadex( + NULL, + 0, + &blocking_thread, + c, + CREATE_SUSPENDED, + &blocking_thread_id); + + if (NULL == blocking_child_thread) { + msyslog(LOG_ERR, "start blocking thread failed: %m"); + exit(-1); + } + c->thread_id = blocking_thread_id; + c->thread_ref = blocking_child_thread; + /* remember the thread priority is only within the process class */ + if (!SetThreadPriority(blocking_child_thread, + THREAD_PRIORITY_BELOW_NORMAL)) + msyslog(LOG_ERR, "Error lowering blocking thread priority: %m"); + + resumed = ResumeThread(blocking_child_thread); + DEBUG_INSIST(resumed); +} +#else /* pthreads start_blocking_thread_internal() follows */ +{ +# ifdef NEED_PTHREAD_INIT + static int pthread_init_called; +# endif + pthread_attr_t thr_attr; + int rc; + int saved_errno; + int pipe_ends[2]; /* read then write */ + int is_pipe; + int flags; + size_t stacksize; + sigset_t saved_sig_mask; + +# ifdef NEED_PTHREAD_INIT + /* + * from lib/isc/unix/app.c: + * BSDI 3.1 seg faults in pthread_sigmask() if we don't do this. + */ + if (!pthread_init_called) { + pthread_init(); + pthread_init_called = TRUE; + } +# endif + + rc = pipe_socketpair(&pipe_ends[0], &is_pipe); + if (0 != rc) { + msyslog(LOG_ERR, "start_blocking_thread: pipe_socketpair() %m"); + exit(1); + } + c->resp_read_pipe = move_fd(pipe_ends[0]); + c->resp_write_pipe = move_fd(pipe_ends[1]); + c->ispipe = is_pipe; + flags = fcntl(c->resp_read_pipe, F_GETFL, 0); + if (-1 == flags) { + msyslog(LOG_ERR, "start_blocking_thread: fcntl(F_GETFL) %m"); + exit(1); + } + rc = fcntl(c->resp_read_pipe, F_SETFL, O_NONBLOCK | flags); + if (-1 == rc) { + msyslog(LOG_ERR, + "start_blocking_thread: fcntl(F_SETFL, O_NONBLOCK) %m"); + exit(1); + } + (*addremove_io_fd)(c->resp_read_pipe, c->ispipe, FALSE); + pthread_attr_init(&thr_attr); + pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED); +#if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \ + defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) + rc = pthread_attr_getstacksize(&thr_attr, &stacksize); + if (-1 == rc) { + msyslog(LOG_ERR, + "start_blocking_thread: pthread_attr_getstacksize %m"); + } else if (stacksize < THREAD_MINSTACKSIZE) { + rc = pthread_attr_setstacksize(&thr_attr, + THREAD_MINSTACKSIZE); + if (-1 == rc) + msyslog(LOG_ERR, + "start_blocking_thread: pthread_attr_setstacksize(0x%lx -> 0x%lx) %m", + (u_long)stacksize, + (u_long)THREAD_MINSTACKSIZE); + } +#else + UNUSED_ARG(stacksize); +#endif +#if defined(PTHREAD_SCOPE_SYSTEM) && defined(NEED_PTHREAD_SCOPE_SYSTEM) + pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM); +#endif + c->thread_ref = emalloc_zero(sizeof(*c->thread_ref)); + block_thread_signals(&saved_sig_mask); + rc = pthread_create(c->thread_ref, &thr_attr, + &blocking_thread, c); + saved_errno = errno; + pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL); + pthread_attr_destroy(&thr_attr); + if (0 != rc) { + errno = saved_errno; + msyslog(LOG_ERR, "pthread_create() blocking child: %m"); + exit(1); + } +} +#endif + + +/* + * block_thread_signals() + * + * Temporarily block signals used by ntpd main thread, so that signal + * mask inherited by child threads leaves them blocked. Returns prior + * active signal mask via pmask, to be restored by the main thread + * after pthread_create(). + */ +#ifndef SYS_WINNT +void +block_thread_signals( + sigset_t * pmask + ) +{ + sigset_t block; + + sigemptyset(&block); +# ifdef HAVE_SIGNALED_IO +# ifdef SIGIO + sigaddset(&block, SIGIO); +# endif +# ifdef SIGPOLL + sigaddset(&block, SIGPOLL); +# endif +# endif /* HAVE_SIGNALED_IO */ + sigaddset(&block, SIGALRM); + sigaddset(&block, MOREDEBUGSIG); + sigaddset(&block, LESSDEBUGSIG); +# ifdef SIGDIE1 + sigaddset(&block, SIGDIE1); +# endif +# ifdef SIGDIE2 + sigaddset(&block, SIGDIE2); +# endif +# ifdef SIGDIE3 + sigaddset(&block, SIGDIE3); +# endif +# ifdef SIGDIE4 + sigaddset(&block, SIGDIE4); +# endif +# ifdef SIGBUS + sigaddset(&block, SIGBUS); +# endif + sigemptyset(pmask); + pthread_sigmask(SIG_BLOCK, &block, pmask); +} +#endif /* !SYS_WINNT */ + + +/* + * prepare_child_sems() + * + * create sync events (semaphores) + * child_is_blocking initially unset + * blocking_req_ready initially unset + * + * Child waits for blocking_req_ready to be set after + * setting child_is_blocking. blocking_req_ready and + * blocking_response_ready are auto-reset, so wake one + * waiter and become unset (unsignalled) in one operation. + */ +static void +prepare_child_sems( + blocking_child *c + ) +#ifdef SYS_WINNT +{ + if (NULL == c->blocking_req_ready) { + /* manual reset using ResetEvent() */ + /* !!!! c->child_is_blocking = CreateEvent(NULL, TRUE, FALSE, NULL); */ + /* auto reset - one thread released from wait each set */ + c->blocking_req_ready = CreateEvent(NULL, FALSE, FALSE, NULL); + c->blocking_response_ready = CreateEvent(NULL, FALSE, FALSE, NULL); + c->wake_scheduled_sleep = CreateEvent(NULL, FALSE, FALSE, NULL); + } else { + /* !!!! ResetEvent(c->child_is_blocking); */ + /* ResetEvent(c->blocking_req_ready); */ + /* ResetEvent(c->blocking_response_ready); */ + /* ResetEvent(c->wake_scheduled_sleep); */ + } +} +#else /* pthreads prepare_child_sems() follows */ +{ + size_t octets; + + if (NULL == c->blocking_req_ready) { + octets = sizeof(*c->blocking_req_ready); + octets += sizeof(*c->wake_scheduled_sleep); + /* !!!! octets += sizeof(*c->child_is_blocking); */ + c->blocking_req_ready = emalloc_zero(octets);; + c->wake_scheduled_sleep = 1 + c->blocking_req_ready; + /* !!!! c->child_is_blocking = 1 + c->wake_scheduled_sleep; */ + } else { + sem_destroy(c->blocking_req_ready); + sem_destroy(c->wake_scheduled_sleep); + /* !!!! sem_destroy(c->child_is_blocking); */ + } + sem_init(c->blocking_req_ready, FALSE, 0); + sem_init(c->wake_scheduled_sleep, FALSE, 0); + /* !!!! sem_init(c->child_is_blocking, FALSE, 0); */ +} +#endif + + +static int +wait_for_sem( + sem_ref sem, + struct timespec * timeout /* wall-clock */ + ) +#ifdef SYS_WINNT +{ + struct timespec now; + struct timespec delta; + DWORD msec; + DWORD rc; + + if (NULL == timeout) { + msec = INFINITE; + } else { + getclock(TIMEOFDAY, &now); + delta = sub_tspec(*timeout, now); + if (delta.tv_sec < 0) { + msec = 0; + } else if ((delta.tv_sec + 1) >= (MAXDWORD / 1000)) { + msec = INFINITE; + } else { + msec = 1000 * (DWORD)delta.tv_sec; + msec += delta.tv_nsec / (1000 * 1000); + } + } + rc = WaitForSingleObject(sem, msec); + if (WAIT_OBJECT_0 == rc) + return 0; + if (WAIT_TIMEOUT == rc) { + errno = ETIMEDOUT; + return -1; + } + msyslog(LOG_ERR, "WaitForSingleObject unexpected 0x%x", rc); + errno = EFAULT; + return -1; +} +#else /* pthreads wait_for_sem() follows */ +{ + int rc; + + if (NULL == timeout) + rc = sem_wait(sem); + else + rc = sem_timedwait(sem, timeout); + + return rc; +} +#endif + + +/* + * blocking_thread - thread functions have WINAPI calling convention + */ +#ifdef SYS_WINNT +u_int +WINAPI +#else +void * +#endif +blocking_thread( + void * ThreadArg + ) +{ + blocking_child *c; + + c = ThreadArg; + exit_worker(blocking_child_common(c)); + + /* NOTREACHED */ + return 0; +} + + +/* + * req_child_exit() runs in the parent. + */ +int +req_child_exit( + blocking_child *c + ) +{ + return queue_req_pointer(c, CHILD_EXIT_REQ); +} + + +/* + * cleanup_after_child() runs in parent. + */ +static void +cleanup_after_child( + blocking_child * c + ) +{ + u_int idx; + + DEBUG_INSIST(!c->reusable); +#ifdef SYS_WINNT + INSIST(CloseHandle(c->thread_ref)); +#else + free(c->thread_ref); +#endif + c->thread_ref = NULL; + c->thread_id = 0; +#ifdef WORK_PIPE + DEBUG_INSIST(-1 != c->resp_read_pipe); + DEBUG_INSIST(-1 != c->resp_write_pipe); + (*addremove_io_fd)(c->resp_read_pipe, c->ispipe, TRUE); + close(c->resp_write_pipe); + close(c->resp_read_pipe); + c->resp_write_pipe = -1; + c->resp_read_pipe = -1; +#else + DEBUG_INSIST(NULL != c->blocking_response_ready); + (*addremove_io_semaphore)(c->blocking_response_ready, TRUE); +#endif + for (idx = 0; idx < c->workitems_alloc; idx++) + c->workitems[idx] = NULL; + c->next_workitem = 0; + c->next_workeritem = 0; + for (idx = 0; idx < c->responses_alloc; idx++) + c->responses[idx] = NULL; + c->next_response = 0; + c->next_workresp = 0; + c->reusable = TRUE; +} + + +#else /* !WORK_THREAD follows */ +char work_thread_nonempty_compilation_unit; +#endif diff --git a/libntp/ymd2yd.c b/libntp/ymd2yd.c index 796ce40948bdb..c6b3a0cad7dce 100644 --- a/libntp/ymd2yd.c +++ b/libntp/ymd2yd.c @@ -1,37 +1,26 @@ /* * ymd2yd - compute the date in the year from y/m/d + * + * A thin wrapper around a more general calendar function. */ -#include "ntp_fp.h" -#include "ntp_unixtime.h" +#include <config.h> #include "ntp_stdlib.h" - -/* - * Tables to compute the day of year from yyyymmdd timecode. - * Viva la leap. - */ -static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +#include "ntp_calendar.h" int ymd2yd( int y, int m, - int d - ) + int d) { - int i, *t; - - if (m < 1 || m > 12 || d < 1) - return (-1); - - if (((y%4 == 0) && (y%100 != 0)) || (y%400 == 0)) - t = day2tab; /* leap year */ - else - t = day1tab; /* not a leap year */ - if (d > t[m - 1]) - return (-1); - for (i = 0; i < m - 1; i++) - d += t[i]; - return d; + /* + * convert y/m/d to elapsed calendar units, convert that to + * elapsed days since the start of the given year and convert + * back to unity-based day in year. + * + * This does no further error checking, since the underlying + * function is assumed to work out how to handle the data. + */ + return ntpcal_edate_to_yeardays(y-1, m-1, d-1) + 1; } |