Justin fixed some leaks a few days back that affected the daemon.
This supposedly fixes some leaks in the handler that I didn't know
about until last night. Comments? (not tested :) hopefully by this
evening I can validate everything)
problems solved:
+ not closing the unix socket on various paths
+ trying to close the unix socket twice (resulting in close(-1) call
due to APR magic) when we pass the unix socket down the filter chain
in a pipe bucket
Index: modules/generators/mod_cgid.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/generators/mod_cgid.c,v
retrieving revision 1.110
diff -u -r1.110 mod_cgid.c
--- modules/generators/mod_cgid.c 8 Jan 2002 06:26:09 -0000 1.110
+++ modules/generators/mod_cgid.c 28 Jan 2002 15:39:33 -0000
@@ -843,7 +843,12 @@
return ret;
}
-
+static apr_status_t close_unix_socket(void *thefd)
+{
+ int fd = (int)thefd;
+
+ return close(fd);
+}
/****************************************************************
*
@@ -926,7 +931,10 @@
if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
return log_scripterror(r, conf, HTTP_INTERNAL_SERVER_ERROR, errno,
"unable to create socket to cgi daemon");
- }
+ }
+ apr_pool_cleanup_register(r->pool, (void *)sd, close_unix_socket,
+ apr_pool_cleanup_null);
+
memset(&unix_addr, 0, sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
strcpy(unix_addr.sun_path, conf->sockname);
@@ -938,8 +946,10 @@
send_req(sd, r, argv0, env, CGI_REQ);
- /* We are putting the tempsock variable into a file so that we can use
- * a pipe bucket to send the data to the client.
+ /* We are putting the socket discriptor into an apr_file_t so that we can
+ * use a pipe bucket to send the data to the client.
+ * Note that this does not register a cleanup for the socket. We did
+ * that explicitly right after we created the socket.
*/
apr_os_file_put(&tempsock, &sd, 0, r->pool);
@@ -1033,7 +1043,13 @@
return HTTP_MOVED_TEMPORARILY;
}
- if (!r->header_only) {
+ if (!r->header_only) {
+ /* Passing our socket down the filter chain in a pipe bucket
+ * gives up the responsibility of closing the socket, so
+ * get rid of the cleanup.
+ */
+ apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
+
bb = apr_brigade_create(r->pool);
b = apr_bucket_pipe_create(tempsock);
APR_BRIGADE_INSERT_TAIL(bb, b);
@@ -1044,6 +1060,12 @@
}
if (nph) {
+ /* Passing our socket down the filter chain in a pipe bucket
+ * gives up the responsibility of closing the socket, so
+ * get rid of the cleanup.
+ */
+ apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
+
bb = apr_brigade_create(r->pool);
b = apr_bucket_pipe_create(tempsock);
APR_BRIGADE_INSERT_TAIL(bb, b);
@@ -1052,8 +1074,6 @@
ap_pass_brigade(r->output_filters, bb);
}
- apr_file_close(tempsock);
-
return OK; /* NOT r->status, even if it has changed. */
}
@@ -1188,7 +1208,9 @@
return log_scripterror(r, conf, HTTP_INTERNAL_SERVER_ERROR, 0,
"unable to create socket to cgi daemon");
}
-
+ apr_pool_cleanup_register(r->pool, (void *)sd, close_unix_socket,
+ apr_pool_cleanup_null);
+
memset(&unix_addr, 0, sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
strcpy(unix_addr.sun_path, conf->sockname);
@@ -1205,8 +1227,10 @@
send_req(sd, r, command, env, SSI_REQ);
- /* We are putting the tempsock variable into a file so that we can use
- * a pipe bucket to send the data to the client.
+ /* We are putting the socket discriptor into an apr_file_t so that we can
+ * use a pipe bucket to send the data to the client.
+ * Note that this does not register a cleanup for the socket. We did
+ * that explicitly right after we created the socket.
*/
apr_os_file_put(&tempsock, &sd, 0, r->pool);
@@ -1246,6 +1270,12 @@
}
if (!r->header_only) {
+ /* Passing our socket down the filter chain in a pipe bucket
+ * gives up the responsibility of closing the socket, so
+ * get rid of the cleanup.
+ */
+ apr_pool_cleanup_kill(r->pool, (void *)sd, close_unix_socket);
+
bcgi = apr_brigade_create(r->pool);
b = apr_bucket_pipe_create(tempsock);
APR_BRIGADE_INSERT_TAIL(bcgi, b);
--
Jeff Trawick | [EMAIL PROTECTED] | PGP public key at web site:
http://www.geocities.com/SiliconValley/Park/9289/
Born in Roswell... married an alien...