apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <...@covalent.net>
Subject Inheritable APR handles.
Date Sat, 14 Jul 2001 23:50:52 GMT

This patch begins to implement the inherit flag that Will Rowe was talking
about yesterday on Unix.  Basically, every APR type that can be inherited
would specify at creation time whether it should be created to be
inherited or not.  Then, there are two functions, apr_foo_set_inherit and
apr_foo_unset_inherit that flip the flag.  This will finally get us
registering child cleanups correctly.  I have created a new APR header,
apr_inherit.h, which implements some macros to create the
apr_foo_(un)set_inherit functions for Unix, I have copied that inline in
this message.

Unless I hear objections, I will commit this code either tomorrow or
Monday.  Once it is committed, I will use it to fix a couple of bugs in
Apache.  :-)

Index: server/listen.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/listen.c,v
retrieving revision 1.53
diff -u -d -b -w -u -r1.53 listen.c
--- server/listen.c	2001/04/05 19:04:14	1.53
+++ server/listen.c	2001/07/14 23:43:26
@@ -191,7 +191,7 @@
     if (default_family == APR_UNSPEC) {
         apr_socket_t *tmp_sock;

-        if (apr_socket_create(&tmp_sock, APR_INET6, SOCK_STREAM,
+        if (apr_socket_create(&tmp_sock, APR_INET6, SOCK_STREAM, APR_INHERIT,
                               p) == APR_SUCCESS) {
             apr_socket_close(tmp_sock);
             default_family = APR_INET6;
@@ -254,7 +254,7 @@
         return;
     }
     if ((status = apr_socket_create(&new->sd, new->bind_addr->sa.sin.sin_family,
-                                    SOCK_STREAM, process->pool)) != APR_SUCCESS) {
+                                    SOCK_STREAM, APR_INHERIT, process->pool)) != APR_SUCCESS)
{
         ap_log_perror(APLOG_MARK, APLOG_CRIT, status, process->pool,
                      "alloc_listener: failed to get a socket for %s", addr);
         return;
@@ -300,7 +300,7 @@
     }
     old_listeners = NULL;

-    apr_pool_cleanup_register(pconf, NULL, apr_pool_cleanup_null, close_listeners_on_exec);
+    apr_pool_cleanup_register(pconf, NULL, close_listeners_on_exec, close_listeners_on_exec);

     return num_open ? 0 : -1;
 }
Index: server/mpm_common.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm_common.c,v
retrieving revision 1.55
diff -u -d -b -w -u -r1.55 mpm_common.c
--- server/mpm_common.c	2001/07/11 14:48:23	1.55
+++ server/mpm_common.c	2001/07/14 23:43:26
@@ -403,7 +403,7 @@
     }

     apr_sockaddr_info_get(&sa, "127.0.0.1", APR_UNSPEC, ap_listeners->bind_addr->port,
0, pod->p);
-    rv = apr_socket_create(&sock, sa->family, SOCK_STREAM, pod->p);
+    rv = apr_socket_create(&sock, sa->family, SOCK_STREAM, APR_NO_INHERIT, pod->p);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
                      "get socket to connect to listener");
Index: server/rfc1413.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/rfc1413.c,v
retrieving revision 1.40
diff -u -d -b -w -u -r1.40 rfc1413.c
--- server/rfc1413.c	2001/04/10 20:41:45	1.40
+++ server/rfc1413.c	2001/07/14 23:43:26
@@ -83,6 +83,7 @@
 #include "apr_network_io.h"
 #include "apr_strings.h"
 #include "apr_lib.h"
+#include "apr_inherit.h"

 #define APR_WANT_STDIO
 #define APR_WANT_STRFUNC
