From: Cliff Woolley Date: Wed, 29 May 2002 04:38:59 +0000 (+0000) Subject: Error out a bit more nicely if the RewriteMap prg: is not found. We X-Git-Tag: 2.0.37~217 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90c19bdbd19d5a33e5e85292b01d4f5ad133ce8d;p=apache Error out a bit more nicely if the RewriteMap prg: is not found. We can't just apr_stat in the first init round because we haven't run apr_tokenize_to_argv() yet, and it would be a relatively ugly hack to run it twice just for that. Well, I suppose we could store the argv in the rewritemap structure, but ... nah. With this, we shutdown (cleanly, as opposed to the old exit(1) method) if we go to execute a rewritemap and discover it doesn't exist, and log a nice descriptive message at the end of the error_log. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95337 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index e8f2813cec..a352fb3a46 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -987,8 +987,11 @@ static int post_config(apr_pool_t *p, */ for (; s; s = s->next) { open_rewritelog(s, p); - if (!first_time) - run_rewritemap_programs(s, p); + if (!first_time) { + if (run_rewritemap_programs(s, p) != APR_SUCCESS) { + return HTTP_INTERNAL_SERVER_ERROR; + } + } } return OK; } @@ -3365,7 +3368,7 @@ static apr_status_t rewritelock_remove(void *data) ** +-------------------------------------------------------+ */ -static void run_rewritemap_programs(server_rec *s, apr_pool_t *p) +static apr_status_t run_rewritemap_programs(server_rec *s, apr_pool_t *p) { rewrite_server_conf *conf; apr_file_t *fpin = NULL; @@ -3383,7 +3386,7 @@ static void run_rewritemap_programs(server_rec *s, apr_pool_t *p) * don't even try to do anything. */ if (conf->state == ENGINE_DISABLED) { - return; + return APR_SUCCESS; } rewritemaps = conf->rewritemaps; @@ -3405,15 +3408,15 @@ static void run_rewritemap_programs(server_rec *s, apr_pool_t *p) &fpout, &fpin, &fperr); if (rc != APR_SUCCESS || fpin == NULL || fpout == NULL) { ap_log_error(APLOG_MARK, APLOG_ERR, rc, s, - "mod_rewrite: could not fork child for " - "RewriteMap process"); - exit(1); + "mod_rewrite: could not startup RewriteMap " + "program %s", map->datafile); + return rc; } map->fpin = fpin; map->fpout = fpout; map->fperr = fperr; } - return; + return APR_SUCCESS; } /* child process code */ @@ -3424,11 +3427,13 @@ static apr_status_t rewritemap_program_child(apr_pool_t *p, const char *progname apr_status_t rc; apr_procattr_t *procattr; apr_proc_t *procnew; + apr_finfo_t st; char **argv; rc = apr_tokenize_to_argv(progname, &argv, p); - if (((rc = apr_procattr_create(&procattr, p)) != APR_SUCCESS) || + if (((rc = apr_stat(&st, argv[0], APR_FINFO_MIN, p)) != APR_SUCCESS) || + ((rc = apr_procattr_create(&procattr, p)) != APR_SUCCESS) || ((rc = apr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_FULL_NONBLOCK, APR_FULL_NONBLOCK)) != APR_SUCCESS) || diff --git a/modules/mappers/mod_rewrite.h b/modules/mappers/mod_rewrite.h index 7590c11278..14a4db7358 100644 --- a/modules/mappers/mod_rewrite.h +++ b/modules/mappers/mod_rewrite.h @@ -455,7 +455,7 @@ static apr_status_t rewritelock_create(server_rec *s, apr_pool_t *p); static apr_status_t rewritelock_remove(void *data); /* program map support */ -static void run_rewritemap_programs(server_rec *s, apr_pool_t *p); +static apr_status_t run_rewritemap_programs(server_rec *s, apr_pool_t *p); static apr_status_t rewritemap_program_child(apr_pool_t *p, const char *progname, apr_file_t **fpout, apr_file_t **fpin, apr_file_t **fperr);