aboutsummaryrefslogtreecommitdiff
path: root/contrib/ntp/ntpd/ntpd.c
diff options
context:
space:
mode:
authorOllivier Robert <roberto@FreeBSD.org>2000-01-28 14:55:50 +0000
committerOllivier Robert <roberto@FreeBSD.org>2000-01-28 14:55:50 +0000
commita151a66c2a1c722d095dfdd6a06d8acd74a03253 (patch)
tree98efdf1b74d6ecb7828bb502a0350116eeb2fd3c /contrib/ntp/ntpd/ntpd.c
parentc0b746e5e8d9479f05b3749cbf1f73b8928719bd (diff)
downloadsrc-a151a66c2a1c722d095dfdd6a06d8acd74a03253.tar.gz
src-a151a66c2a1c722d095dfdd6a06d8acd74a03253.zip
Virgin import of ntpd 4.0.99b
Notes
Notes: svn path=/vendor/ntp/dist/; revision=56746
Diffstat (limited to 'contrib/ntp/ntpd/ntpd.c')
-rw-r--r--contrib/ntp/ntpd/ntpd.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/contrib/ntp/ntpd/ntpd.c b/contrib/ntp/ntpd/ntpd.c
index 923b1f702653..3dbef6074263 100644
--- a/contrib/ntp/ntpd/ntpd.c
+++ b/contrib/ntp/ntpd/ntpd.c
@@ -108,13 +108,13 @@
#define SIGDIE4 SIGTERM
#endif /* SYS_WINNT */
-#if defined SYS_WINNT || defined SYS_CYGWIN32
+#if defined SYS_WINNT
/* handles for various threads, process, and objects */
HANDLE ResolverThreadHandle = NULL;
/* variables used to inform the Service Control Manager of our current state */
SERVICE_STATUS ssStatus;
SERVICE_STATUS_HANDLE sshStatusHandle;
-HANDLE WaitHandles[3] = { NULL, NULL, NULL };
+HANDLE WaitHandles[2] = { NULL, NULL };
char szMsgPath[255];
static BOOL WINAPI OnConsoleEvent(DWORD dwCtrlType);
#endif /* SYS_WINNT */
@@ -122,11 +122,7 @@ static BOOL WINAPI OnConsoleEvent(DWORD dwCtrlType);
/*
* Scheduling priority we run at
*/
-#if !defined SYS_WINNT
# define NTPD_PRIO (-12)
-#else
-# define NTPD_PRIO REALTIME_PRIORITY_CLASS
-#endif
/*
* Debugging flag
@@ -230,13 +226,35 @@ set_process_priority(void)
int done = 0;
#ifdef SYS_WINNT
+ DWORD SingleCPUMask = 0;
+ DWORD ProcessAffinityMask, SystemAffinityMask;
+ if (!GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask, &SystemAffinityMask))
+ msyslog(LOG_ERR, "GetProcessAffinityMask: %m");
+ else {
+ SingleCPUMask = 1;
+# ifdef DEBUG
+ msyslog(LOG_INFO, "System AffinityMask = %x", SystemAffinityMask );
+# endif
+ }
+ while (SingleCPUMask && !(SingleCPUMask & SystemAffinityMask)) {
+ SingleCPUMask = SingleCPUMask << 1;
+ }
+
+ if (!SingleCPUMask)
+ msyslog(LOG_ERR, "Can't set Processor Affinity Mask");
+ else if (!SetProcessAffinityMask(GetCurrentProcess(), SingleCPUMask))
+ msyslog(LOG_ERR, "SetProcessAffinityMask: %m");
+# ifdef DEBUG
+ else msyslog(LOG_INFO,"ProcessorAffinity Mask: %x", SingleCPUMask );
+# endif
+
if (!SetPriorityClass(GetCurrentProcess(), (DWORD) REALTIME_PRIORITY_CLASS))
msyslog(LOG_ERR, "SetPriorityClass: %m");
else
++done;
-#else /* not SYS_WINNT */
-# if defined(HAVE_SCHED_SETSCHEDULER)
+#endif
+# if defined(HAVE_SCHED_SETSCHEDULER)
if (!done) {
extern int config_priority_override, config_priority;
int pmax, pmin;
@@ -300,11 +318,11 @@ set_process_priority(void)
}
# endif /* HAVE_BSD_NICE */
# endif /* NTPD_PRIO && NTPD_PRIO != 0 */
-#endif /* not SYS_WINNT */
if (!done)
msyslog(LOG_ERR, "set_process_priority: No way found to improve our priority");
}
+
/*
* Main program. Initialize us, disconnect us from the tty if necessary,
* and loop waiting for I/O and/or timer expiries.
@@ -549,7 +567,6 @@ service_main(
# define LOG_NTP LOG_DAEMON
# endif
openlog(cp, LOG_PID | LOG_NDELAY, LOG_NTP);
-#ifndef SYS_CYGWIN32
# ifdef DEBUG
if (debug)
setlogmask(LOG_UPTO(LOG_DEBUG));
@@ -557,8 +574,6 @@ service_main(
# endif /* DEBUG */
setlogmask(LOG_UPTO(LOG_DEBUG)); /* @@@ was INFO */
# endif /* LOG_DAEMON */
-#endif
-
#endif /* !SYS_WINNT && !VMS */
NLOG(NLOG_SYSINFO) /* conditional if clause for conditional syslog */
@@ -669,7 +684,7 @@ service_main(
/*
* Set up signals we should never pay attention to.
*/
-#if defined SIGPIPE && !defined SYS_CYGWIN32
+#if defined SIGPIPE
(void) signal_no_reset(SIGPIPE, SIG_IGN);
#endif /* SIGPIPE */
@@ -759,33 +774,20 @@ service_main(
* yet to learn about anything else that is.
*/
# if defined(HAVE_IO_COMPLETION_PORT)
- {
WaitHandles[0] = CreateEvent(NULL, FALSE, FALSE, NULL); /* exit reques */
- WaitHandles[1] = get_recv_buff_event();
- WaitHandles[2] = get_timer_handle();
+ WaitHandles[1] = get_timer_handle();
for (;;) {
- DWORD Index = MsgWaitForMultipleObjectsEx(sizeof(WaitHandles)/sizeof(WaitHandles[0]), WaitHandles, INFINITE, QS_ALLEVENTS, MWMO_ALERTABLE);
+ DWORD Index = WaitForMultipleObjectsEx(sizeof(WaitHandles)/sizeof(WaitHandles[0]), WaitHandles, FALSE, 1000, MWMO_ALERTABLE);
switch (Index) {
case WAIT_OBJECT_0 + 0 : /* exit request */
exit(0);
break;
- case WAIT_OBJECT_0 + 1 : {/* recv buffer */
- if (NULL != (rbuf = get_full_recv_buffer())) {
- if (rbuf->receiver != NULL) {
- rbuf->receiver(rbuf);
- }
- freerecvbuf(rbuf);
- }
- }
- break;
-
- case WAIT_OBJECT_0 + 2 : /* 1 second timer */
+ case WAIT_OBJECT_0 + 1 : /* timer */
timer();
break;
-
- case WAIT_OBJECT_0 + 3 : { /* Windows message */
+ case WAIT_OBJECT_0 + 2 : { /* Windows message */
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
@@ -800,10 +802,9 @@ service_main(
case WAIT_TIMEOUT :
break;
- }
+ } /* switch */
+ rbuflist = getrecvbufs(); /* get received buffers */
- }
- }
# else /* normal I/O */
was_alarmed = 0;
@@ -858,7 +859,7 @@ service_main(
else if (nfound == -1 && errno != EINTR)
msyslog(LOG_ERR, "select() error: %m");
else if (debug) {
-# if !defined SYS_VXWORKS && !defined SYS_CYGWIN32 && !defined SCO5_CLOCK /* to unclutter log */
+# if !defined SYS_VXWORKS && !defined SCO5_CLOCK /* to unclutter log */
msyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
# endif
}
@@ -887,6 +888,7 @@ service_main(
was_alarmed = 0;
}
+# endif /* HAVE_IO_COMPLETION_PORT */
/*
* Call the data procedure to handle each received
* packet.
@@ -908,7 +910,6 @@ service_main(
* Go around again
*/
}
-# endif /* HAVE_IO_COMPLETION_PORT */
exit(1); /* unreachable */
return 1; /* DEC OSF cc braindamage */
}