From 75bf5412af152e06c62a7e48467461c0b05d19a6 Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Sun, 23 Jun 2002 10:24:07 +0000 Subject: [PATCH] Finish the -w keep-console-open-on-error patch. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95869 13f79535-47bb-0310-9956-ffa450edef68 --- os/win32/os.h | 19 ++++++++++++++++--- server/mpm/winnt/mpm_winnt.c | 21 +++++++++++++++++++-- server/mpm/winnt/mpm_winnt.h | 1 + server/mpm/winnt/service.c | 5 ++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/os/win32/os.h b/os/win32/os.h index dfb44598ca..2a8f9945b5 100644 --- a/os/win32/os.h +++ b/os/win32/os.h @@ -69,8 +69,8 @@ * windows.h prior to any other Apache header files. */ -#ifndef _WIN32 -#define _WIN32 +#ifndef ap_os_h +#define ap_os_h #endif #include @@ -87,4 +87,17 @@ #include -#endif /* ! APACHE_OS_H */ +/* BIG RED WARNING: exit() is mapped to allow us to capture the exit + * status. This header must only be included from modules linked into + * the ApacheCore.dll - since it's a horrible behavior to exit() from + * any module outside the main() block, and we -will- assume it's a + * fatal error. No dynamically linked module will ever be able to find + * the real_exit_code, and _will_ GP fault if it tries this macro. + */ + +AP_DECLARE_DATA extern int real_exit_code; + +#define exit(status) ((exit)((real_exit_code==2) ? (real_exit_code = (status)) \ + : ((real_exit_code = 0), (status)))) + +#endif /* ! ap_os_h */ diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 9fa66b5863..b5f99e5523 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -2082,6 +2082,9 @@ void winnt_rewrite_args(process_rec *process) my_pid = GetCurrentProcessId(); parent_pid = (DWORD) atol(pid); + /* Prevent holding open the (nonexistant) console */ + real_exit_code = 0; + /* The parent is responsible for providing the * COMPLETE ARGUMENTS REQUIRED to the child. * @@ -2145,16 +2148,27 @@ void winnt_rewrite_args(process_rec *process) optbuf[2] = '\0'; apr_getopt_init(&opt, process->pool, process->argc, (char**) process->argv); opt->errfn = NULL; - while ((rv = apr_getopt(opt, "n:k:iu" AP_SERVER_BASEARGS, + while ((rv = apr_getopt(opt, "wn:k:" AP_SERVER_BASEARGS, optbuf + 1, &optarg)) == APR_SUCCESS) { switch (optbuf[1]) { + + /* Shortcuts; include the -w option to hold the window open on error. + * This must not be toggled once we reset real_exit_code to 0! + */ + case 'w': + if (real_exit_code) + real_exit_code = 2; + break; + case 'n': service_set = mpm_service_set_name(process->pool, &service_name, optarg); break; + case 'k': signal_arg = optarg; break; + case 'E': errout = 1; /* Fall through so the Apache main() handles the 'E' arg */ @@ -2307,7 +2321,10 @@ static int winnt_pre_config(apr_pool_t *pconf_, apr_pool_t *plog, apr_pool_t *pt /* Initialize shared static objects. */ pconf = pconf_; - + + /* This behavior is voided by setting real_exit_code to 0 */ + atexit(hold_console_open_on_error); + if (ap_exists_config_define("ONE_PROCESS") || ap_exists_config_define("DEBUG")) one_process = -1; diff --git a/server/mpm/winnt/mpm_winnt.h b/server/mpm/winnt/mpm_winnt.h index 127512bbf0..e3229b3741 100644 --- a/server/mpm/winnt/mpm_winnt.h +++ b/server/mpm/winnt/mpm_winnt.h @@ -212,4 +212,5 @@ typedef enum { AP_DECLARE(PCOMP_CONTEXT) mpm_get_completion_context(void); AP_DECLARE(void) mpm_recycle_completion_context(PCOMP_CONTEXT pCompContext); AP_DECLARE(apr_status_t) mpm_post_completion_context(PCOMP_CONTEXT pCompContext, io_state_e state); +void hold_console_open_on_error(void); #endif /* APACHE_MPM_WINNT_H */ diff --git a/server/mpm/winnt/service.c b/server/mpm/winnt/service.c index 4c99ea74fc..afec0e8463 100644 --- a/server/mpm/winnt/service.c +++ b/server/mpm/winnt/service.c @@ -118,7 +118,7 @@ static int ReportStatusToSCMgr(int currentState, int exitCode, int waitHint); * behavior on exit. All service and child processes are expected to * reset this flag to zero to avoid undesireable side effects. */ -int real_exit_code = 1; +AP_DECLARE_DATA int real_exit_code = 1; void hold_console_open_on_error(void) { @@ -698,6 +698,9 @@ apr_status_t mpm_service_to_start(const char **display_name, apr_pool_t *p) HANDLE hThread = GetCurrentThread(); HANDLE waitfor[2]; + /* Prevent holding open the (hidden) console */ + real_exit_code = 0; + /* GetCurrentThread returns a psuedo-handle, we need * a real handle for another thread to wait upon. */ -- 2.40.0