From: Colm MacCarthaigh Date: Thu, 25 Aug 2005 11:51:24 +0000 (+0000) Subject: Append the .PID to the ScriptSock filename. This change ensures that multiple X-Git-Tag: 2.3.0~3080 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b379e699a4b7f2588fa11503738635317ca1516d;p=thirdparty%2Fapache%2Fhttpd.git Append the .PID to the ScriptSock filename. This change ensures that multiple running instances of httpd will not clobber each others script sockets. Because a different socket will be created for each instance, this change also unlinks the script-socket on exit, to prevent pollution. unlink() happens from within the parent process, since the change in userid's means the cgid process likely won't have the correct permissions. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@240044 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 16e1c8bed28..e30da9b75fe 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.3.0 [Remove entries to the current 2.0 and 2.2 section below, when backported] + *) mod_cgid: Append .PID to the script socket filename and remove the + script socket on exit. [Colm MacCarthaigh] + *) prefork and worker MPM's: Prevent children from holding open listening ports upon graceful restart. PR28167. [Colm MacCarthaigh, Brian Pinkerton ] diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index 72f60ef50b5..013b2010766 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -268,6 +268,15 @@ static void cgid_maint(int reason, void *data, apr_wait_t status) * up when pconf gets cleaned up */ kill(proc->pid, SIGHUP); /* send signal to daemon telling it to die */ + + /* Remove the cgi socket, we must do it here in order to try and + * guarantee the same permissions as when the socket was created. + */ + if (unlink(sockname) < 0 && errno != ENOENT) { + ap_log_error(APLOG_MARK, APLOG_ERR, errno, NULL, + "Couldn't unlink unix domain socket %s", + sockname); + } break; } } @@ -582,13 +591,6 @@ static int cgid_server(void *data) apr_signal(SIGCHLD, SIG_IGN); apr_signal(SIGHUP, daemon_signal_handler); - if (unlink(sockname) < 0 && errno != ENOENT) { - ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, - "Couldn't unlink unix domain socket %s", - sockname); - /* just a warning; don't bail out */ - } - if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, "Couldn't create unix domain socket"); @@ -818,7 +820,8 @@ static int cgid_start(apr_pool_t *p, server_rec *main_server, static int cgid_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { - sockname = DEFAULT_SOCKET; + sockname = apr_psprintf(pconf, "%s.%" APR_PID_T_FMT, DEFAULT_SOCKET, + getpid()); return OK; } @@ -932,8 +935,10 @@ static const char *set_script_socket(cmd_parms *cmd, void *dummy, const char *ar if (err != NULL) { return err; } - - sockname = ap_server_root_relative(cmd->pool, arg); + + /* Make sure the pid is appended to the sockname */ + sockname = apr_psprintf(cmd->pool, "%s.%" APR_PID_T_FMT, arg, getpid()); + sockname = ap_server_root_relative(cmd->pool, sockname); if (!sockname) { return apr_pstrcat(cmd->pool, "Invalid ScriptSock path",