httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Stoddard" <b...@wstoddard.com>
Subject Re: [PATCH] allow pre_config to return error codes and prevent startup
Date Mon, 28 Jan 2002 23:42:05 GMT
Sounds reasonable to me.

Bill

> I have the need to return and detect errors from the pre_config phase.
> I'd like this mostly for detecting apr_proc_detach errors, but this will
> be useful in other places too. (Something tells me we should have done
> this in all the RUN_ALL-type hooks).
>
> Here's a patch that implements it. It seems to work fine on Solaris
> and Linux and will probably work everywhere else unless there's a typo.
>
> Does anyone see a reason not to apply this?
>
> -aaron
>
>
> Index: modules/arch/netware/mod_nw_ssl.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/modules/arch/netware/mod_nw_ssl.c,v
> retrieving revision 1.3
> diff -u -u -r1.3 mod_nw_ssl.c
> --- modules/arch/netware/mod_nw_ssl.c 23 Nov 2001 16:35:21 -0000 1.3
> +++ modules/arch/netware/mod_nw_ssl.c 28 Jan 2002 23:10:42 -0000
> @@ -334,10 +334,12 @@
>      return APR_SUCCESS;
>  }
>
> -static void nwssl_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
> +static int nwssl_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
>                           apr_pool_t *ptemp)
>  {
>      ap_seclisteners = NULL;
> +
> +    return OK;
>  }
>
>  static int nwssl_post_config(apr_pool_t *pconf, apr_pool_t *plog,
> Index: modules/experimental/mod_example.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/modules/experimental/mod_example.c,v
> retrieving revision 1.31
> diff -u -u -r1.31 mod_example.c
> --- modules/experimental/mod_example.c 10 Jan 2002 09:20:28 -0000 1.31
> +++ modules/experimental/mod_example.c 28 Jan 2002 23:10:46 -0000
> @@ -847,13 +847,15 @@
>   * This routine is called before the server processes the configuration
>   * files.  There is no return value.
>   */
> -static void x_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
> -                         apr_pool_t *ptemp)
> +static int x_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
> +                        apr_pool_t *ptemp)
>  {
>      /*
>       * Log the call and exit.
>       */
>      trace_add(NULL, NULL, NULL, "x_pre_config()");
> +
> +    return OK;
>  }
>
>  /*
> Index: modules/loggers/mod_log_config.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/modules/loggers/mod_log_config.c,v
> retrieving revision 1.76
> diff -u -u -r1.76 mod_log_config.c
> --- modules/loggers/mod_log_config.c 10 Jan 2002 03:23:33 -0000 1.76
> +++ modules/loggers/mod_log_config.c 28 Jan 2002 23:10:48 -0000
> @@ -1194,7 +1194,7 @@
>      apr_hash_set(log_hash, tag, 1, (const void *)log_struct);
>  }
>
> -static void log_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int log_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      static APR_OPTIONAL_FN_TYPE(ap_register_log_handler) *log_pfn_register;
>
> @@ -1229,6 +1229,8 @@
>          log_pfn_register(p, "U", log_request_uri, 1);
>          log_pfn_register(p, "s", log_status, 1);
>      }
> +
> +    return OK;
>  }
>
>  static void register_hooks(apr_pool_t *p)
> Index: modules/metadata/mod_headers.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/modules/metadata/mod_headers.c,v
> retrieving revision 1.35
> diff -u -u -r1.35 mod_headers.c
> --- modules/metadata/mod_headers.c 8 Nov 2001 23:26:36 -0000 1.35
> +++ modules/metadata/mod_headers.c 28 Jan 2002 23:10:50 -0000
> @@ -605,12 +605,14 @@
>      h = tag_handler;
>      apr_hash_set(format_tag_hash, tag, 1, h);
>  }
> -static void header_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int header_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      format_tag_hash = apr_hash_make(p);
>      register_format_tag_handler(p, "D", (void*) header_request_duration, 0);
>      register_format_tag_handler(p, "t", (void*) header_request_time, 0);
>      register_format_tag_handler(p, "e", (void*) header_request_env_var, 0);
> +
> +    return OK;
>  }
>
>  static void register_hooks(apr_pool_t *p)
> Index: modules/ssl/mod_ssl.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/modules/ssl/mod_ssl.c,v
> retrieving revision 1.42
> diff -u -u -r1.42 mod_ssl.c
> --- modules/ssl/mod_ssl.c 29 Nov 2001 07:07:36 -0000 1.42
> +++ modules/ssl/mod_ssl.c 28 Jan 2002 23:10:52 -0000
> @@ -204,7 +204,7 @@
>   *  the various processing hooks
>   */
>
> -static void ssl_hook_pre_config(
> +static int ssl_hook_pre_config(
>      apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      /* Register us to handle mod_log_config %c/%x variables */
> @@ -215,6 +215,8 @@
>      /* XXX: Register us to handle mod_status extensions that don't exist yet */
>      ssl_scache_status_register(pconf);
>  #endif /* -0- */
> +
> +    return OK;
>  }
>
>  static int ssl_hook_pre_connection(conn_rec *c)
> Index: server/config.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/config.c,v
> retrieving revision 1.143
> diff -u -u -r1.143 config.c
> --- server/config.c 2 Jan 2002 23:27:57 -0000 1.143
> +++ server/config.c 28 Jan 2002 23:10:56 -0000
> @@ -118,9 +118,9 @@
>
>  AP_IMPLEMENT_HOOK_RUN_ALL(int,header_parser,
>                            (request_rec *r),(r),OK,DECLINED)
> -AP_IMPLEMENT_HOOK_VOID(pre_config,
> +AP_IMPLEMENT_HOOK_RUN_ALL(int,pre_config,
>          (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp),
> -                       (pconf,plog,ptemp))
> +                       (pconf,plog,ptemp),OK,DECLINED)
>  AP_IMPLEMENT_HOOK_RUN_ALL(int,post_config,
>          (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
>                          server_rec *s),(pconf,plog,ptemp,s),OK,DECLINED)
> Index: server/main.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/main.c,v
> retrieving revision 1.115
> diff -u -u -r1.115 main.c
> --- server/main.c 17 Jan 2002 22:28:08 -0000 1.115
> +++ server/main.c 28 Jan 2002 23:11:02 -0000
> @@ -433,7 +433,10 @@
>
>      ap_server_root = def_server_root;
>      server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
> -    ap_run_pre_config(pconf, plog, ptemp);
> +    if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
> +        ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR| APLOG_NOERRNO, 0, NULL,
"Pre-configuration failed\n");
> +        destroy_and_exit_process(process, 1);
> +    }
>      ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
>      ap_fixup_virtual_hosts(pconf, server_conf);
>      ap_fini_vhost_config(pconf, server_conf);
> @@ -469,7 +472,10 @@
>   apr_pool_create(&ptemp, pconf);
>   ap_server_root = def_server_root;
>          server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
> - ap_run_pre_config(pconf, plog, ptemp);
> +        if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
> +            ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR| APLOG_NOERRNO, 0, NULL,
"Pre-configuration failed\n");
> +            destroy_and_exit_process(process, 1);
> +        }
>          ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
>          ap_fixup_virtual_hosts(pconf, server_conf);
>          ap_fini_vhost_config(pconf, server_conf);
> Index: server/mpm/beos/beos.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/mpm/beos/beos.c,v
> retrieving revision 1.79
> diff -u -u -r1.79 beos.c
> --- server/mpm/beos/beos.c 28 Jan 2002 00:41:31 -0000 1.79
> +++ server/mpm/beos/beos.c 28 Jan 2002 23:11:05 -0000
> @@ -992,7 +992,7 @@
>      return 0;
>  }
>
> -static void beos_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int beos_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      static int restart_num = 0;
>      int no_detach, debug;
> @@ -1028,6 +1028,8 @@
>      ap_scoreboard_fname = DEFAULT_SCOREBOARD;
>
>      apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
> +
> +    return OK;
>  }
>
>  static void beos_hooks(apr_pool_t *p)
> Index: server/mpm/mpmt_os2/mpmt_os2.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/mpm/mpmt_os2/mpmt_os2.c,v
> retrieving revision 1.13
> diff -u -u -r1.13 mpmt_os2.c
> --- server/mpm/mpmt_os2/mpmt_os2.c 10 Jan 2002 15:09:18 -0000 1.13
> +++ server/mpm/mpmt_os2/mpmt_os2.c 28 Jan 2002 23:11:07 -0000
> @@ -494,7 +494,7 @@
>
>  /* Configuration handling stuff */
>
> -static void mpmt_os2_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int mpmt_os2_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      one_process = ap_exists_config_define("ONE_PROCESS") ||
>                    ap_exists_config_define("DEBUG");
> @@ -507,6 +507,8 @@
>      ap_extended_status = 0;
>      ap_min_spare_threads = DEFAULT_MIN_SPARE_THREAD;
>      ap_max_spare_threads = DEFAULT_MAX_SPARE_THREAD;
> +
> +    return OK;
>  }
>
>
> Index: server/mpm/netware/mpm_netware.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/mpm/netware/mpm_netware.c,v
> retrieving revision 1.26
> diff -u -u -r1.26 mpm_netware.c
> --- server/mpm/netware/mpm_netware.c 28 Jan 2002 00:41:31 -0000 1.26
> +++ server/mpm/netware/mpm_netware.c 28 Jan 2002 23:11:10 -0000
> @@ -953,7 +953,7 @@
>      return 0;
>  }
>
> -static void netware_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int netware_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      int debug;
>
> @@ -970,6 +970,8 @@
>      ap_scoreboard_fname = DEFAULT_SCOREBOARD;
>      ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
>      ap_extended_status = 0;
> +
> +    return OK;
>  }
>
>  static void netware_mpm_hooks(apr_pool_t *p)
> Index: server/mpm/perchild/perchild.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/mpm/perchild/perchild.c,v
> retrieving revision 1.102
> diff -u -u -r1.102 perchild.c
> --- server/mpm/perchild/perchild.c 28 Jan 2002 00:41:31 -0000 1.102
> +++ server/mpm/perchild/perchild.c 28 Jan 2002 23:11:15 -0000
> @@ -1424,7 +1424,7 @@
>      return 0;
>  }
>
> -static void perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      static int restart_num = 0;
>      int no_detach, debug;
> @@ -1497,6 +1497,8 @@
>          child_info_table[i].gid = -1;
>          child_info_table[i].sd = -1;
>      }
> +
> +    return OK;
>  }
>
>  static int pass_request(request_rec *r)
> Index: server/mpm/prefork/prefork.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/mpm/prefork/prefork.c,v
> retrieving revision 1.232
> diff -u -u -r1.232 prefork.c
> --- server/mpm/prefork/prefork.c 28 Jan 2002 00:41:31 -0000 1.232
> +++ server/mpm/prefork/prefork.c 28 Jan 2002 23:11:19 -0000
> @@ -1200,7 +1200,7 @@
>      return 0;
>  }
>
> -static void prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      static int restart_num = 0;
>      int no_detach, debug;
> @@ -1239,6 +1239,8 @@
>      ap_extended_status = 0;
>
>      apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
> +
> +    return OK;
>  }
>
>  static void prefork_hooks(apr_pool_t *p)
> Index: server/mpm/winnt/mpm_winnt.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm_winnt.c,v
> retrieving revision 1.211
> diff -u -u -r1.211 mpm_winnt.c
> --- server/mpm/winnt/mpm_winnt.c 28 Jan 2002 00:41:32 -0000 1.211
> +++ server/mpm/winnt/mpm_winnt.c 28 Jan 2002 23:11:25 -0000
> @@ -1933,7 +1933,7 @@
>  }
>
>
> -static void winnt_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
> +static int winnt_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
>  {
>      /* Handle the following SCM aspects in this phase:
>       *
> @@ -1955,6 +1955,7 @@
>          ap_log_error(APLOG_MARK,APLOG_CRIT, service_to_start_success, NULL,
>                       "%s: Unable to start the service manager.",
>                       service_name);
> +        /* XXX: return HTTP_INTERNAL_SERVER_ERROR? */
>          exit(1);
>      }
>
> @@ -1974,6 +1975,8 @@
>      ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
>
>      apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
> +
> +    return OK;
>  }
>
>  static int winnt_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
server_rec* server)
> Index: server/mpm/worker/worker.c
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/server/mpm/worker/worker.c,v
> retrieving revision 1.63
> diff -u -u -r1.63 worker.c
> --- server/mpm/worker/worker.c 28 Jan 2002 00:49:04 -0000 1.63
> +++ server/mpm/worker/worker.c 28 Jan 2002 23:11:29 -0000
> @@ -1540,7 +1540,7 @@
>      return 0;
>  }
>
> -static void worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
> +static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
>                                apr_pool_t *ptemp)
>  {
>      static int restart_num = 0;
> @@ -1618,6 +1618,8 @@
>      ap_extended_status = 0;
>
>      apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
> +
> +    return OK;
>  }
>
>  static void worker_hooks(apr_pool_t *p)
> Index: include/http_config.h
> ===================================================================
> RCS file: /home/cvs/httpd-2.0/include/http_config.h,v
> retrieving revision 1.92
> diff -u -u -r1.92 http_config.h
> --- include/http_config.h 24 Nov 2001 00:08:29 -0000 1.92
> +++ include/http_config.h 28 Jan 2002 23:11:33 -0000
> @@ -970,8 +970,9 @@
>   * @param pconf The config pool
>   * @param plog The logging streams pool
>   * @param ptemp The temporary pool
> + * @return OK or DECLINED on success anything else is a error
>   */
> -AP_DECLARE_HOOK(void,pre_config,(apr_pool_t *pconf,apr_pool_t *plog,apr_pool_t *ptemp))
> +AP_DECLARE_HOOK(int,pre_config,(apr_pool_t *pconf,apr_pool_t *plog,apr_pool_t *ptemp))
>
>  /**
>   * Run the post_config function for each module
>


Mime
View raw message