From: Dave Hart Date: Sun, 19 Apr 2009 17:50:29 +0000 (+0000) Subject: ntp_intres.c, ntpd.h, ChangeLog, ntp_config.c: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d76e58b32c45a4f330c75a52cb58eebc73864e8b;p=thirdparty%2Fntp.git ntp_intres.c, ntpd.h, ChangeLog, ntp_config.c: [Bug 1125] C runtime per-thread initialization on Windows bk: 49eb6465V9XFfrUiblqHJpo1LAJRqg --- diff --git a/ChangeLog b/ChangeLog index 3ebfe866a9..e3d79b1e0e 100644 --- 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 (4.2.5p162) 2009/04/09 Released by Harlan Stenn * Documentation updates from Dave Mills. diff --git a/include/ntpd.h b/include/ntpd.h index b61bcad090..fc282796b5 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -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 { diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 105e6a0347..ad44481ed9 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -45,7 +45,6 @@ #ifdef SYS_WINNT # include -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(); diff --git a/ntpd/ntp_intres.c b/ntpd/ntp_intres.c index 7d2e96df7d..1ff059aac5 100644 --- a/ntpd/ntp_intres.c +++ b/ntpd/ntp_intres.c @@ -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