@@ -140,7 +141,7 @@

     if ((rv = apr_socket_create(newsock,
                                 localsa->sa.sin.sin_family, /* has to match */
-                                SOCK_STREAM, conn->pool)) != APR_SUCCESS) {
+                                SOCK_STREAM, APR_NO_INHERIT, conn->pool)) != APR_SUCCESS)
{
 	ap_log_error(APLOG_MARK, APLOG_CRIT, rv, srv,
                      "rfc1413: error creating query socket");
         return rv;
Index: srclib/apr/include/apr_network_io.h
===================================================================
RCS file: /home/cvs/apr/include/apr_network_io.h,v
retrieving revision 1.102
diff -u -d -b -w -u -r1.102 apr_network_io.h
--- srclib/apr/include/apr_network_io.h	2001/05/02 02:32:44	1.102
+++ srclib/apr/include/apr_network_io.h	2001/07/14 23:43:29
@@ -63,6 +63,7 @@
 #include "apr_pools.h"
 #include "apr_file_io.h"
 #include "apr_errno.h"
+#include "apr_inherit.h"

 #if APR_HAVE_NETINET_IN_H
 #include <netinet/in.h>
@@ -240,12 +241,13 @@
  * @param new_sock The new socket that has been set up.
  * @param family The address family of the socket (e.g., APR_INET).
  * @param type The type of the socket (e.g., SOCK_STREAM).
+ * @param inherit Should this socket be inherited by child processes
  * @param cont The pool to use
  * @deffunc apr_status_t apr_socket_create(apr_socket_t **new_sock, int family, int type,
apr_pool_t *cont)
  */
 APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new_sock,
                                             int family, int type,
-                                            apr_pool_t *cont);
+                                            int inherit, apr_pool_t *cont);

 /**
  * Shutdown either reading, writing, or both sides of a tcp socket.
@@ -800,6 +802,8 @@
 apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char name[16],
                                       char args[256 - 16]);
 #endif
+
+APR_DECLARE_SET_INHERIT(socket);

 #ifdef __cplusplus
 }
Index: srclib/apr/include/apr_portable.h
===================================================================
RCS file: /home/cvs/apr/include/apr_portable.h,v
retrieving revision 1.62
diff -u -d -b -w -u -r1.62 apr_portable.h
--- srclib/apr/include/apr_portable.h	2001/07/07 16:45:08	1.62
+++ srclib/apr/include/apr_portable.h	2001/07/14 23:43:29
@@ -321,6 +321,7 @@
  * @param apr_sock The new socket that has been set up
  * @param os_sock_info The os representation of the socket handle and
  *        other characteristics of the socket
+ * @param inherit Should this socket be inherited by child processes
  * @param cont The pool to use
  * @deffunc apr_status_t apr_os_sock_make(apr_socket_t **apr_sock, apr_os_sock_info_t *os_sock_info,
apr_pool_t *cont)
  * @tip If you only know the descriptor/handle or if it isn't really
@@ -328,6 +329,7 @@
  */
 APR_DECLARE(apr_status_t) apr_os_sock_make(apr_socket_t **apr_sock,
                                            apr_os_sock_info_t *os_sock_info,
+                                           int inherit,
                                            apr_pool_t *cont);

 /**
Index: srclib/apr/include/arch/unix/networkio.h
===================================================================
RCS file: /home/cvs/apr/include/arch/unix/networkio.h,v
retrieving revision 1.46
diff -u -d -b -w -u -r1.46 networkio.h
--- srclib/apr/include/arch/unix/networkio.h	2001/07/10 15:01:33	1.46
+++ srclib/apr/include/arch/unix/networkio.h	2001/07/14 23:43:29
@@ -135,6 +135,7 @@
     int local_port_unknown;
     int local_interface_unknown;
     apr_int32_t netmask;
+    int inherit;
 };

 struct apr_pollfd_t {
Index: srclib/apr/network_io/unix/sockets.c
===================================================================
RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
retrieving revision 1.76
diff -u -d -b -w -u -r1.76 sockets.c
--- srclib/apr/network_io/unix/sockets.c	2001/07/10 17:18:55	1.76
+++ srclib/apr/network_io/unix/sockets.c	2001/07/14 23:43:31
@@ -53,7 +53,9 @@
  */

 #include "networkio.h"
+#include "apr_network_io.h"
 #include "apr_portable.h"
+#include "apr_inherit.h"

 static apr_status_t socket_cleanup(void *sock)
 {
@@ -125,7 +127,7 @@
 }

 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
-                               apr_pool_t *cont)
+                               int inherit, apr_pool_t *cont)
 {
     int family = ofamily;

@@ -158,8 +160,9 @@
     set_socket_vars(*new, family, type);

     (*new)->timeout = -1;
+    (*new)->inherit = inherit;
     apr_pool_cleanup_register((*new)->cntxt, (void *)(*new),
-                        socket_cleanup, apr_pool_cleanup_null);
+                        socket_cleanup, inherit ? socket_cleanup : NULL );
     return APR_SUCCESS;
 }

@@ -250,8 +253,9 @@
         (*new)->local_interface_unknown = 1;
     }

+    (*new)->inherit = sock->inherit;
     apr_pool_cleanup_register((*new)->cntxt, (void *)(*new),
-                        socket_cleanup, apr_pool_cleanup_null);
+                        socket_cleanup, (*new)->inherit ? socket_cleanup : NULL);
     return APR_SUCCESS;
 }

