return ret;
}
-
+static apr_status_t close_unix_socket(void *thefd)
+{
+ int fd = (int)thefd;
+
+ return close(fd);
+}
/****************************************************************
*
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);
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);
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);
}
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);
ap_pass_brigade(r->output_filters, bb);
}
- apr_file_close(tempsock);
-
return OK; /* NOT r->status, even if it has changed. */
}
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);
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);
}
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);