From 25be2b6a89ff7dc550748f69457a02238a9cc15d Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Fri, 4 Apr 2003 18:55:49 +0000 Subject: [PATCH] Fix the inability to log errors like exec failure in mod_ext_filter/mod_cgi script children (e.g., exec failure). This was broken after such children stopped inheriting the error log handle. (For this to work with mod_ext_filter, that module's LogStderr option has to be on.) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@99211 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 5 +++++ modules/filters/mod_ext_filter.c | 19 +++++++++++++++---- modules/generators/mod_cgi.c | 18 ++++++++---------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index 67921e4d85..b4be9095e5 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,11 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Fix the inability to log errors like exec failure in + mod_ext_filter/mod_cgi script children (e.g., exec failure). This + was broken after such children stopped inheriting the error log + handle. [Jeff Trawick] + *) Fix a compile failure with recent OpenSSL and picky compilers (e.g., OpenSSL 0.9.7a and xlc_r on AIX). [Jeff Trawick] diff --git a/modules/filters/mod_ext_filter.c b/modules/filters/mod_ext_filter.c index 6031cd45a8..316c8e22bc 100644 --- a/modules/filters/mod_ext_filter.c +++ b/modules/filters/mod_ext_filter.c @@ -69,6 +69,7 @@ #include "apr_buckets.h" #include "util_filter.h" #include "util_script.h" +#include "util_time.h" #include "apr_strings.h" #include "apr_hash.h" #include "apr_lib.h" @@ -423,15 +424,25 @@ static apr_status_t ef_close_file(void *vfile) return apr_file_close(vfile); } -static void child_errfn(apr_pool_t *p, apr_status_t err, const char *desc) +static void child_errfn(apr_pool_t *pool, apr_status_t err, const char *description) { request_rec *r; void *vr; + apr_file_t *stderr_log; + char errbuf[200]; + char time_str[APR_CTIME_LEN]; - apr_pool_userdata_get(&vr, ERRFN_USERDATA_KEY, p); + apr_pool_userdata_get(&vr, ERRFN_USERDATA_KEY, pool); r = vr; - - ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, "%s", desc); + apr_file_open_stderr(&stderr_log, pool); + ap_recent_ctime(time_str, apr_time_now()); + apr_file_printf(stderr_log, + "[%s] [client %s] mod_ext_filter (%d)%s: %s\n", + time_str, + r->connection->remote_ip, + err, + apr_strerror(err, errbuf, sizeof(errbuf)), + description); } /* init_ext_filter_process: get the external filter process going diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index 3d9e1284b5..01c1f245eb 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -122,8 +122,6 @@ static int is_scriptaliased(request_rec *r) #define DEFAULT_LOGBYTES 10385760 #define DEFAULT_BUFBYTES 1024 -#define ERRFN_USERDATA_KEY "CGICHILDERRFN" - typedef struct { const char *logname; long logbytes; @@ -385,13 +383,15 @@ static void add_ssi_vars(request_rec *r) static void cgi_child_errfn(apr_pool_t *pool, apr_status_t err, const char *description) { - request_rec *r; - void *vr; + apr_file_t *stderr_log; + char errbuf[200]; - apr_pool_userdata_get(&vr, ERRFN_USERDATA_KEY, pool); - r = vr; - - ap_log_rerror(APLOG_MARK, APLOG_ERR, err, r, "%s", description); + apr_file_open_stderr(&stderr_log, pool); + apr_file_printf(stderr_log, + "(%d)%s: %s\n", + err, + apr_strerror(err, errbuf, sizeof(errbuf)), + description); } static apr_status_t run_cgi_child(apr_file_t **script_out, @@ -473,8 +473,6 @@ static apr_status_t run_cgi_child(apr_file_t **script_out, "couldn't set child process attributes: %s", r->filename); } else { - apr_pool_userdata_set(r, ERRFN_USERDATA_KEY, apr_pool_cleanup_null, p); - procnew = apr_pcalloc(p, sizeof(*procnew)); if (e_info->prog_type == RUN_AS_SSI) { SPLIT_AND_PASS_PRETAG_BUCKETS(*(e_info->bb), e_info->ctx,