diff options
-rw-r--r-- | Apache.dsp | 23 | ||||
-rw-r--r-- | ApacheCore.def | 17 | ||||
-rw-r--r-- | ApacheCore.dsp | 16 | ||||
-rw-r--r-- | httpd.dsp | 16 | ||||
-rw-r--r-- | include/http_config.h | 1 | ||||
-rw-r--r-- | libhttpd.def | 17 | ||||
-rw-r--r-- | os/win32/os.h | 2 | ||||
-rw-r--r-- | server/main.c | 4 | ||||
-rw-r--r-- | server/mpm/winnt/mpm_winnt.c | 17 | ||||
-rw-r--r-- | server/mpm/winnt/service.c | 63 |
10 files changed, 119 insertions, 57 deletions
diff --git a/Apache.dsp b/Apache.dsp index d115a35406..1e7180ce8b 100644 --- a/Apache.dsp +++ b/Apache.dsp @@ -90,10 +90,26 @@ LINK32=link.exe SOURCE=.\os\win32\main_win32.c # End Source File +# Begin Source File + +SOURCE=.\os\win32\registry.c +# End Source File +# Begin Source File + +SOURCE=.\os\win32\service.c +# End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd" +# Begin Source File + +SOURCE=.\os\win32\registry.h +# End Source File +# Begin Source File + +SOURCE=.\os\win32\service.h +# End Source File # End Group # Begin Group "Resource Files" @@ -105,6 +121,13 @@ SOURCE=.\os\win32\apache.ico # Begin Source File SOURCE=.\os\win32\apache.rc + +!IF "$(CFG)" == "Apache - Win32 Release" + +!ELSEIF "$(CFG)" == "Apache - Win32 Debug" + +!ENDIF + # End Source File # End Group # End Target diff --git a/ApacheCore.def b/ApacheCore.def index 627160c00b..68836fc32d 100644 --- a/ApacheCore.def +++ b/ApacheCore.def @@ -369,18 +369,18 @@ EXPORTS regerror @364 ap_send_error_response @365 ap_start_shutdown @366 - send_signal_to_service @367 +; send_signal_to_service @367 ap_read_config @368 ap_server_pre_read_config @369 ap_server_post_read_config @370 ap_setup_prelinked_modules @371 - RemoveService @372 - InstallService @373 - isValidService @374 - service_main @375 - isProcessService @376 - ap_registry_get_server_root @377 - ap_registry_get_service_conf @378 +; RemoveService @372 +; InstallService @373 +; isValidService @374 +; service_main @375 +; isProcessService @376 +; ap_registry_get_server_root @377 +; ap_registry_get_service_conf @378 ap_hook_pre_connection @379 ap_hook_post_read_request @380 ap_hook_log_transaction @381 @@ -399,3 +399,4 @@ EXPORTS ap_run_http_method @394 ap_bread_core @395 ap_bwrite_core @396 + ap_mpm_init_complete @397 diff --git a/ApacheCore.dsp b/ApacheCore.dsp index 64bdba3e9b..1cd8efabed 100644 --- a/ApacheCore.dsp +++ b/ApacheCore.dsp @@ -227,18 +227,10 @@ SOURCE=.\os\win32\modules.c # End Source File # Begin Source File -SOURCE=.\os\win32\registry.c -# End Source File -# Begin Source File - SOURCE=.\main\rfc1413.c # End Source File # Begin Source File -SOURCE=.\os\win32\service.c -# End Source File -# Begin Source File - SOURCE=.\main\util.c # End Source File # Begin Source File @@ -363,18 +355,10 @@ SOURCE=.\os\win32\os.h # End Source File # Begin Source File -SOURCE=.\os\win32\registry.h -# End Source File -# Begin Source File - SOURCE=.\include\rfc1413.h # End Source File # Begin Source File -SOURCE=.\os\win32\service.h -# End Source File -# Begin Source File - SOURCE=.\include\util_cfgtree.h # End Source File # Begin Source File @@ -227,18 +227,10 @@ SOURCE=.\os\win32\modules.c # End Source File # Begin Source File -SOURCE=.\os\win32\registry.c -# End Source File -# Begin Source File - SOURCE=.\main\rfc1413.c # End Source File # Begin Source File -SOURCE=.\os\win32\service.c -# End Source File -# Begin Source File - SOURCE=.\main\util.c # End Source File # Begin Source File @@ -363,18 +355,10 @@ SOURCE=.\os\win32\os.h # End Source File # Begin Source File -SOURCE=.\os\win32\registry.h -# End Source File -# Begin Source File - SOURCE=.\include\rfc1413.h # End Source File # Begin Source File -SOURCE=.\os\win32\service.h -# End Source File -# Begin Source File - SOURCE=.\include\util_cfgtree.h # End Source File # Begin Source File diff --git a/include/http_config.h b/include/http_config.h index 30a80cc0e2..f3fcdd25ee 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -382,6 +382,7 @@ void ap_show_modules(void); server_rec *ap_read_config(process_rec *process, ap_pool_t *temp_pool, const char *config_name); void ap_post_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s); void ap_child_init_hook(ap_pool_t *pchild, server_rec *s); +void ap_run_pre_config(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp); void ap_register_hooks(module *m); void ap_hook_deregister_all(void); diff --git a/libhttpd.def b/libhttpd.def index 627160c00b..68836fc32d 100644 --- a/libhttpd.def +++ b/libhttpd.def @@ -369,18 +369,18 @@ EXPORTS regerror @364 ap_send_error_response @365 ap_start_shutdown @366 - send_signal_to_service @367 +; send_signal_to_service @367 ap_read_config @368 ap_server_pre_read_config @369 ap_server_post_read_config @370 ap_setup_prelinked_modules @371 - RemoveService @372 - InstallService @373 - isValidService @374 - service_main @375 - isProcessService @376 - ap_registry_get_server_root @377 - ap_registry_get_service_conf @378 +; RemoveService @372 +; InstallService @373 +; isValidService @374 +; service_main @375 +; isProcessService @376 +; ap_registry_get_server_root @377 +; ap_registry_get_service_conf @378 ap_hook_pre_connection @379 ap_hook_post_read_request @380 ap_hook_log_transaction @381 @@ -399,3 +399,4 @@ EXPORTS ap_run_http_method @394 ap_bread_core @395 ap_bwrite_core @396 + ap_mpm_init_complete @397 diff --git a/os/win32/os.h b/os/win32/os.h index bee53b9171..7c246d6392 100644 --- a/os/win32/os.h +++ b/os/win32/os.h @@ -109,7 +109,7 @@ #define USE_MMAP_SCOREBOARD #define HAVE_CANONICAL_FILENAME #define HAVE_DRIVE_LETTERS -#define HAVE_SENDFILE +#define HAVE_SENDFILE_UNKNOWN typedef int uid_t; typedef int gid_t; diff --git a/server/main.c b/server/main.c index 1e87e79cad..ed6a8b8f39 100644 --- a/server/main.c +++ b/server/main.c @@ -280,9 +280,9 @@ static void usage(process_rec *process) ap_pool_t *g_pHookPool; #ifdef WIN32 -API_EXPORT_NONSTD(int) apache_main(int argc, char *argv[]) +API_EXPORT(int) apache_main(int argc, char *argv[]) #else -API_EXPORT_NONSTD(int) main(int argc, char *argv[]) +API_EXPORT(int) main(int argc, char *argv[]) #endif { int c; diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 09a5c79c84..0be5f8b266 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -68,7 +68,7 @@ #include "ap_config.h" #include "ap_listen.h" #include "mpm_default.h" -#include "service.h" +//#include "service.h" #include "iol_socket.h" #include "winnt.h" @@ -107,6 +107,8 @@ HANDLE maintenance_event; ap_lock_t *start_mutex; int my_pid; int parent_pid; +typedef void (CALLBACK *ap_completion_t)(); +API_VAR_EXPORT ap_completion_t ap_mpm_init_complete = NULL; static ap_status_t socket_cleanup(void *sock) { @@ -1555,7 +1557,7 @@ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_even /* Create child process * Should only be one in this version of Apache for WIN32 */ - service_set_status(SERVICE_START_PENDING); + //service_set_status(SERVICE_START_PENDING); while (remaining_children_to_start--) { if (create_process(pconf, process_handles, process_kill_events, ¤t_live_processes) < 0) { @@ -1565,7 +1567,7 @@ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_even goto die_now; } } - service_set_status(SERVICE_RUNNING); + //service_set_status(SERVICE_RUNNING); restart_pending = shutdown_pending = 0; @@ -1738,7 +1740,7 @@ static void winnt_post_config(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptem } ap_log_pid(pconf, ap_pid_fname); - service_set_status(SERVICE_START_PENDING); + //service_set_status(SERVICE_START_PENDING); /* Create shutdown event, apPID_shutdown, where PID is the parent * Apache process ID. Shutdown is signaled by 'apache -k shutdown'. @@ -1763,7 +1765,10 @@ static void winnt_post_config(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptem exit(1); } CleanNullACL((void *)sa); - + + if (ap_mpm_init_complete) + ap_mpm_init_complete(); + /* Create the start mutex, apPID, where PID is the parent Apache process ID. * Ths start mutex is used during a restart to prevent more than one * child process from entering the accept loop at once. @@ -1808,7 +1813,7 @@ API_EXPORT(int) ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s ) CloseHandle(restart_event); CloseHandle(shutdown_event); - service_set_status(SERVICE_STOPPED); + //service_set_status(SERVICE_STOPPED); return 1; } diff --git a/server/mpm/winnt/service.c b/server/mpm/winnt/service.c index c99b4abe62..e60b8a0169 100644 --- a/server/mpm/winnt/service.c +++ b/server/mpm/winnt/service.c @@ -71,6 +71,9 @@ #include "registry.h" #include "ap_mpm.h" +typedef void (CALLBACK *ap_completion_t)(); +API_VAR_IMPORT ap_completion_t ap_mpm_init_complete; + static struct { int (*main_fn)(int, char **); @@ -90,6 +93,53 @@ static int ReportStatusToSCMgr(int currentState, int exitCode, int waitHint); static int ap_start_service(SC_HANDLE); static int ap_stop_service(SC_HANDLE); +static void CALLBACK report_service95_running() +{ + FreeConsole(); + + /* We do this only once, ever */ + ap_mpm_init_complete = NULL; +} + +int service95_main(int (*main_fn)(int, char **), int argc, char **argv ) +{ + HINSTANCE hkernel; + DWORD (WINAPI *RegisterServiceProcess)(DWORD, DWORD); + + /* Obtain a handle to the kernel library */ + hkernel = LoadLibrary("KERNEL32.DLL"); + if (!hkernel) + return -1; + + /* Find the RegisterServiceProcess function */ + RegisterServiceProcess = (DWORD (WINAPI *)(DWORD, DWORD)) + GetProcAddress(hkernel, "RegisterServiceProcess"); + if (RegisterServiceProcess == NULL) + return -1; + + /* Register this process as a service */ + if (!RegisterServiceProcess((DWORD)NULL, 1)) + return -1; + + /* Eliminate the console for the remainer of the service session */ + ap_mpm_init_complete = report_service95_running; + + /* Run the service */ + globdat.exit_status = main_fn(argc, argv); + + /* When the service quits, remove it from the + system service table */ + RegisterServiceProcess((DWORD)NULL, 0); + + /* Free the kernel library */ + // Worthless, methinks, since it won't be reclaimed + // FreeLibrary(hkernel); + + /* We have to quit right here to avoid an invalid page fault */ + // But, this is worth experimenting with! + return (globdat.exit_status); +} + int service_main(int (*main_fn)(int, char **), int argc, char **argv ) { SERVICE_TABLE_ENTRY dispatchTable[] = @@ -125,6 +175,17 @@ void service_cd() chdir(buf); } +static void CALLBACK report_service_started() +{ + ReportStatusToSCMgr( + SERVICE_RUNNING, // service state + NO_ERROR, // exit code + 0); // wait hint + + /* This is only reported once, ever! */ + ap_mpm_init_complete = NULL; +} + void __stdcall service_main_fn(DWORD argc, LPTSTR *argv) { int i, new_argc; @@ -157,6 +218,8 @@ void __stdcall service_main_fn(DWORD argc, LPTSTR *argv) NO_ERROR, // exit code 3000); // wait hint + ap_mpm_init_complete = report_service_started; + service_cd(); /* Fetch server_conf from the registry |