Here's a simple patch that allows windows users who wish to -avoid-
the Event Log to use a '-E file' argument to start Apache, and begin
logging errors to the named file immediately.
It won't catch parsing errors on the command line [duh - how did they
bork that] or in the config args registered for the service.
This patch could be simpler, I could treat it as a Win32-only case. But
I'm betting that some other platforms (Netware, OS/2, daemon-tool
invocations) might also benefit from the -E argument.
Feedback? If it leaves a bad taste in enough folks mouths, I'll make this
a Win32-only argument. If no one complains, I'll commit as-is (for all
platforms) sometime tomorrow.
Bill
Index: include/http_log.h
===================================================================
RCS file: /home/cvs/httpd-2.0/include/http_log.h,v
retrieving revision 1.33
diff -u -r1.33 http_log.h
--- include/http_log.h 13 Mar 2002 20:47:42 -0000 1.33
+++ include/http_log.h 17 Apr 2002 03:00:30 -0000
@@ -122,6 +122,14 @@
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
* @param p The pool to allocate out of
Index: server/log.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/log.c,v
retrieving revision 1.115
diff -u -r1.115 log.c
--- server/log.c 17 Mar 2002 23:17:28 -0000 1.115
+++ server/log.c 17 Apr 2002 03:00:31 -0000
@@ -187,6 +187,39 @@
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: include/http_main.h
===================================================================
RCS file: /home/cvs/httpd-2.0/include/http_main.h,v
retrieving revision 1.22
diff -u -r1.22 http_main.h
--- include/http_main.h 13 Mar 2002 20:47:42 -0000 1.22
+++ include/http_main.h 17 Apr 2002 03:00:30 -0000
@@ -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: server/main.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/main.c,v
retrieving revision 1.126
diff -u -r1.126 main.c
--- server/main.c 13 Apr 2002 19:35:17 -0000 1.126
+++ server/main.c 17 Apr 2002 03:00:31 -0000
@@ -360,6 +360,8 @@
" -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,
" -V : show compile settings");
@@ -390,6 +392,7 @@
int configtestonly = 0;
const char *confname = SERVER_CONFIG_FILE;
const char *def_server_root = HTTPD_ROOT;
+ const char *startup_error_log = NULL;
process_rec *process;
server_rec *server_conf;
apr_pool_t *pglobal;
@@ -486,6 +489,10 @@
}
break;
+ case 'E':
+ startup_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 @@
*/
ap_server_root = def_server_root;
+ if (startup_error_log) {
+ ap_replace_stderr_log(process->pool, startup_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: server/mpm/winnt/mpm_winnt.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm_winnt.c,v
retrieving revision 1.263
diff -u -r1.263 mpm_winnt.c
--- server/mpm/winnt/mpm_winnt.c 10 Apr 2002 17:02:00 -0000 1.263
+++ server/mpm/winnt/mpm_winnt.c 17 Apr 2002 03:00:33 -0000
@@ -1975,6 +1975,7 @@
char *pid;
apr_getopt_t *opt;
int running_as_service = 1;
+ int startup_log = 0;
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osver);
@@ -2060,6 +2061,9 @@
case 'k':
signal_arg = optarg;
break;
+ case 'E':
+ startup_log = 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 @@
* 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 (!startup_log) {
+ 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: server/mpm/winnt/service.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/service.c,v
retrieving revision 1.49
diff -u -r1.49 service.c
--- server/mpm/winnt/service.c 22 Mar 2002 01:28:01 -0000 1.49
+++ server/mpm/winnt/service.c 17 Apr 2002 03:00:33 -0000
@@ -708,8 +708,6 @@
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) {