@@ -328,6 +332,7 @@

 apr_status_t apr_os_sock_make(apr_socket_t **apr_sock,
                               apr_os_sock_info_t *os_sock_info,
+                              int inherit,
                               apr_pool_t *cont)
 {
     alloc_socket(apr_sock, cont);
@@ -351,8 +356,9 @@
                (*apr_sock)->remote_addr->salen);
     }

+    (*apr_sock)->inherit = inherit;
     apr_pool_cleanup_register((*apr_sock)->cntxt, (void *)(*apr_sock),
-                        socket_cleanup, apr_pool_cleanup_null);
+                        socket_cleanup, inherit ? socket_cleanup : NULL);

     return APR_SUCCESS;
 }
@@ -373,3 +379,4 @@
     return APR_SUCCESS;
 }

+APR_SET_INHERIT(socket, cntxt, socket_cleanup, 1)
Index: srclib/apr/test/client.c
===================================================================
RCS file: /home/cvs/apr/test/client.c,v
retrieving revision 1.30
diff -u -d -b -w -u -r1.30 client.c
--- srclib/apr/test/client.c	2001/07/10 15:01:43	1.30
+++ srclib/apr/test/client.c	2001/07/14 23:43:32
@@ -110,7 +110,7 @@
     fprintf(stdout,"OK\n");

     fprintf(stdout, "\tClient:  Creating new socket.......");
-    if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM,
+    if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM, APR_NO_INHERIT,
                           context) != APR_SUCCESS) {
         fprintf(stderr, "Couldn't create socket\n");
         exit(-1);
Index: srclib/apr/test/sendfile.c
===================================================================
RCS file: /home/cvs/apr/test/sendfile.c,v
retrieving revision 1.14
diff -u -d -b -w -u -r1.14 sendfile.c
--- srclib/apr/test/sendfile.c	2001/06/08 04:49:44	1.14
+++ srclib/apr/test/sendfile.c	2001/07/14 23:43:32
@@ -114,7 +114,7 @@
     }

     *sock = NULL;
-    rv = apr_socket_create(sock, *family, SOCK_STREAM, *p);
+    rv = apr_socket_create(sock, *family, SOCK_STREAM, APR_NO_INHERIT, *p);
     if (rv != APR_SUCCESS) {
         fprintf(stderr, "apr_socket_create()->%d/%s\n",
                 rv,
Index: srclib/apr/test/server.c
===================================================================
RCS file: /home/cvs/apr/test/server.c,v
retrieving revision 1.28
diff -u -d -b -w -u -r1.28 server.c
--- srclib/apr/test/server.c	2001/06/08 04:49:44	1.28
+++ srclib/apr/test/server.c	2001/07/14 23:43:32
@@ -132,7 +132,7 @@
     }

     fprintf(stdout, "\tServer:  Creating new socket.......");
-    if (apr_socket_create(&sock, family, SOCK_STREAM, context) != APR_SUCCESS) {
+    if (apr_socket_create(&sock, family, SOCK_STREAM, APR_NO_INHERIT, context) != APR_SUCCESS)
{
         fprintf(stderr, "Couldn't create socket\n");
         exit(-1);
     }
Index: srclib/apr/test/testpoll.c
===================================================================
RCS file: /home/cvs/apr/test/testpoll.c,v
retrieving revision 1.3
diff -u -d -b -w -u -r1.3 testpoll.c
--- srclib/apr/test/testpoll.c	2001/06/08 04:49:48	1.3
+++ srclib/apr/test/testpoll.c	2001/07/14 23:43:32
@@ -72,7 +72,7 @@
         printf("couldn't create control socket information, shutting down");
         return 1;
     }
-    if (apr_socket_create(sock, (*sa)->sa.sin.sin_family, SOCK_DGRAM, p)
+    if (apr_socket_create(sock, (*sa)->sa.sin.sin_family, SOCK_DGRAM, APR_NO_INHERIT,
p)
         != APR_SUCCESS){
         printf("couldn't create UDP socket, shutting down");
         return 1;
Index: srclib/apr/test/testsockets.c
===================================================================
RCS file: /home/cvs/apr/test/testsockets.c,v
retrieving revision 1.1
diff -u -d -b -w -u -r1.1 testsockets.c
--- srclib/apr/test/testsockets.c	2001/07/07 07:55:18	1.1
+++ srclib/apr/test/testsockets.c	2001/07/14 23:43:32
@@ -101,20 +101,20 @@
     printf("Testing socket creation functions.\n");

     STD_TEST_NEQ("    Creating a TCP socket",
-                 apr_socket_create(&sock, APR_INET, SOCK_STREAM, pool))
+                 apr_socket_create(&sock, APR_INET, SOCK_STREAM, APR_NO_INHERIT, pool))
     close_sock(sock);

     STD_TEST_NEQ("    Creating UDP socket",
-                 apr_socket_create(&sock, APR_INET, SOCK_DGRAM, pool))
+                 apr_socket_create(&sock, APR_INET, SOCK_DGRAM, APR_NO_INHERIT, pool))
     close_sock(sock);

 #if APR_HAVE_IPV6
     STD_TEST_NEQ("    Creating an IPv6 TCP socket",
-                 apr_socket_create(&sock, APR_INET6, SOCK_STREAM, pool))
+                 apr_socket_create(&sock, APR_INET6, SOCK_STREAM, APR_NO_INHERIT, pool))
     close_sock(sock);

     STD_TEST_NEQ("    Creating an IPv6 UDP socket",
-                 apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, pool))
+                 apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, APR_NO_INHERIT, pool))
     close_sock(sock);
 #else
     printf("NO IPv6 support.\n");
