1 /* $NetBSD: ntpd.c,v 1.14 2009/02/03 12:51:13 drochner Exp $ */
4 * ntpd.c - main program for the fixed point NTP daemon
11 #include "ntp_machine.h"
14 #include "ntp_stdlib.h"
15 #include <ntp_random.h>
19 # include "ntpdsim-opts.h"
21 # include "ntpd-opts.h"
27 #ifdef HAVE_SYS_STAT_H
28 # include <sys/stat.h>
31 #if !defined(VMS) /*wjm*/
32 # ifdef HAVE_SYS_PARAM_H
33 # include <sys/param.h>
36 #ifdef HAVE_SYS_SIGNAL_H
37 # include <sys/signal.h>
41 #ifdef HAVE_SYS_IOCTL_H
42 # include <sys/ioctl.h>
43 #endif /* HAVE_SYS_IOCTL_H */
44 #ifdef HAVE_SYS_RESOURCE_H
45 # include <sys/resource.h>
46 #endif /* HAVE_SYS_RESOURCE_H */
47 #if defined(HAVE_RTPRIO)
48 # ifdef HAVE_SYS_RESOURCE_H
49 # include <sys/resource.h>
51 # ifdef HAVE_SYS_LOCK_H
52 # include <sys/lock.h>
54 # include <sys/rtprio.h>
57 # ifdef HAVE_SYS_LOCK_H
58 # include <sys/lock.h>
62 #if defined(HAVE_SCHED_SETSCHEDULER)
66 # ifdef HAVE_SYS_SCHED_H
67 # include <sys/sched.h>
71 #if defined(HAVE_SYS_MMAN_H)
72 # include <sys/mman.h>
80 # include <apollo/base.h>
81 #endif /* SYS_DOMAINOS */
84 #include "ntp_cmdargs.h"
86 #if 0 /* HMS: I don't think we need this. 961223 */
89 # include <sys/mman.h>
91 # include <sys/lock.h>
101 # include <sys/ci/ciioctl.h>
108 #ifdef HAVE_LINUX_CAPABILITIES
109 # include <sys/capability.h>
110 # include <sys/prctl.h>
115 * Signals we catch for debugging. If not debugging we ignore them.
117 #define MOREDEBUGSIG SIGUSR1
118 #define LESSDEBUGSIG SIGUSR2
121 * Signals which terminate us gracefully.
124 # define SIGDIE1 SIGHUP
125 # define SIGDIE3 SIGQUIT
126 # define SIGDIE2 SIGINT
127 # define SIGDIE4 SIGTERM
128 #endif /* SYS_WINNT */
130 #ifdef HAVE_DNSREGISTRATION
136 * Scheduling priority we run at
138 #define NTPD_PRIO (-12)
140 int priority_done
= 2; /* 0 - Set priority */
141 /* 1 - priority is OK where it is */
142 /* 2 - Don't set priority */
143 /* 1 and 2 are pretty much the same */
149 volatile int debug
= 0; /* No debugging by default */
152 int listen_to_virtual_ips
= 1;
153 const char *specific_interface
= NULL
; /* interface name or IP address to bind to */
156 * No-fork flag. If set, we do not become a background daemon.
158 int nofork
= 0; /* Fork by default */
162 char *user
= NULL
; /* User to switch to */
163 char *group
= NULL
; /* group to switch to */
164 char *chrootdir
= NULL
; /* directory to chroot to */
170 #endif /* HAVE_DROPROOT */
173 * Initializing flag. All async routines watch this and only do their
174 * thing when it is clear.
179 * Version declaration
181 extern const char *Version
;
183 char const *progname
;
189 * We put this here, since the argument profile is syscall-specific
191 extern int syscall
P((int, ...));
192 #endif /* DECL_SYSCALL */
196 static RETSIGTYPE finish
P((int));
201 static RETSIGTYPE moredebug
P((int));
202 static RETSIGTYPE lessdebug
P((int));
204 #else /* not DEBUG */
205 static RETSIGTYPE no_debug
P((int));
206 #endif /* not DEBUG */
208 int ntpdmain
P((int, char **));
209 static void set_process_priority
P((void));
210 static void init_logging
P((char const *));
211 static void setup_logfile
P((void));
214 * Initialize the logging
217 init_logging(char const *name
)
222 * Logging. This may actually work on the gizmo board. Find a name
223 * to log with by using the basename
225 cp
= strrchr(name
, '/');
234 openlog(cp
, LOG_PID
);
235 # else /* LOG_DAEMON */
238 # define LOG_NTP LOG_DAEMON
240 openlog(cp
, LOG_PID
| LOG_NDELAY
, LOG_NTP
);
243 setlogmask(LOG_UPTO(LOG_DEBUG
));
246 setlogmask(LOG_UPTO(LOG_DEBUG
)); /* @@@ was INFO */
247 # endif /* LOG_DAEMON */
248 #endif /* !SYS_WINNT && !VMS */
250 NLOG(NLOG_SYSINFO
) /* conditional if clause for conditional syslog */
251 msyslog(LOG_NOTICE
, "%s", Version
);
256 * See if we should redirect the logfile
264 if (HAVE_OPT( LOGFILE
)) {
265 const char *my_optarg
= OPT_ARG( LOGFILE
);
268 if(strcmp(my_optarg
, "stderr") == 0)
270 else if(strcmp(my_optarg
, "stdout") == 0)
273 new_file
= fopen(my_optarg
, "a");
274 if (new_file
!= NULL
) {
276 msyslog(LOG_NOTICE
, "logging to file %s", my_optarg
);
277 if (syslog_file
!= NULL
&&
278 fileno(syslog_file
) != fileno(new_file
))
279 (void)fclose(syslog_file
);
281 syslog_file
= new_file
;
286 "Cannot open log file %s",
298 return ntpsim(argc
, argv
);
301 #ifdef NO_MAIN_ALLOWED
302 CALL(ntpd
,"ntpd",ntpdmain
);
311 return ntpdmain(argc
, argv
);
313 #endif /* SYS_WINNT */
314 #endif /* NO_MAIN_ALLOWED */
319 * OK. AIX is different than solaris in how it implements plock().
320 * If you do NOT adjust the stack limit, you will get the MAXIMUM
321 * stack size allocated and PINNED with you program. To check the
322 * value, use ulimit -a.
324 * To fix this, we create an automatic variable and set our stack limit
325 * to that PLUS 32KB of extra space (we need some headroom).
327 * This subroutine gets the stack address.
329 * Grover Davidson and Matt Ladendorf
340 * Signal handler for SIGDANGER.
343 catch_danger(int signo
)
345 msyslog(LOG_INFO
, "ntpd: setpgid(): %m");
346 /* Make the system believe we'll free something, but don't do it! */
352 * Set the process priority
355 set_process_priority(void)
360 msyslog(LOG_DEBUG
, "set_process_priority: %s: priority_done is <%d>",
362 ? "Leave priority alone"
363 : "Attempt to set priority"
369 priority_done
+= NT_set_process_priority();
372 #if defined(HAVE_SCHED_SETSCHEDULER)
373 if (!priority_done
) {
374 extern int config_priority_override
, config_priority
;
376 struct sched_param sched
;
378 pmax
= sched_get_priority_max(SCHED_FIFO
);
379 sched
.sched_priority
= pmax
;
380 if ( config_priority_override
) {
381 pmin
= sched_get_priority_min(SCHED_FIFO
);
382 if ( config_priority
> pmax
)
383 sched
.sched_priority
= pmax
;
384 else if ( config_priority
< pmin
)
385 sched
.sched_priority
= pmin
;
387 sched
.sched_priority
= config_priority
;
389 if ( sched_setscheduler(0, SCHED_FIFO
, &sched
) == -1 )
390 msyslog(LOG_ERR
, "sched_setscheduler(): %m");
394 #endif /* HAVE_SCHED_SETSCHEDULER */
395 #if defined(HAVE_RTPRIO)
397 if (!priority_done
) {
400 srtp
.type
= RTP_PRIO_REALTIME
; /* was: RTP_PRIO_NORMAL */
401 srtp
.prio
= 0; /* 0 (hi) -> RTP_PRIO_MAX (31,lo) */
403 if (rtprio(RTP_SET
, getpid(), &srtp
) < 0)
404 msyslog(LOG_ERR
, "rtprio() error: %m");
408 # else /* not RTP_SET */
409 if (!priority_done
) {
410 if (rtprio(0, 120) < 0)
411 msyslog(LOG_ERR
, "rtprio() error: %m");
415 # endif /* not RTP_SET */
416 #endif /* HAVE_RTPRIO */
417 #if defined(NTPD_PRIO) && NTPD_PRIO != 0
418 # ifdef HAVE_ATT_NICE
419 if (!priority_done
) {
421 if (-1 == nice (NTPD_PRIO
) && errno
!= 0)
422 msyslog(LOG_ERR
, "nice() error: %m");
426 # endif /* HAVE_ATT_NICE */
427 # ifdef HAVE_BSD_NICE
428 if (!priority_done
) {
429 if (-1 == setpriority(PRIO_PROCESS
, 0, NTPD_PRIO
))
430 msyslog(LOG_ERR
, "setpriority() error: %m");
434 # endif /* HAVE_BSD_NICE */
435 #endif /* NTPD_PRIO && NTPD_PRIO != 0 */
437 msyslog(LOG_ERR
, "set_process_priority: No way found to improve our priority");
442 * Main program. Initialize us, disconnect us from the tty if necessary,
443 * and loop waiting for I/O and/or timer expiries.
452 struct recvbuf
*rbuf
;
453 #ifdef _AIX /* HMS: ifdef SIGDANGER? */
459 initializing
= 1; /* mark that we are initializing */
462 int optct
= optionProcess(
473 /* HMS: is this lame? Should we process -l first? */
475 init_logging(progname
); /* Open the log file */
489 #if defined(HAVE_GETUID) && !defined(MPE) /* MPE lacks the concept of root */
496 msyslog(LOG_ERR
, "ntpd: must be run as root, not uid %ld", (long)uid
);
497 printf("must be run as root, not uid %ld", (long)uid
);
504 if ((SSLeay() ^ OPENSSL_VERSION_NUMBER
) & ~0xff0L
) {
506 "ntpd: OpenSSL version mismatch. Built against %lx, you have %lx\n",
507 (long) OPENSSL_VERSION_NUMBER
, SSLeay());
512 /* getstartup(argc, argv); / * startup configuration, may set debug */
515 debug
= DESC(DEBUG_LEVEL
).optOccCt
;
517 printf("%s\n", Version
);
521 * Enable the Multi-Media Timer for Windows?
524 if (HAVE_OPT( MODIFYMMTIMER
))
525 set_mm_timer(MM_TIMER_HIRES
);
528 if (HAVE_OPT( NOFORK
) || HAVE_OPT( QUIT
))
531 if (HAVE_OPT( NOVIRTUALIPS
))
532 listen_to_virtual_ips
= 0;
534 if (HAVE_OPT( INTERFACE
)) {
536 int ifacect
= STACKCT_OPT( INTERFACE
);
537 char** ifaces
= STACKLST_OPT( INTERFACE
);
539 /* malloc space for the array of names */
540 while (ifacect
-- > 0) {
541 next_iface
= *ifaces
++;
544 specific_interface
= OPT_ARG( INTERFACE
);
548 if (HAVE_OPT( NICE
))
551 #if defined(HAVE_SCHED_SETSCHEDULER)
552 if (HAVE_OPT( PRIORITY
)) {
553 config_priority
= OPT_VALUE_PRIORITY
;
554 config_priority_override
= 1;
561 * Initialize the time structures and variables
569 * Initialize random generator and public key pair
573 ntp_srandom((int)(now
.l_i
* now
.l_uf
));
575 #ifdef HAVE_DNSREGISTRATION
576 /* HMS: does this have to happen this early? */
577 msyslog(LOG_INFO
, "Attemping to register mDNS");
578 if ( DNSServiceRegister (&mdns
, 0, 0, NULL
, "_ntp._udp", NULL
, NULL
, htons(NTP_PORT
), 0, NULL
, NULL
, NULL
) != kDNSServiceErr_NoError
) {
579 msyslog(LOG_ERR
, "Unable to register mDNS");
586 * Detach us from the terminal. May need an #ifndef GIZMO.
597 # else /* not HAVE_DAEMON */
598 if (fork()) /* HMS: What about a -1? */
602 #if !defined(F_CLOSEM)
605 #endif /* not F_CLOSEM */
607 #if defined(F_CLOSEM)
609 * From 'Writing Reliable AIX Daemons,' SG24-4946-00,
610 * by Eric Agar (saves us from doing 32767 system
613 if (fcntl(0, F_CLOSEM
, 0) == -1)
614 msyslog(LOG_ERR
, "ntpd: failed to close open files(): %m");
615 #else /* not F_CLOSEM */
617 # if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
618 max_fd
= sysconf(_SC_OPEN_MAX
);
619 # else /* HAVE_SYSCONF && _SC_OPEN_MAX */
620 max_fd
= getdtablesize();
621 # endif /* HAVE_SYSCONF && _SC_OPEN_MAX */
622 for (s
= 0; s
< max_fd
; s
++)
623 (void) close((int)s
);
624 #endif /* not F_CLOSEM */
633 proc2_$
who_am_i(&puid
);
634 proc2_$
make_server(&puid
, &st
);
636 #endif /* SYS_DOMAINOS */
637 #if defined(HAVE_SETPGID) || defined(HAVE_SETSID)
639 if (setsid() == (pid_t
)-1)
640 msyslog(LOG_ERR
, "ntpd: setsid(): %m");
642 if (setpgid(0, 0) == -1)
643 msyslog(LOG_ERR
, "ntpd: setpgid(): %m");
645 #else /* HAVE_SETPGID || HAVE_SETSID */
647 # if defined(TIOCNOTTY)
650 fid
= open("/dev/tty", 2);
653 (void) ioctl(fid
, (u_long
) TIOCNOTTY
, (char *) 0);
656 # endif /* defined(TIOCNOTTY) */
657 # ifdef HAVE_SETPGRP_0
659 # else /* HAVE_SETPGRP_0 */
660 (void) setpgrp(0, getpid());
661 # endif /* HAVE_SETPGRP_0 */
663 #endif /* HAVE_SETPGID || HAVE_SETSID */
665 /* Don't get killed by low-on-memory signal. */
666 sa
.sa_handler
= catch_danger
;
667 sigemptyset(&sa
.sa_mask
);
668 sa
.sa_flags
= SA_RESTART
;
670 (void) sigaction(SIGDANGER
, &sa
, NULL
);
673 # endif /* not HAVE_DAEMON */
674 # endif /* SYS_WINNT */
676 # endif /* NODETACH */
679 setup_logfile(); /* We lost any redirect when we daemonized */
683 * SCO OpenServer's system clock offers much more precise timekeeping
684 * on the base CPU than the other CPUs (for multiprocessor systems),
685 * so we must lock to the base CPU.
688 int fd
= open("/dev/at1", O_RDONLY
);
691 if (ioctl(fd
, ACPU_LOCK
, &zero
) < 0)
692 msyslog(LOG_ERR
, "cannot lock to base CPU: %m");
695 * If we can't open the device, this probably just isn't
696 * a multiprocessor system, so we're A-OK.
701 #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) && defined(MCL_FUTURE)
702 # ifdef HAVE_SETRLIMIT
704 * Set the stack limit to something smaller, so that we don't lock a lot
705 * of unused stack memory.
710 /* HMS: must make the rlim_cur amount configurable */
711 if (getrlimit(RLIMIT_STACK
, &rl
) != -1
712 && (rl
.rlim_cur
= 50 * 4096) < rl
.rlim_max
)
714 if (setrlimit(RLIMIT_STACK
, &rl
) == -1)
717 "Cannot adjust stack limit for mlockall: %m");
720 # ifdef RLIMIT_MEMLOCK
722 * The default RLIMIT_MEMLOCK is very low on Linux systems.
723 * Unless we increase this limit malloc calls are likely to
724 * fail if we drop root privlege. To be useful the value
725 * has to be larger than the largest ntpd resident set size.
727 rl
.rlim_cur
= rl
.rlim_max
= 32*1024*1024;
728 if (setrlimit(RLIMIT_MEMLOCK
, &rl
) == -1) {
729 msyslog(LOG_ERR
, "Cannot set RLIMIT_MEMLOCK: %m");
731 # endif /* RLIMIT_MEMLOCK */
733 # endif /* HAVE_SETRLIMIT */
735 * lock the process into memory
737 if (mlockall(MCL_CURRENT
|MCL_FUTURE
) < 0)
738 msyslog(LOG_ERR
, "mlockall(): %m");
739 #else /* not (HAVE_MLOCKALL && MCL_CURRENT && MCL_FUTURE) */
744 * set the stack limit for AIX for plock().
745 * see get_aix_stack() for more info.
747 if (ulimit(SET_STACKLIM
, (get_aix_stack() - 8*4096)) < 0)
749 msyslog(LOG_ERR
,"Cannot adjust stack limit for plock on AIX: %m");
753 * lock the process into memory
755 if (plock(PROCLOCK
) < 0)
756 msyslog(LOG_ERR
, "plock(PROCLOCK): %m");
757 # else /* not PROCLOCK */
762 if (plock(TXTLOCK
) < 0)
763 msyslog(LOG_ERR
, "plock(TXTLOCK) error: %m");
764 # else /* not TXTLOCK */
765 msyslog(LOG_ERR
, "plock() - don't know what to lock!");
766 # endif /* not TXTLOCK */
767 # endif /* not PROCLOCK */
768 # endif /* HAVE_PLOCK */
769 #endif /* not (HAVE_MLOCKALL && MCL_CURRENT && MCL_FUTURE) */
772 * Set up signals we pay attention to locally.
775 (void) signal_no_reset(SIGDIE1
, finish
);
778 (void) signal_no_reset(SIGDIE2
, finish
);
781 (void) signal_no_reset(SIGDIE3
, finish
);
784 (void) signal_no_reset(SIGDIE4
, finish
);
788 (void) signal_no_reset(SIGBUS
, finish
);
791 #if !defined(SYS_WINNT) && !defined(VMS)
793 (void) signal_no_reset(MOREDEBUGSIG
, moredebug
);
794 (void) signal_no_reset(LESSDEBUGSIG
, lessdebug
);
796 (void) signal_no_reset(MOREDEBUGSIG
, no_debug
);
797 (void) signal_no_reset(LESSDEBUGSIG
, no_debug
);
799 #endif /* !SYS_WINNT && !VMS */
802 * Set up signals we should never pay attention to.
805 (void) signal_no_reset(SIGPIPE
, SIG_IGN
);
809 * Call the init_ routines to initialize the data structures.
811 * Exactly what command-line options are we expecting here?
825 set_process_priority();
826 init_proto(); /* Call at high priority */
829 mon_start(MON_ON
); /* monitor on by default now */
830 /* turn off in config if unwanted */
833 * Get the configuration. This is done in a separate module
834 * since this will definitely be different for the gizmo board.
837 getconfig(argc
, argv
);
839 loop_config(LOOP_DRIFTCOMP
, old_drift
/ 1e6
);
847 /* Drop super-user privileges and chroot now if the OS supports this */
849 #ifdef HAVE_LINUX_CAPABILITIES
850 /* set flag: keep privileges accross setuid() call (we only really need cap_sys_time): */
851 if( prctl( PR_SET_KEEPCAPS
, 1L, 0L, 0L, 0L ) == -1 ) {
852 msyslog( LOG_ERR
, "prctl( PR_SET_KEEPCAPS, 1L ) failed: %m" );
856 /* we need a user to switch to */
858 msyslog(LOG_ERR
, "Need user name to drop root privileges (see -u flag!)" );
861 #endif /* HAVE_LINUX_CAPABILITIES */
864 if (isdigit((unsigned char)*user
)) {
865 sw_uid
= (uid_t
)strtoul(user
, &endp
, 0);
870 if ((pw
= getpwnam(user
)) != NULL
) {
874 msyslog(LOG_ERR
, "Cannot find user `%s'", user
);
880 if (isdigit((unsigned char)*group
)) {
881 sw_gid
= (gid_t
)strtoul(group
, &endp
, 0);
886 if ((gr
= getgrnam(group
)) != NULL
) {
890 msyslog(LOG_ERR
, "Cannot find group `%s'", group
);
897 /* make sure cwd is inside the jail: */
898 if( chdir(chrootdir
) ) {
899 msyslog(LOG_ERR
, "Cannot chdir() to `%s': %m", chrootdir
);
902 if( chroot(chrootdir
) ) {
903 msyslog(LOG_ERR
, "Cannot chroot() to `%s': %m", chrootdir
);
907 if (group
&& setgid(sw_gid
)) {
908 msyslog(LOG_ERR
, "Cannot setgid() to group `%s': %m", group
);
911 if (group
&& setegid(sw_gid
)) {
912 msyslog(LOG_ERR
, "Cannot setegid() to group `%s': %m", group
);
916 setgroups(1, &sw_gid
);
918 initgroups(pw
->pw_name
, pw
->pw_gid
);
919 if (user
&& setuid(sw_uid
)) {
920 msyslog(LOG_ERR
, "Cannot setuid() to user `%s': %m", user
);
923 if (user
&& seteuid(sw_uid
)) {
924 msyslog(LOG_ERR
, "Cannot seteuid() to user `%s': %m", user
);
928 #ifndef HAVE_LINUX_CAPABILITIES
930 * for now assume that the privilege to bind to privileged ports
931 * is associated with running with uid 0 - should be refined on
932 * ports that allow binding to NTP_PORT with uid != 0
934 disable_dynamic_updates
|= (sw_uid
!= 0); /* also notifies routing message listener */
937 if (disable_dynamic_updates
&& interface_interval
) {
938 interface_interval
= 0;
939 msyslog(LOG_INFO
, "running in unprivileged mode disables dynamic interface tracking");
942 #ifdef HAVE_LINUX_CAPABILITIES
945 * We may be running under non-root uid now, but we still hold full root privileges!
946 * We drop all of them, except for the crucial one or two: cap_sys_time and
947 * cap_net_bind_service if doing dynamic interface tracking.
950 char *captext
= interface_interval
?
951 "cap_sys_time,cap_net_bind_service=ipe" :
953 if( ! ( caps
= cap_from_text( captext
) ) ) {
954 msyslog( LOG_ERR
, "cap_from_text() failed: %m" );
957 if( cap_set_proc( caps
) == -1 ) {
958 msyslog( LOG_ERR
, "cap_set_proc() failed to drop root privileges: %m" );
963 #endif /* HAVE_LINUX_CAPABILITIES */
965 } /* if( droproot ) */
966 #endif /* HAVE_DROPROOT */
969 * Report that we're up to any trappers
971 report_event(EVNT_SYSRESTART
, (struct peer
*)0);
974 * Use select() on all on all input fd's for unlimited
975 * time. select() will terminate on SIGALARM or on the
976 * reception of input. Using select() means we can't do
977 * robust signal handling and we get a potential race
978 * between checking for alarms and doing the select().
979 * Mostly harmless, I think.
981 /* On VMS, I suspect that select() can't be interrupted
982 * by a "signal" either, so I take the easy way out and
983 * have select() time out after one second.
984 * System clock updates really aren't time-critical,
985 * and - lacking a hardware reference clock - I have
986 * yet to learn about anything else that is.
988 #if defined(HAVE_IO_COMPLETION_PORT)
991 GetReceivedBuffers();
992 #else /* normal I/O */
994 BLOCK_IO_AND_ALARM();
998 # if !defined(HAVE_SIGNALED_IO)
999 extern fd_set activefds
;
1000 extern int maxactivefd
;
1006 if (alarm_flag
) /* alarmed? */
1012 if (!was_alarmed
&& has_full_recv_buffer() == ISC_FALSE
)
1015 * Nothing to do. Wait for something.
1017 # ifndef HAVE_SIGNALED_IO
1019 # if defined(VMS) || defined(SYS_VXWORKS)
1020 /* make select() wake up after one second */
1024 t1
.tv_sec
= 1; t1
.tv_usec
= 0;
1025 nfound
= select(maxactivefd
+1, &rdfdes
, (fd_set
*)0,
1029 nfound
= select(maxactivefd
+1, &rdfdes
, (fd_set
*)0,
1030 (fd_set
*)0, (struct timeval
*)0);
1038 (void)input_handler(&ts
);
1040 else if (nfound
== -1 && errno
!= EINTR
)
1041 netsyslog(LOG_ERR
, "select() error: %m");
1044 netsyslog(LOG_DEBUG
, "select(): nfound=%d, error: %m", nfound
);
1046 # else /* HAVE_SIGNALED_IO */
1049 # endif /* HAVE_SIGNALED_IO */
1050 if (alarm_flag
) /* alarmed? */
1059 UNBLOCK_IO_AND_ALARM();
1061 * Out here, signals are unblocked. Call timer routine
1062 * to process expiry.
1066 BLOCK_IO_AND_ALARM();
1069 #endif /* HAVE_IO_COMPLETION_PORT */
1080 rbuf
= get_full_recv_buffer();
1081 while (rbuf
!= NULL
)
1088 UNBLOCK_IO_AND_ALARM();
1091 { /* avoid timer starvation during lengthy I/O handling */
1097 * Call the data procedure to handle each received
1100 if (rbuf
->receiver
!= NULL
) /* This should always be true */
1105 L_SUB(&dts
, &rbuf
->recv_time
);
1106 DPRINTF(2, ("processing timestamp delta %s (with prec. fuzz)\n", lfptoa(&dts
, 9)));
1107 collect_timing(rbuf
, "buffer processing delay", 1, &dts
);
1110 (rbuf
->receiver
)(rbuf
);
1112 msyslog(LOG_ERR
, "receive buffer corruption - receiver found to be NULL - ABORTING");
1116 BLOCK_IO_AND_ALARM();
1118 rbuf
= get_full_recv_buffer();
1124 collect_timing(NULL
, "processing", bufcount
, &tsb
);
1125 DPRINTF(2, ("processing time for %d buffers %s\n", bufcount
, lfptoa(&tsb
, 9)));
1134 UNBLOCK_IO_AND_ALARM();
1141 * finish - exit gracefully
1149 msyslog(LOG_NOTICE
, "ntpd exiting on signal %d", sig
);
1151 #ifdef HAVE_DNSREGISTRATION
1153 DNSServiceRefDeallocate(mdns
);
1160 printf("\nfinish(SIGBUS)\n");
1163 case 0: /* Should never happen... */
1169 #endif /* SIGDIE2 */
1175 * moredebug - increase debugging verbosity
1182 int saved_errno
= errno
;
1187 msyslog(LOG_DEBUG
, "debug raised to %d", debug
);
1189 errno
= saved_errno
;
1193 * lessdebug - decrease debugging verbosity
1200 int saved_errno
= errno
;
1205 msyslog(LOG_DEBUG
, "debug lowered to %d", debug
);
1207 errno
= saved_errno
;
1210 #else /* not DEBUG */
1213 * no_debug - We don't do the debug here.
1220 int saved_errno
= errno
;
1222 msyslog(LOG_DEBUG
, "ntpd not compiled for debugging (signal %d)", sig
);
1223 errno
= saved_errno
;
1225 #endif /* not SYS_WINNT */
1226 #endif /* not DEBUG */