Initialize the main thread trampoline for Windows Service process
When BIND is running as a Windows Service the ISC library's initializations initiated by the DLLMain loading procedure are happening under the Windows Service Manager thread instead of BIND's main thread. This commit will make sure that BIND's main thread trampoline has been initialized before running the main() function.
This commit is contained in:
committed by
Arаm Sаrgsyаn
parent
05ce4af871
commit
ec64f4492b
@@ -30,11 +30,22 @@ static char ConsoleTitle[128];
|
||||
/*
|
||||
* Forward declarations
|
||||
*/
|
||||
static int
|
||||
bindmain_service_wrapper(int argc, char *argv[]);
|
||||
void
|
||||
ServiceControl(DWORD dwCtrlCode);
|
||||
int
|
||||
bindmain(int, char *[]); /* From main.c */
|
||||
|
||||
/*
|
||||
* Initialize the ISC library running as a Windows Service before calling
|
||||
* bindmain()
|
||||
*/
|
||||
static int
|
||||
bindmain_service_wrapper(int argc, char *argv[]) {
|
||||
return (isc_lib_ntservice(bindmain, argc, argv));
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the Service by registering it.
|
||||
*/
|
||||
@@ -60,6 +71,7 @@ void
|
||||
ntservice_shutdown(void) {
|
||||
UpdateSCM(SERVICE_STOPPED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Routine to check if this is a service or a foreground program
|
||||
*/
|
||||
@@ -67,6 +79,7 @@ BOOL
|
||||
ntservice_isservice(void) {
|
||||
return (!foreground);
|
||||
}
|
||||
|
||||
/*
|
||||
* ServiceControl(): Handles requests from the SCM and passes them on
|
||||
* to named.
|
||||
@@ -159,7 +172,7 @@ main(int argc, char *argv[]) {
|
||||
|
||||
SERVICE_TABLE_ENTRY dispatchTable[] = {
|
||||
{ TEXT(SERVICE_NAME),
|
||||
(LPSERVICE_MAIN_FUNCTION)bindmain },
|
||||
(LPSERVICE_MAIN_FUNCTION)bindmain_service_wrapper },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
@@ -27,10 +27,19 @@ isc_lib_register(void);
|
||||
* function very early in main().
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
int
|
||||
isc_lib_ntservice(int(WINAPI *mainfunc)(int argc, char *argv[]), int argc,
|
||||
char *argv[]);
|
||||
/*!<
|
||||
* \brief Execute a special routine needed when running as a Windows Service.
|
||||
*/
|
||||
#endif /* ifdef WIN32 */
|
||||
|
||||
extern void
|
||||
isc_enable_constructors(void);
|
||||
/*!<
|
||||
* \bried Enable constructor linkage in non-libtool static builds
|
||||
* \brief Enable constructor linkage in non-libtool static builds.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
@@ -34,6 +34,23 @@ isc_lib_register(void) {
|
||||
isc_bind9 = false;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int
|
||||
isc_lib_ntservice(int(WINAPI *mainfunc)(int argc, char *argv[]), int argc,
|
||||
char *argv[]) {
|
||||
isc__trampoline_t *trampoline = isc__trampoline_get(NULL, NULL);
|
||||
int r;
|
||||
|
||||
isc__trampoline_attach(trampoline);
|
||||
|
||||
r = mainfunc(argc, argv);
|
||||
|
||||
isc__trampoline_detach(trampoline);
|
||||
|
||||
return (r);
|
||||
}
|
||||
#endif /* ifdef WIN32 */
|
||||
|
||||
void
|
||||
isc__initialize(void) ISC_CONSTRUCTOR;
|
||||
void
|
||||
|
||||
+13
-8
@@ -154,8 +154,8 @@ done:
|
||||
return (trampoline);
|
||||
}
|
||||
|
||||
static void
|
||||
trampoline_put(isc__trampoline_t *trampoline) {
|
||||
void
|
||||
isc__trampoline_detach(isc__trampoline_t *trampoline) {
|
||||
LOCK(&isc__trampoline_lock);
|
||||
REQUIRE(trampoline->tid > 0 &&
|
||||
(size_t)trampoline->tid < isc__trampoline_max);
|
||||
@@ -174,11 +174,8 @@ trampoline_put(isc__trampoline_t *trampoline) {
|
||||
return;
|
||||
}
|
||||
|
||||
isc_threadresult_t
|
||||
isc__trampoline_run(isc_threadarg_t arg) {
|
||||
isc__trampoline_t *trampoline = (isc__trampoline_t *)arg;
|
||||
isc_threadresult_t result;
|
||||
|
||||
void
|
||||
isc__trampoline_attach(isc__trampoline_t *trampoline) {
|
||||
REQUIRE(trampoline->tid > 0 &&
|
||||
(size_t)trampoline->tid < isc__trampoline_max);
|
||||
REQUIRE(trampoline->self == ISC__TRAMPOLINE_UNUSED);
|
||||
@@ -186,11 +183,19 @@ isc__trampoline_run(isc_threadarg_t arg) {
|
||||
/* Initialize the trampoline */
|
||||
isc_tid_v = trampoline->tid;
|
||||
trampoline->self = isc_thread_self();
|
||||
}
|
||||
|
||||
isc_threadresult_t
|
||||
isc__trampoline_run(isc_threadarg_t arg) {
|
||||
isc__trampoline_t *trampoline = (isc__trampoline_t *)arg;
|
||||
isc_threadresult_t result;
|
||||
|
||||
isc__trampoline_attach(trampoline);
|
||||
|
||||
/* Run the main function */
|
||||
result = (trampoline->start)(trampoline->arg);
|
||||
|
||||
trampoline_put(trampoline);
|
||||
isc__trampoline_detach(trampoline);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,17 @@ isc__trampoline_get(isc_threadfunc_t start_routine, isc_threadarg_t arg);
|
||||
*\li 'start_routine' is a valid non-NULL thread start_routine
|
||||
*/
|
||||
|
||||
void
|
||||
isc__trampoline_attach(isc__trampoline_t *trampoline);
|
||||
void
|
||||
isc__trampoline_detach(isc__trampoline_t *trampoline);
|
||||
/*%<
|
||||
* Attach/detach the trampoline to/from the current thread.
|
||||
*
|
||||
* Requires:
|
||||
* \li 'trampoline' is a valid isc__trampoline_t
|
||||
*/
|
||||
|
||||
isc_threadresult_t
|
||||
isc__trampoline_run(isc_threadarg_t arg);
|
||||
/*%<
|
||||
|
||||
@@ -329,6 +329,7 @@ isc_lfsr_generate
|
||||
isc_lfsr_generate32
|
||||
isc_lfsr_init
|
||||
isc_lfsr_skip
|
||||
isc_lib_ntservice
|
||||
isc_lib_register
|
||||
isc_log_categorybyname
|
||||
isc_log_closefilelogs
|
||||
|
||||
Reference in New Issue
Block a user