stoddard 00/02/09 14:16:32
Modified: src/os/win32 service.c main_win32.c Log: Fix some bugs with running Apache as a service Submitted by: Allan Edwards <[EMAIL PROTECTED]> Reviewed by: Bill Stoddard <[EMAIL PROTECTED]> Revision Changes Path 1.3 +41 -3 apache-2.0/src/os/win32/service.c Index: service.c =================================================================== RCS file: /home/cvs/apache-2.0/src/os/win32/service.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- service.c 1999/12/08 22:34:02 1.2 +++ service.c 2000/02/09 22:16:17 1.3 @@ -61,6 +61,7 @@ #include <stdlib.h> #include <direct.h> +#define CORE_PRIVATE #include "httpd.h" #include "http_conf_globals.h" #include "http_log.h" @@ -78,6 +79,7 @@ int exit_status; SERVICE_STATUS ssStatus; FILE *logFile; + char *service_dir; } globdat; static void WINAPI service_main_fn(DWORD, LPTSTR *); @@ -97,6 +99,7 @@ globdat.main_fn = main_fn; globdat.stop_event = CreateEvent(NULL, 0, 0, "apache-signal"); globdat.connected = 1; + globdat.service_dir = argv[0]; if(!StartServiceCtrlDispatcher(dispatchTable)) { @@ -122,7 +125,23 @@ void __stdcall service_main_fn(DWORD argc, LPTSTR *argv) { + int i, new_argc; + char **new, *server_root, *tmp; + char *server_confname = SERVER_CONFIG_FILE; + ap_array_header_t *cmdtbl; + ap_context_t *pwincmd; + + ap_create_context(&pwincmd, NULL); + if (pwincmd == NULL) { + exit(0); + } + ap_server_argv0 = globdat.name = argv[0]; + cmdtbl = ap_make_array(pwincmd, 1, sizeof(char *)); + + server_root = ap_pstrdup(pwincmd, globdat.service_dir); + tmp = strrchr(server_root, '\\'); + *tmp = '\0'; if(!(globdat.hServiceStatus = RegisterServiceCtrlHandler( globdat.name, service_ctrl))) { @@ -137,9 +156,28 @@ 3000); // wait hint service_cd(); -// if( service_init() ) - /* Arguments are ok except for \! */ - globdat.exit_status = (*globdat.main_fn)( argc, argv ); + + /* Fetch server_conf from the registry + * Rebuild argv and argc adding the -d server_root and -f server_conf then + * call apache_main + */ + ap_registry_get_service_conf(pwincmd, &server_confname, argv[0]); + for (i = 0; i < argc ; i++) { + new = (char **) ap_push_array(cmdtbl); + *new = argv[i]; + } + /* Add server_confname to the argument list */ + new = (char **) ap_push_array(cmdtbl); + *new = "-f"; + new = (char **) ap_push_array(cmdtbl); + *new = server_confname; + new = (char **) ap_push_array(cmdtbl); + *new = "-d"; + new = (char **) ap_push_array(cmdtbl); + *new = server_root; + new_argc = argc + 4; + + globdat.exit_status = (*globdat.main_fn)( new_argc, (char**) cmdtbl->elts ); ReportStatusToSCMgr(SERVICE_STOPPED, NO_ERROR, 0); 1.6 +1 -21 apache-2.0/src/os/win32/main_win32.c Index: main_win32.c =================================================================== RCS file: /home/cvs/apache-2.0/src/os/win32/main_win32.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- main_win32.c 2000/01/23 16:37:46 1.5 +++ main_win32.c 2000/02/09 22:16:24 1.6 @@ -120,27 +120,7 @@ * HKLM\System\CurrentControlSet\Services\[Svc name]\Parameters\ConfPath */ if (isProcessService()) { - /* Fetch server_conf from the registry - * Rebuild argv and argc adding the -d server_root and -f server_conf then - * call service_main - */ - int i; - ap_registry_get_service_conf(pwincmd, &server_confname, argv[0]); - for (i = 0; i < argc ; i++) { - new = (char **) ap_push_array(cmdtbl); - *new = argv[i]; - } - /* Add server_confname to the argument list */ - new = (char **) ap_push_array(cmdtbl); - *new = "-f"; - new = (char **) ap_push_array(cmdtbl); - *new = server_confname; - new = (char **) ap_push_array(cmdtbl); - *new = "-d"; - new = (char **) ap_push_array(cmdtbl); - *new = server_root; - argc += 4; - service_main(apache_main, new_argc, (char**) cmdtbl->elts); + service_main(apache_main, argc, argv); exit(0); }