]> granicus.if.org Git - apache/commitdiff
Finish the -w keep-console-open-on-error patch.
authorWilliam A. Rowe Jr <wrowe@apache.org>
Sun, 23 Jun 2002 10:24:07 +0000 (10:24 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Sun, 23 Jun 2002 10:24:07 +0000 (10:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95869 13f79535-47bb-0310-9956-ffa450edef68

os/win32/os.h
server/mpm/winnt/mpm_winnt.c
server/mpm/winnt/mpm_winnt.h
server/mpm/winnt/service.c

index dfb44598cabcac01981105fc2ca1768f66618e6c..2a8f9945b5c3e6a6e00b3b5e10754afd04c17696 100644 (file)
@@ -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 <io.h>
 
 #include <stddef.h>
 
-#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 */
index 9fa66b58637e729c2ed55675c8c0a41875c2d4f1..b5f99e5523f9d2231b0932f3342b560807691ff9 100644 (file)
@@ -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;
index 127512bbf0b41005f350cfd43f45816b3c4d061c..e3229b374184fb2690a5867305e403c8660a8d0e 100644 (file)
@@ -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 */
index 4c99ea74fc02ecf3ad7d22f8596ce3fa15a22942..afec0e8463a29b639b38c89bed6185a5ad257f5e 100644 (file)
@@ -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.
       */