You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "William A. Rowe, Jr." <wr...@lnd.com> on 2000/06/12 02:43:20 UTC
FW: cvs commit: apache-1.3/src/main http_main.c
This is to the attention of all Win32 folks.
I looked at the 'dirtier' aspects of last weeks Services for 9x
patch, and have committed a few cleanups to make the common code
a little cleaner, and our win32 process clean up after itself a
little more reliably.
Bill
> -----Original Message-----
> From: wrowe@locus.apache.org [mailto:wrowe@locus.apache.org]
> Sent: Sunday, June 11, 2000 7:41 PM
> To: apache-1.3-cvs@apache.org
> Subject: cvs commit: apache-1.3/src/main http_main.c
>
>
> wrowe 00/06/11 17:41:24
>
> Modified: src/os/win32 service.c service.h
> src/main http_main.c
> Log:
> This patch accomplishes three things:
>
> 1) Removes a bunch of Win32 junk from http_main.c into
> service.c, so that
> http_main.c nearly goes back to the state it was in last week.
>
> 2) Hooks in termination logic that is often not called
> when apache is
> exit()ed with atexit() calls. This, incidently,
> prepares us to pause
> while exiting Apache from a Win32 console window.
>
> 3) Explicitly names the hidden Win32 notification message
> monitor by the
> name of the service. This will allow taskbar applets
> to walk the list
> of windows to determine which Apache services are
> running under Win9x.
>
> Revision Changes Path
> 1.19 +74 -34 apache-1.3/src/os/win32/service.c
>
> Index: service.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/os/win32/service.c,v
> retrieving revision 1.18
> retrieving revision 1.19
> diff -u -r1.18 -r1.19
> --- service.c 2000/06/09 18:16:10 1.18
> +++ service.c 2000/06/12 00:41:23 1.19
> @@ -26,6 +26,13 @@
> FILE *logFile;
> } globdat;
>
> +/* statics for atexit processing or shared between threads */
> +static BOOL die_on_logoff = FALSE;
> +static DWORD monitor_thread_id = 0;
> +DWORD (WINAPI *RegisterServiceProcess)(DWORD, DWORD);
> +HINSTANCE monitor_hkernel = NULL;
> +
> +
> static void WINAPI service_main_fn(DWORD, LPTSTR *);
> static void WINAPI service_ctrl(DWORD ctrlCode);
> static int ReportStatusToSCMgr(int currentState, int
> exitCode, int waitHint);
> @@ -69,8 +76,6 @@
>
> int send_signal(pool *p, char *signal);
>
> -static BOOL die_on_logoff;
> -
> LRESULT CALLBACK Service9xWndProc(HWND hWnd, UINT message,
> WPARAM wParam, LPARAM lParam)
> {
> if (message == WM_QUERYENDSESSION)
> @@ -88,11 +93,16 @@
> return (DefWindowProc(hWnd, message, wParam, lParam));
> }
>
> -DWORD WINAPI WatchWindow(void *kill_on_logoff)
> +DWORD WINAPI WatchWindow(void *service_name)
> {
> /* When running as a service under Windows 9x, there
> is no console
> * window present, and no ConsoleCtrlHandler to call
> when the system
> - * is shutdown.
> + * is shutdown. If the WatchWindow thread is created
> with a NULL
> + * service_name argument, then the ...SystemMonitor
> window class is
> + * used to create the "Apache" window to watch for
> logoff and shutdown.
> + * If the service_name is provided, the
> ...ServiceMonitor window class
> + * is used to create the window named by the
> service_name argument,
> + * and the logoff message is ignored.
> */
> WNDCLASS wc;
> HWND hwndMain;
> @@ -106,9 +116,12 @@
> wc.hCursor = NULL;
> wc.hbrBackground = NULL;
> wc.lpszMenuName = NULL;
> - wc.lpszClassName = "ApacheWin95ServiceMonitor";
> + if (service_name)
> + wc.lpszClassName = "ApacheWin95ServiceMonitor";
> + else
> + wc.lpszClassName = "ApacheWin95SystemMonitor";
>
> - die_on_logoff = (BOOL) kill_on_logoff;
> + die_on_logoff = service_name ? FALSE : TRUE;
>
> if (!RegisterClass(&wc))
> {
> @@ -118,7 +131,8 @@
> }
>
> /* Create an invisible window */
> - hwndMain = CreateWindow("ApacheWin95ServiceMonitor",
> "Apache Service",
> + hwndMain = CreateWindow(wc.lpszClassName,
> + service_name ? (char *)
> service_name : "Apache",
> WS_OVERLAPPEDWINDOW &
> ~WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
> CW_USEDEFAULT, CW_USEDEFAULT,
> NULL, NULL, NULL, NULL);
>
> @@ -137,23 +151,37 @@
> return 0;
> }
>
> +void stop_service_monitor(void)
> +{
> + PostThreadMessage(monitor_thread_id, WM_QUIT, 0, 0);
> +
> + /* When the service quits, remove it from the
> + system service table */
> + RegisterServiceProcess((DWORD)NULL, 0);
> +
> + /* Free the kernel library */
> + FreeLibrary(monitor_hkernel);
> +}
>
> -int service95_main(int (*main_fn)(int, char **), int argc,
> char **argv )
> +int service95_main(int (*main_fn)(int, char **), int argc,
> char **argv,
> + char *display_name)
> {
> /* Windows 95/98 */
> + char *service_name;
> HANDLE thread;
> - DWORD thread_id;
> - HINSTANCE hkernel;
> - DWORD (WINAPI *RegisterServiceProcess)(DWORD, DWORD);
>
> + /* Remove spaces from display name to create service name */
> + service_name = strdup(display_name);
> + ap_remove_spaces(service_name, display_name);
> +
> /* Obtain a handle to the kernel library */
> - hkernel = LoadLibrary("KERNEL32.DLL");
> - if (!hkernel)
> + monitor_hkernel = LoadLibrary("KERNEL32.DLL");
> + if (!monitor_hkernel)
> return -1;
>
> /* Find the RegisterServiceProcess function */
> RegisterServiceProcess = (DWORD (WINAPI *)(DWORD, DWORD))
> - GetProcAddress(hkernel,
> "RegisterServiceProcess");
> + GetProcAddress(monitor_hkernel,
> "RegisterServiceProcess");
> if (RegisterServiceProcess == NULL)
> return -1;
>
> @@ -164,23 +192,14 @@
> /* Hide the console */
> FreeConsole();
>
> - thread = CreateThread(NULL, 0, WatchWindow, (LPVOID)
> FALSE, 0, &thread_id);
> + thread = CreateThread(NULL, 0, WatchWindow, (LPVOID)
> service_name, 0,
> + &monitor_thread_id);
> CloseHandle(thread);
>
> + atexit(stop_service_monitor);
> +
> /* Run the service */
> globdat.exit_status = main_fn(argc, argv);
> -
> - PostThreadMessage(thread_id, WM_QUIT, 0, 0);
> -
> - /* When the service quits, remove it from the
> - system service table */
> - RegisterServiceProcess((DWORD)NULL, 0);
> -
> - /* Free the kernel library */
> - FreeLibrary(hkernel);
> -
> - /* We have to quit right here to avoid an invalid page fault */
> - exit(globdat.exit_status);
> }
>
> void service_cd()
> @@ -220,6 +239,7 @@
> return;
> }
>
> +
> void service_set_status(int status)
> {
> ReportStatusToSCMgr(status, NO_ERROR, 3000);
> @@ -681,14 +701,8 @@
> * on Windows NT also user logoff and system shutdown
> */
>
> -void ap_control_handler_terminate(void)
> +static BOOL CALLBACK ap_control_handler(DWORD ctrl_type)
> {
> - /* Remove the control handler at the end of the day. */
> - SetConsoleCtrlHandler(ap_control_handler, FALSE);
> -}
> -
> -BOOL CALLBACK ap_control_handler(DWORD ctrl_type)
> -{
> switch (ctrl_type)
> {
> case CTRL_C_EVENT:
> @@ -717,6 +731,32 @@
>
> /* We should never get here, but this is (mostly) harmless */
> return FALSE;
> +}
> +
> +void stop_console_monitor(void)
> +{
> + if (!isWindowsNT() && monitor_thread_id)
> + PostThreadMessage(monitor_thread_id, WM_QUIT, 0, 0);
> +
> + /* Remove the control handler at the end of the day. */
> + SetConsoleCtrlHandler(ap_control_handler, FALSE);
> +}
> +
> +void ap_start_console_monitor(void)
> +{
> + /* Under 95/98 create a monitor window to watch for
> session end,
> + * pass NULL to WatchWindow so we do not appear to run
> as a service.
> + */
> + SetConsoleCtrlHandler(ap_control_handler, TRUE);
> +
> + if (!isWindowsNT()) {
> + HANDLE thread;
> + thread = CreateThread(NULL, 0, WatchWindow, NULL, 0,
> + &monitor_thread_id);
> + CloseHandle(thread);
> + }
> +
> + atexit(stop_console_monitor);
> }
> #endif /* WIN32 */
>
>
>
>
> 1.8 +3 -4 apache-1.3/src/os/win32/service.h
>
> Index: service.h
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/os/win32/service.h,v
> retrieving revision 1.7
> retrieving revision 1.8
> diff -u -r1.7 -r1.8
> --- service.h 2000/06/09 18:16:10 1.7
> +++ service.h 2000/06/12 00:41:23 1.8
> @@ -4,7 +4,8 @@
>
> #ifdef WIN32
> int service_main(int (*main_fn)(int, char **), int argc,
> char **argv);
> -int service95_main(int (*main_fn)(int, char **), int argc,
> char **argv);
> +int service95_main(int (*main_fn)(int, char **), int argc,
> char **argv,
> + char *display_name);
> void service_set_status(int status);
> void service_cd();
> BOOL isProcessService();
> @@ -13,10 +14,8 @@
> void RemoveService(char *display_name);
> int service_init();
> int send_signal_to_service(char *display_name, char *sig);
> -void ap_control_handler_terminate(void);
> -BOOL CALLBACK ap_control_handler(DWORD ctrl_type);
> BOOL isWindowsNT(void);
> -DWORD WINAPI WatchWindow(void *kill_on_logoff);
> +void ap_start_console_monitor(void);
> #endif /* WIN32 */
>
> #endif /* SERVICE_H */
>
>
>
> 1.498 +7 -23 apache-1.3/src/main/http_main.c
>
> Index: http_main.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v
> retrieving revision 1.497
> retrieving revision 1.498
> diff -u -r1.497 -r1.498
> --- http_main.c 2000/06/10 00:38:56 1.497
> +++ http_main.c 2000/06/12 00:41:24 1.498
> @@ -6918,35 +6918,19 @@
> else if (service_name && signal_to_send && !isWindowsNT()
> && !strcasecmp(signal_to_send, "start")) {
> /* service95_main will call master_main() */
> - service95_main(master_main, argc, argv);
> + service95_main(master_main, argc, argv, service_name);
> }
> else
> {
> #ifdef WIN32
> - /* Let's go fishing for some signals including
> ctrl+c/ctrl+break,
> - * and logoff, close and shutdown under WinNT/2000
> - *
> - * Under 95/98 create a monitor window to watch for session end
> - */
> - DWORD thread_id;
> - SetConsoleCtrlHandler(ap_control_handler, TRUE);
> - atexit(ap_control_handler_terminate);
> - if (!isWindowsNT()) {
> - HANDLE thread;
> - thread = CreateThread(NULL, 0, WatchWindow,
> - (LPVOID) TRUE, 0, &thread_id);
> - CloseHandle(thread);
> - }
> -#endif
> -
> + /* Let's go fishing for some signals including ctrl+c,
> + * ctrl+break, logoff, close and shutdown.
> + */
> + ap_start_console_monitor();
> +#endif /* WIN32 */
> master_main(argc, argv);
> -
> -#ifdef WIN32
> - if (!isWindowsNT())
> - PostThreadMessage(thread_id, WM_QUIT, 0, 0);
> -#endif
> }
> -#endif
> +#endif /* ndef NETWARE */
>
> clean_parent_exit(0);
> return 0; /* purely to avoid a warning */
>
>
>
>
Re: cvs commit: apache-1.3/src/main http_main.c
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
>
> I looked at the 'dirtier' aspects of last weeks Services for 9x
> patch, and have committed a few cleanups to make the common code
> a little cleaner, and our win32 process clean up after itself a
> little more reliably.
>
> Bill
>
> > Log:
> > This patch accomplishes three things:
> >
> > 1) Removes a bunch of Win32 junk from http_main.c into
> > service.c, so that
> > http_main.c nearly goes back to the state it was in last week.
> >
Thank you. I would have squacked when I noticed all the Win32 specific stuff in
http_main.c. I spend a good deal of time trying to eliminate http_main.c Win32 stuff it in
2.0.
Bill