Commit 9f3ee68d authored by Cliff Woolley's avatar Cliff Woolley
Browse files

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
parent 6ba2a536
Loading
Loading
Loading
Loading
+14 −9
Changes for modules/mappers/mod_rewrite.c: 14 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -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) ||
+1 −1
Changes for modules/mappers/mod_rewrite.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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);