@@ -123,9 +123,9 @@
     printf("Now trying sendto/recvfrom (simple tests only)\n");

     STD_TEST_NEQ("    Creating socket #1 for test",
-                 apr_socket_create(&sock, family, SOCK_DGRAM, pool))
+                 apr_socket_create(&sock, family, SOCK_DGRAM, APR_NO_INHERIT, pool))
     STD_TEST_NEQ("    Creating socket #2 for test",
-                 apr_socket_create(&sock2, family, SOCK_DGRAM, pool))
+                 apr_socket_create(&sock2, family, SOCK_DGRAM, APR_NO_INHERIT, pool))

     apr_sockaddr_info_get(&to, US, APR_UNSPEC, 7772, 0, pool);
     apr_sockaddr_info_get(&from, US, APR_UNSPEC, 7771, 0, pool);
Index: srclib/apr/test/testsockopt.c
===================================================================
RCS file: /home/cvs/apr/test/testsockopt.c,v
retrieving revision 1.6
diff -u -d -b -w -u -r1.6 testsockopt.c
--- srclib/apr/test/testsockopt.c	2001/06/08 04:49:50	1.6
+++ srclib/apr/test/testsockopt.c	2001/07/14 23:43:32
@@ -103,7 +103,7 @@
     printf("Testing socket option functions.\n");

     printf("\tCreating socket..........................");
-    if ((stat = apr_socket_create(&sock, APR_INET, SOCK_STREAM, context))
+    if ((stat = apr_socket_create(&sock, APR_INET, SOCK_STREAM, APR_NO_INHERIT, context))
          != APR_SUCCESS){
         printf("Failed to create a socket!\n");
         exit(-1);
Index: support/ab.c
===================================================================
RCS file: /home/cvs/httpd-2.0/support/ab.c,v
retrieving revision 1.72
diff -u -d -b -w -u -r1.72 ab.c
--- support/ab.c	2001/06/26 04:07:43	1.72
+++ support/ab.c	2001/07/14 23:43:34
@@ -844,7 +844,7 @@
 	apr_err(buf, rv);
     }
     if ((rv = apr_socket_create(&c->aprsock, destsa->sa.sin.sin_family,
-				SOCK_STREAM, cntxt)) != APR_SUCCESS) {
+				SOCK_STREAM, APR_NO_INHERIT, cntxt)) != APR_SUCCESS) {
 	apr_err("socket", rv);
     }
     c->start = apr_time_now();


apr_inherit.h
-------------
/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

#ifndef APR_INHERIT_H
#define APR_INHERIT_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#define APR_NO_INHERIT 0
#define APR_INHERIT    1

#define APR_DECLARE_SET_INHERIT(name) \
    void apr_##name##_set_inherit(apr_##name##_t *name)

#define APR_SET_INHERIT(name, pool, cleanup, field_exists)          \
void apr_##name##_set_inherit(apr_##name##_t *name)                 \
{                                                                   \
    name->inherit = 1;                                              \
    apr_pool_cleanup_register(name->##pool, (void *)##name##, NULL, \
                              cleanup);                             \
}

#define APR_DECLARE_UNSET_INHERIT(name) \
    void apr_##name##_unset_inherit(apr_##name##_t *name)

#define APR_UNSET_INHERIT(name, pool, cleanup, field_exists)          \
void apr_##name##_unset_inherit(apr_##name##_t *name)                 \
{                                                                   \
    name->inherit = 0;                                              \
    apr_pool_cleanup_kill(name->##pool, (void *)##name##, NULL, \
                              cleanup);                             \
}

#ifdef __cplusplus
}
#endif

#endif	/* ! APR_INHERIT_H */

_____________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
Covalent Technologies			rbb@covalent.net
-----------------------------------------------------------------------------


Mime
View raw message