]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ntp_intres.c, ntpd.h, ChangeLog, ntp_config.c:
authorDave Hart <hart@ntp.org>
Sun, 19 Apr 2009 17:50:29 +0000 (17:50 +0000)
committerDave Hart <hart@ntp.org>
Sun, 19 Apr 2009 17:50:29 +0000 (17:50 +0000)
  [Bug 1125] C runtime per-thread initialization on Windows

bk: 49eb6465V9XFfrUiblqHJpo1LAJRqg

ChangeLog
include/ntpd.h
ntpd/ntp_config.c
ntpd/ntp_intres.c

index 3ebfe866a9b389a897d30ed630635845898d7d45..e3d79b1e0eea485ae2223d14e25df979704658d5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 1125] C runtime per-thread initialization on Windows
 (4.2.5p163) 2009/04/10 Released by Harlan Stenn <stenn@ntp.org>
 (4.2.5p162) 2009/04/09 Released by Harlan Stenn <stenn@ntp.org>
 * Documentation updates from Dave Mills.
index b61bcad0902984a8d66f6f53a59396e8583420ce..fc282796b57a4163091e4c4b3a83584b3d386368 100644 (file)
@@ -62,6 +62,9 @@ extern  void    set_sys_var (const char *, u_long, u_short);
 extern void    ntp_res_name    (struct sockaddr_storage, u_short);
 extern void    ntp_res_recv    (void);
 extern void    ntp_intres      (void);
+#ifdef SYS_WINNT
+extern unsigned WINAPI ntp_intres_thread       (void *);
+#endif
 
 /* ntp_io.c */
 typedef struct interface_info {
index 105e6a03471d114cb677ed6e7474ec32e3e5133d..ad44481ed92bec1fa4f857fd3606a89808361a45 100644 (file)
@@ -45,7 +45,6 @@
 
 #ifdef SYS_WINNT
 # include <io.h>
-static HANDLE ResolverThreadHandle = NULL;
 HANDLE ResolverEventHandle;
 #else
 int resolver_pipe_fd[2];  /* used to let the resolver process alert the parent process */
@@ -2725,22 +2724,24 @@ do_resolve_internal(void)
                 * of the new process is an executable filename rather than
                 * a function name as desired here.
                 */
-               DWORD dwThreadId;
+               unsigned thread_id;
+               uintptr_t res_thd_handle;
+
                fflush(stdout);
                ResolverEventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
                if (ResolverEventHandle == NULL) {
                        msyslog(LOG_ERR, "Unable to create resolver event object, can't start ntp_intres");
                        abort_resolve();
                }
-               ResolverThreadHandle = CreateThread(
-                   NULL,                        /* no security attributes      */
-                   0,                           /* use default stack size      */
-                   (LPTHREAD_START_ROUTINE) ntp_intres, /* thread function             */
-                   NULL,                        /* argument to thread function   */
-                   0,                           /* use default creation flags    */
-                   &dwThreadId);                /* returns the thread identifier */
-               if (ResolverThreadHandle == NULL) {
-                       msyslog(LOG_ERR, "CreateThread() failed, can't start ntp_intres");
+               res_thd_handle = _beginthreadex(
+                       NULL,                   /* no security attributes       */
+                       0,                      /* use default stack size       */
+                       ntp_intres_thread,      /* thread function              */
+                       NULL,                   /* argument to thread function  */
+                       0,                      /* use default creation flags   */
+                       &thread_id);            /* receives thread identifier   */
+               if (!res_thd_handle) {
+                       msyslog(LOG_ERR, "_beginthreadex ntp_intres_thread failed %m");
                        CloseHandle(ResolverEventHandle);
                        ResolverEventHandle = NULL;
                        abort_resolve();
index 7d2e96df7dd923279941b36d1247fabb375cda86..1ff059aac5cbec43b7b4f8315cbffbfc599483f4 100644 (file)
@@ -185,7 +185,7 @@ static void resolver_exit (int code)
 #ifdef SYS_WINNT
        CloseHandle(ResolverEventHandle);
        ResolverEventHandle = NULL;
-       ExitThread(code);       /* Just to kill the thread not the process */
+       _endthreadex(code);     /* Just to kill the thread not the process */
 #else
        exit(code);             /* kill the forked process */
 #endif
@@ -335,6 +335,21 @@ ntp_intres(void)
 }
 
 
+#ifdef SYS_WINNT
+/*
+ * ntp_intres_thread wraps the slightly different interface of Windows
+ * thread functions and ntp_intres
+ */
+unsigned WINAPI
+ntp_intres_thread(void *UnusedThreadArg)
+{
+       UNUSED_ARG(UnusedThreadArg);
+
+       ntp_intres();
+       return 0;
+}
+#endif /* SYS_WINNT */
+
 
 /*
  * checkparent - see if our parent process is still running