From a32a75c59974c91662a2404541da2e9fbdabd45d Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Sun, 15 Sep 2002 22:04:01 +0000 Subject: [PATCH] Modify ap_open_logs (an internal function) to follow the hook open_logs argument schema so it can be directly invoked by the hook handler. Also clean up the open_logs processing to return an error rather than simply exit()ing. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96829 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_log.h | 9 +++++++-- server/core.c | 8 +------- server/log.c | 28 ++++++++++++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/http_log.h b/include/http_log.h index 669c564a1a..9492741957 100644 --- a/include/http_log.h +++ b/include/http_log.h @@ -148,10 +148,15 @@ AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, /** * Open the error log and replace stderr with it. + * @param pconf Not used + * @param plog The pool to allocate the logs from + * @param ptemp Pool used for temporary allocations * @param s_main The main server - * @param p The pool to allocate out of + * @tip ap_open_logs isn't expected to be used by modules, it is + * an internal core function */ -void ap_open_logs (server_rec *s_main, apr_pool_t *p); +int ap_open_logs(apr_pool_t *pconf, apr_pool_t *plog, + apr_pool_t *ptemp, server_rec *s_main); /* * The three primary logging functions, ap_log_error, ap_log_rerror, and diff --git a/server/core.c b/server/core.c index 2dc2887a35..51275d7ee5 100644 --- a/server/core.c +++ b/server/core.c @@ -3932,12 +3932,6 @@ static int core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *pte return OK; } -static int core_open_logs(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) -{ - ap_open_logs(s, plog); - return OK; -} - static void core_insert_filter(request_rec *r) { core_dir_config *conf = (core_dir_config *) @@ -4111,7 +4105,7 @@ static void register_hooks(apr_pool_t *p) ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST); ap_hook_translate_name(ap_core_translate,NULL,NULL,APR_HOOK_REALLY_LAST); ap_hook_map_to_storage(core_map_to_storage,NULL,NULL,APR_HOOK_REALLY_LAST); - ap_hook_open_logs(core_open_logs,NULL,NULL,APR_HOOK_MIDDLE); + ap_hook_open_logs(ap_open_logs,NULL,NULL,APR_HOOK_REALLY_FIRST); ap_hook_handler(default_handler,NULL,NULL,APR_HOOK_REALLY_LAST); /* FIXME: I suspect we can eliminate the need for these do_nothings - Ben */ ap_hook_type_checker(do_nothing,NULL,NULL,APR_HOOK_REALLY_LAST); diff --git a/server/log.c b/server/log.c index 4522ea24cf..24c8034262 100644 --- a/server/log.c +++ b/server/log.c @@ -197,7 +197,7 @@ AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH, NULL, "Invalid -E error log file %s", fname); - exit(1); + return APR_EBADPATH; } if ((rc = apr_file_open(&stderr_file, filename, APR_APPEND | APR_READ | APR_WRITE | APR_CREATE, @@ -254,7 +254,7 @@ static int log_child(apr_pool_t *p, const char *progname, return rc; } -static void open_error_log(server_rec *s, apr_pool_t *p) +static int open_error_log(server_rec *s, apr_pool_t *p) { const char *fname; int rc; @@ -267,7 +267,7 @@ static void open_error_log(server_rec *s, apr_pool_t *p) if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "Couldn't start ErrorLog process"); - exit(1); + return DONE; } s->error_log = dummy; @@ -284,7 +284,7 @@ static void open_error_log(server_rec *s, apr_pool_t *p) openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, fac->t_val); s->error_log = NULL; - return; + return OK; } } } @@ -301,7 +301,7 @@ static void open_error_log(server_rec *s, apr_pool_t *p) ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL, "%s: Invalid error log path %s.", ap_server_argv0, s->error_fname); - exit(1); + return DONE; } if ((rc = apr_file_open(&s->error_log, fname, APR_APPEND | APR_READ | APR_WRITE | APR_CREATE, @@ -309,21 +309,26 @@ static void open_error_log(server_rec *s, apr_pool_t *p) ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "%s: could not open error log file %s.", ap_server_argv0, fname); - exit(1); + return DONE; } apr_file_inherit_set(s->error_log); } + + return OK; } -void ap_open_logs(server_rec *s_main, apr_pool_t *p) +int ap_open_logs(apr_pool_t *pconf, apr_pool_t *p /* plog */, + apr_pool_t *ptemp, server_rec *s_main) { apr_status_t rc = APR_SUCCESS; server_rec *virt, *q; int replace_stderr; apr_file_t *errfile = NULL; - open_error_log(s_main, p); + if (open_error_log(s_main, p) != OK) { + return DONE; + } replace_stderr = 1; if (s_main->error_log) { @@ -360,7 +365,9 @@ void ap_open_logs(server_rec *s_main, apr_pool_t *p) } if (q == virt) { - open_error_log(virt, p); + if (open_error_log(virt, p) != OK) { + return DONE; + } } else { virt->error_log = q->error_log; @@ -370,6 +377,7 @@ void ap_open_logs(server_rec *s_main, apr_pool_t *p) virt->error_log = s_main->error_log; } } + return OK; } AP_DECLARE(void) ap_error_log2stderr(server_rec *s) { @@ -856,7 +864,7 @@ AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program) if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, "Couldn't start piped log process"); - exit (1); + return NULL; } pl = apr_palloc(p, sizeof (*pl)); -- 2.50.1