]> granicus.if.org Git - apache/commitdiff
Introduced -E startup_logfile_name option to httpd to allow admins
authorWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 17 Apr 2002 16:36:28 +0000 (16:36 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 17 Apr 2002 16:36:28 +0000 (16:36 +0000)
     to begin logging errors immediately.  This provides Win32 users
     an alternative to sending startup errors to the event viewer, and
     allows other daemon tool authors an alternative to logging to stderr.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94681 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
include/http_log.h
include/http_main.h
server/log.c
server/main.c
server/mpm/winnt/mpm_winnt.c
server/mpm/winnt/service.c

diff --git a/CHANGES b/CHANGES
index de4b6ae4e89df957252df1908ac8989669d7d53e..1f5bab6a77f1c7e2b2a9daf594da4697c24fde69 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,11 @@
 Changes with Apache 2.0.36
 
+  *) Introduced -E startup_logfile_name option to httpd to allow admins
+     to begin logging errors immediately.  This provides Win32 users 
+     an alternative to sending startup errors to the event viewer, and
+     allows other daemon tool authors an alternative to logging to stderr.
+     [William Rowe] 
+     
   *) Fix subreqs with non-defined Content-Types being served improperly.
      [Justin Erenkrantz]
 
index d6fbc714e44f4059bee21b31071d0cefe573f383..d5f39db3da94ac636eb848a91c3610104b156b14 100644 (file)
@@ -121,6 +121,14 @@ extern int AP_DECLARE_DATA ap_default_loglevel;
  */
 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p);
 
+/**
+ * Replace logging to stderr with logging to the given file.
+ * @param p The pool to allocate out of
+ * @param file Name of the file to log stderr output
+ */
+AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
+                                               const char *file);
+
 /**
  * Open the error log and replace stderr with it.
  * @param s_main The main server
index fdab7457e5c4728d9c22c90bc0a84f6f8b772695..724f5575b410639d45c057f91e78f92cb521ab58 100644 (file)
@@ -63,7 +63,7 @@
  * in apr_getopt() format.  Use this for default'ing args that the MPM
  * can safely ignore and pass on from its rewrite_args() handler.
  */
-#define AP_SERVER_BASEARGS "C:c:D:d:e:f:vVlLth?X"
+#define AP_SERVER_BASEARGS "C:c:D:d:E:e:f:vVlLth?X"
 
 #ifdef __cplusplus
 extern "C" {
index 37e8561ec4867ae8423b30ab2ca181a05f3e58c6..4898aba926fbfbde4b8d11afdd64756ac86cac71 100644 (file)
@@ -187,6 +187,39 @@ AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p)
     apr_file_open_stderr(&stderr_log, p);
 }
 
+AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, 
+                                               const char *fname)
+{
+    apr_file_t *stderr_file;
+    apr_status_t rc;
+    char *filename = ap_server_root_relative(p, fname);
+    if (!filename) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
+                     APR_EBADPATH, NULL, "Invalid -E error log file %s",
+                     fname);
+        exit(1);
+    }
+    if ((rc = apr_file_open(&stderr_file, filename,
+                            APR_APPEND | APR_READ | APR_WRITE | APR_CREATE,
+                            APR_OS_DEFAULT, p)) != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
+                     "%s: could not open error log file %s.",
+                     ap_server_argv0, fname);
+        return rc;
+    }
+    if ((rc = apr_file_open_stderr(&stderr_log, p)) == APR_SUCCESS) {
+        apr_file_flush(stderr_log);
+        if ((rc = apr_file_dup2(stderr_log, stderr_file, p)) == APR_SUCCESS) {
+            apr_file_close(stderr_file);
+        }
+    }
+    if (rc != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_CRIT, rc, NULL,
+                     "unable to replace stderr with error_log");
+        return rc;
+    }
+}
+
 static int log_child(apr_pool_t *p, const char *progname,
                      apr_file_t **fpin)
 {
index 811af8202992cea10104f239fc6818c6f5a43bcb..f6182f95c1d3a135f923738fd7157e2528cdc086 100644 (file)
@@ -359,6 +359,8 @@ static void usage(process_rec *process)
     ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
                  "  -e level          : show startup errors of level "
                  "(see LogLevel)");
+    ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
+                 "  -E file           : log startup errors to file");
     ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
                  "  -v                : show version number");
     ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
@@ -390,6 +392,7 @@ int main(int argc, const char * const argv[])
     int configtestonly = 0;
     const char *confname = SERVER_CONFIG_FILE;
     const char *def_server_root = HTTPD_ROOT;
+    const char *temp_error_log = NULL;
     process_rec *process;
     server_rec *server_conf;
     apr_pool_t *pglobal;
@@ -486,6 +489,10 @@ int main(int argc, const char * const argv[])
             }
             break;
 
+        case 'E':
+            temp_error_log = apr_pstrdup(process->pool, optarg);
+            break;
+
         case 'X':
             new = (char **)apr_array_push(ap_server_config_defines);
             *new = "DEBUG";
@@ -539,6 +546,9 @@ int main(int argc, const char * const argv[])
      */
 
     ap_server_root = def_server_root;
+    if (temp_error_log) {
+        ap_replace_stderr_log(process->pool, temp_error_log);
+    }
     server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
     if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
         ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR| APLOG_NOERRNO, 0,
index 2b965d9ab1c0c007067df51832e87b0f35b33a33..4ece337118e071bf1dbb6ed9cee519647921893f 100644 (file)
@@ -1975,6 +1975,7 @@ void winnt_rewrite_args(process_rec *process)
     char *pid;
     apr_getopt_t *opt;
     int running_as_service = 1;
+    int errout = 0;
 
     osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     GetVersionEx(&osver);
@@ -2060,6 +2061,9 @@ void winnt_rewrite_args(process_rec *process)
         case 'k':
             signal_arg = optarg;
             break;
+        case 'E':
+            errout = 1;
+            /* Fall through so the Apache main() handles the 'E' arg */
         default:
             *(const char **)apr_array_push(mpm_new_argv) =
                 apr_pstrdup(process->pool, optbuf);
@@ -2106,7 +2110,11 @@ void winnt_rewrite_args(process_rec *process)
          * We hold the return value so that we can die in pre_config
          * after logging begins, and the failure can land in the log.
          */
-        if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+        if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) 
+        {
+            if (!errout) {
+                mpm_nt_eventlog_stderr_open(service_name, process->pool);
+            }
             service_to_start_success = mpm_service_to_start(&service_name,
                                                             process->pool);
             if (service_to_start_success == APR_SUCCESS) {
index 0981d6ad05ce57663f27e4f58110227f3a89f9db..6e6da38c0584615d223f9d344a2cf57fef8001b7 100644 (file)
@@ -708,8 +708,6 @@ apr_status_t mpm_service_to_start(const char **display_name, apr_pool_t *p)
     
     if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
     {
-        mpm_nt_eventlog_stderr_open(mpm_display_name, p);
-
         globdat.service_init = CreateEvent(NULL, FALSE, FALSE, NULL);
         globdat.service_term = CreateMutex(NULL, TRUE, NULL);
         if (!globdat.service_init || !globdat.service_term) {