From: William A. Rowe Jr Date: Wed, 17 Apr 2002 16:36:28 +0000 (+0000) Subject: Introduced -E startup_logfile_name option to httpd to allow admins X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91c1380c0c0b239d07a7355c1ee3d78122f638d7;p=apache 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. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94681 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index de4b6ae4e8..1f5bab6a77 100644 --- 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] diff --git a/include/http_log.h b/include/http_log.h index d6fbc714e4..d5f39db3da 100644 --- a/include/http_log.h +++ b/include/http_log.h @@ -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 diff --git a/include/http_main.h b/include/http_main.h index fdab7457e5..724f5575b4 100644 --- a/include/http_main.h +++ b/include/http_main.h @@ -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" { diff --git a/server/log.c b/server/log.c index 37e8561ec4..4898aba926 100644 --- a/server/log.c +++ b/server/log.c @@ -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) { diff --git a/server/main.c b/server/main.c index 811af82029..f6182f95c1 100644 --- a/server/main.c +++ b/server/main.c @@ -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, diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 2b965d9ab1..4ece337118 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -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) { diff --git a/server/mpm/winnt/service.c b/server/mpm/winnt/service.c index 0981d6ad05..6e6da38c05 100644 --- a/server/mpm/winnt/service.c +++ b/server/mpm/winnt/service.c @@ -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) {