mod_cgid.c revision efd83d1dd1a25688a3093c5a542ae16bacef62dd
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* Licensed to the Apache Software Foundation (ASF) under one or more
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * contributor license agreements. See the NOTICE file distributed with
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * this work for additional information regarding copyright ownership.
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * The ASF licenses this file to You under the Apache License, Version 2.0
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * (the "License"); you may not use this file except in compliance with
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * the License. You may obtain a copy of the License at
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * Unless required by applicable law or agreed to in writing, software
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * distributed under the License is distributed on an "AS IS" BASIS,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * See the License for the specific language governing permissions and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * limitations under the License.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * http_script: keeps all script-related ramblings together.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * Compliant to cgi/1.1 spec
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * Adapted by rst from original NCSA code by Rob McCool
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * custom error responses, and DOCUMENT_ROOT because we found it useful.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * they fail.
4d59c48d506af681afac46a88516e369495c1ae4nilgun/* ### should be tossed in favor of APR */
243722a207c664dc2c62388a2095b1cba1fea3f0nilgunstatic int cgid_start(apr_pool_t *p, server_rec *main_server, apr_proc_t *procnew);
243722a207c664dc2c62388a2095b1cba1fea3f0nilgunstatic int cgid_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server);
4d59c48d506af681afac46a88516e369495c1ae4nilgunstatic int handle_exec(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb);
4d59c48d506af681afac46a88516e369495c1ae4nilgunstatic APR_OPTIONAL_FN_TYPE(ap_register_include_handler) *cgid_pfn_reg_with_ssi;
4d59c48d506af681afac46a88516e369495c1ae4nilgunstatic APR_OPTIONAL_FN_TYPE(ap_ssi_get_tag_and_value) *cgid_pfn_gtv;
4d59c48d506af681afac46a88516e369495c1ae4nilgunstatic APR_OPTIONAL_FN_TYPE(ap_ssi_parse_string) *cgid_pfn_ps;
4d59c48d506af681afac46a88516e369495c1ae4nilgunstatic int total_modules = 0;
4d59c48d506af681afac46a88516e369495c1ae4nilgunstatic int daemon_should_exit = 0;
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic const char *sockname;
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 };
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* The APR other-child API doesn't tell us how the daemon exited
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * (SIGSEGV vs. exit(1)). The other-child maintenance function
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * needs to decide whether to restart the daemon after a failure
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * based on whether or not it exited due to a fatal startup error
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * or something that happened at steady-state. This exit status
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * is unlikely to collide with exit signals.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* Read and discard the data in the brigade produced by a CGI script */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic void discard_script_output(apr_bucket_brigade *bb);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* This doer will only ever be called when we are sure that we have
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * a valid ugid.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic ap_unix_identity_t *cgid_suexec_id_doer(const request_rec *r)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_get_module_config(r->request_config, &cgid_module);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* KLUDGE --- for back-combatibility, we don't have to check ExecCGI
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * in ScriptAliased directories, which means we need to know if this
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * request came through ScriptAlias or not... so the Alias module
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * leaves a note for us.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony const char *t = apr_table_get(r->notes, "alias-forced-type");
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* Configuration stuff */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony#define DEFAULT_SOCKET DEFAULT_REL_RUNTIMEDIR "/cgisock"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony#define GETPID_REQ 3 /* get the pid of script created for prior request */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* DEFAULT_CGID_LISTENBACKLOG controls the max depth on the unix socket's
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * pending connection queue. If a bunch of cgi requests arrive at about
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * the same time, connections from httpd threads/processes will back up
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * in the queue while the cgid process slowly forks off a child to process
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * each connection on the unix socket. If the queue is too short, the
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * httpd process will get ECONNREFUSED when trying to connect.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* DEFAULT_CONNECT_ATTEMPTS controls how many times we'll try to connect
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * to the cgi daemon from the thread/process handling the cgi request.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * Generally we want to retry when we get ECONNREFUSED since it is
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * probably because the listen queue is full. We need to try harder so
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * the client doesn't see it as a 503 error.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * Set this to 0 to continually retry until the connect works or Apache
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * terminates.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonytypedef struct {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony const char *logname;
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonytypedef struct {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony int req_type; /* request type (CGI_REQ, SSI_REQ, etc.) */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony unsigned long conn_id; /* connection id; daemon uses this as a hash value
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * to find the script pid when it is time for that
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * process to be cleaned up
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony pid_t ppid; /* sanity check for config problems leading to
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * wrong cgid socket use
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun/* This routine is called to create the argument list to be passed
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * to the CGI script. When suexec is enabled, the suexec path, user, and
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * group are the first three arguments to be passed; if not, all three
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * must be NULL. The query info is split into separate arguments, where
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * "+" is the separator between keyword arguments.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * Do not process the args if they containing an '=' assignment.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic char **create_argv(apr_pool_t *p, char *path, char *user, char *group,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* count the number of keywords */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony numwords = APACHE_ARG_MAX - 5; /* Truncate args to prevent overrun */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony av = (char **) apr_pcalloc(p, (numwords + 5) * sizeof(char *));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic void cgid_maint(int reason, void *data, apr_wait_t status)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* If apache is not terminating or restarting,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * restart the cgid daemon
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * assume we shouldn't restart daemon
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state) == APR_SUCCESS &&
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "cgid daemon failed to initialize");
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "cgid daemon process died, restarting");
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* don't do anything; server is stopping or restarting */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* Restart the child cgid daemon process */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* we get here when pcgi is cleaned up; pcgi gets cleaned
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * up when pconf gets cleaned up
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony kill(proc->pid, SIGHUP); /* send signal to daemon telling it to die */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* Remove the cgi socket, we must do it here in order to try and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * guarantee the same permissions as when the socket was created.
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun "Couldn't unlink unix domain socket %s",
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* deal with incomplete reads and signals
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * assume you really have to read buf_size bytes
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic apr_status_t sock_read(int fd, void *vbuf, size_t buf_size)
331e0914b4c54463a06069051f0245b4058a90c2nilgun rc = read(fd, buf + bytes_read, buf_size - bytes_read);
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun case 0: /* unexpected */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony/* deal with signals
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic apr_status_t sock_write(int fd, const void *buf, size_t buf_size)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if (rc < 0) {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic apr_status_t sock_writev(int fd, request_rec *r, int count, ...)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony vec = (struct iovec *)apr_palloc(r->pool, count * sizeof(struct iovec));
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun for (i = 0; i < count; i++) {
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun if (rc < 0) {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic apr_status_t get_req(int fd, request_rec *r, char **argv0, char ***env,
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun r->server = apr_pcalloc(r->pool, sizeof(server_rec));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* read the request header */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* no more data sent for this request */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* handle module indexes and such */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony rconf = (void **) apr_pcalloc(r->pool, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun temp_core = (core_request_config *)apr_palloc(r->pool, sizeof(core_module));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_set_module_config(r->request_config, &cgid_module, (void *)&req->ugid);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* Read the filename, argv0, uri, and args */
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun r->filename = apr_pcalloc(r->pool, req->filename_len + 1);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if ((stat = sock_read(fd, r->filename, req->filename_len)) != APR_SUCCESS ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony (stat = sock_read(fd, *argv0, req->argv0_len)) != APR_SUCCESS ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony (stat = sock_read(fd, r->uri, req->uri_len)) != APR_SUCCESS) {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony r->args = apr_pcalloc(r->pool, req->args_len + 1); /* empty string if no args */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if ((stat = sock_read(fd, r->args, req->args_len)) != APR_SUCCESS) {
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun /* read the environment variables */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony environ = apr_pcalloc(r->pool, (req->env_count + 2) *sizeof(char *));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if ((stat = sock_read(fd, &curlen, sizeof(curlen))) != APR_SUCCESS) {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if ((stat = sock_read(fd, environ[i], curlen)) != APR_SUCCESS) {
331e0914b4c54463a06069051f0245b4058a90c2nilgun temp_core->limit_cpu = (struct rlimit *)apr_palloc (sizeof(struct rlimit));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony sock_read(fd, temp_core->limit_cpu, sizeof(struct rlimit));
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun#if defined (RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun temp_core->limit_mem = (struct rlimit *)apr_palloc(r->pool, sizeof(struct rlimit));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony sock_read(fd, temp_core->limit_mem, sizeof(struct rlimit));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony temp_core->limit_nproc = (struct rlimit *)apr_palloc(r->pool, sizeof(struct rlimit));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony sock_read(fd, temp_core->limit_nproc, sizeof(struct rlimit));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic apr_status_t send_req(int fd, request_rec *r, char *argv0, char **env,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_unix_identity_t * ugid = ap_run_get_suexec_identity(r);
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun for (req.env_count = 0; env[req.env_count]; req.env_count++) {
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun /* Write the request header */
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun /* write the environment variables */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if ((stat = sock_writev(fd, r, 2, &curlen, sizeof(curlen),
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun stat = sock_write(fd, conf->limit_cpu, sizeof(struct rlimit));
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony stat = sock_write(fd, conf->limit_mem, sizeof(struct rlimit));
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun stat = sock_write(fd, conf->limit_nproc, sizeof(struct rlimit));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonystatic void cgid_child_errfn(apr_pool_t *pool, apr_status_t err,
331e0914b4c54463a06069051f0245b4058a90c2nilgun apr_pool_userdata_get(&vr, ERRFN_USERDATA_KEY, pool);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* sure we got r, but don't call ap_log_rerror() because we don't
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * have r->headers_in and possibly other storage referenced by
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * ap_log_rerror()
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun ap_log_error(APLOG_MARK, APLOG_ERR, err, r->server, "%s", description);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* Close our copy of the listening sockets */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* cgid should use its own suexec doer */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_hook_get_suexec_identity(cgid_suexec_id_doer, NULL, NULL,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "Couldn't create unix domain socket");
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun omask = umask(0077); /* so that only Apache can use socket */
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun rc = bind(sd, (struct sockaddr *)server_addr, server_addr_len);
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun umask(omask); /* can't fail, so can't clobber errno */
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun if (rc < 0) {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "Couldn't bind unix domain socket %s",
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* Not all flavors of unix use the current umask for AF_UNIX perms */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony rv = apr_file_perms_set(sockname, APR_FPROT_UREAD|APR_FPROT_UWRITE|APR_FPROT_UEXECUTE);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_log_error(APLOG_MARK, APLOG_CRIT, rv, main_server,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "Couldn't set permissions on unix domain socket %s",
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "Couldn't listen on unix domain socket");
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun if (chown(sockname, ap_unixd_config.user_id, -1) < 0) {
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun "Couldn't change owner of unix domain socket %s",
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* if running as root, switch to configured user/group */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if ((rc = ap_run_drop_privileges(pcgi, ap_server_conf)) != 0) {
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun const char * const *argv;
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun sd2 = accept(sd, (struct sockaddr *)&unix_addr, &len);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* The network has been shut down, no need to continue. Die gracefully */
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "Error accepting on cgid socket");
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "Error reading request on cgid socket");
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "CGI request received from wrong server instance; "
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "see ScriptSock directive");
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony pid = (pid_t)((long)apr_hash_get(script_hash, &cgid_req.conn_id, sizeof(cgid_req.conn_id)));
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony "Error writing pid %" APR_PID_T_FMT " to handler", pid);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony apr_os_file_put(&r->server->error_log, &errfileno, 0, r->pool);
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if (((rc = apr_procattr_create(&procattr, ptrans)) != APR_SUCCESS) ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* XXX apr_procattr_child_*_set() is creating an unnecessary
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * pipe between this process and the child being created...
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * It is cleaned up with the temporary pool for this request.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ((rc = apr_procattr_child_err_set(procattr, r->server->error_log, NULL)) != APR_SUCCESS) ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ((rc = apr_procattr_child_in_set(procattr, inout, NULL)) != APR_SUCCESS))) ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ((rc = apr_procattr_child_out_set(procattr, inout, NULL)) != APR_SUCCESS) ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ap_make_dirstr_parent(r->pool, r->filename))) != APR_SUCCESS) ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ((rc = apr_procattr_cmdtype_set(procattr, cmd_type)) != APR_SUCCESS) ||
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ((rc = apr_procattr_child_errfn_set(procattr, cgid_child_errfn)) != APR_SUCCESS)) {
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony /* Something bad happened, tell the world.
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * ap_log_rerror() won't work because the header table used by
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * ap_log_rerror() hasn't been replicated in the phony r
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun "couldn't set child process attributes: %s", r->filename);
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun apr_pool_userdata_set(r, ERRFN_USERDATA_KEY, apr_pool_cleanup_null, ptrans);
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun argv = (const char * const *)create_argv(r->pool, NULL, NULL, NULL, argv0, r->args);
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun /* We want to close sd2 for the new CGI process too.
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * If it is left open it'll make ap_pass_brigade() block
243722a207c664dc2c62388a2095b1cba1fea3f0nilgun * waiting for EOF if CGI forked something running long.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * close(sd2) here should be okay, as CGI channel
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony * is already dup()ed by apr_procattr_child_{in,out}_set()
(const char * const *)env,
(const char * const *)env,
return DECLINED;
else if (daemon_pid == 0) {
return OK;
return OK;
int first_time = 0;
module **m;
void *data;
root_pool = p;
if (!data) {
if (!first_time) {
total_modules = 0;
return ret;
return ret;
cgid_server_conf *c =
&cgid_module);
return NULL;
&cgid_module);
return NULL;
&cgid_module);
return NULL;
return err;
if (!sockname) {
return NULL;
{NULL}
return ret;
apr_file_close(f);
return ret;
apr_bucket *e;
const char *buf;
int first;
if (script_err) {
return ret;
&& *dbuf) {
e = APR_BUCKET_NEXT(e))
if (APR_BUCKET_IS_EOS(e)) {
if (first) {
first = 0;
if (script_err) {
if (script_err) {
apr_file_close(f);
return ret;
int sd;
int connect_tries;
connect_tries = 0;
return OK;
apr_bucket *e;
const char *buf;
e = APR_BUCKET_NEXT(e))
if (APR_BUCKET_IS_EOS(e)) {
struct cleanup_script_info {
request_rec *r;
unsigned long conn_id;
#ifdef _AIX
return APR_SUCCESS;
return APR_EGENERAL;
return APR_SUCCESS;
pid);
return APR_SUCCESS;
pid);
return APR_EGENERAL;
int sd;
int rc;
return APR_EGENERAL;
return stat;
return stat;
if (pid == 0) {
return APR_EGENERAL;
apr_bucket *b;
int is_included;
int sd;
char **env;
return DECLINED;
argv0++;
ap_add_cgi_vars(r);
return retval;
info->r = r;
argv0++;
seen_eos = 0;
dbpos = 0;
return HTTP_REQUEST_TIME_OUT;
return HTTP_INTERNAL_SERVER_ERROR;
const char *data;
if (child_stopped_reading) {
int cursize;
while (!seen_eos);
if (!nph) {
const char *location;
int ret;
return OK;
return ret;
return OK;
return HTTP_MOVED_TEMPORARILY;
if (nph) {
request_rec *r = f->r;
int rr_status;
return APR_EGENERAL;
return APR_EGENERAL;
return APR_EGENERAL;
if (location) {
char *buffer;
f->c->bucket_alloc));
return APR_SUCCESS;
if (r->args) {
char **env;
int sd;
int retval;
request_rec *r = f->r;
&cgid_module);
add_ssi_vars(r);
return retval;
info->r = r;
f->c->bucket_alloc));
return APR_SUCCESS;
request_rec *r = f->r;
r->filename);
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;