s4-socket: use set_close_on_exec()
authorAndrew Tridgell <tridge@samba.org>
Wed, 30 Nov 2011 04:18:45 +0000 (15:18 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 15 Dec 2011 22:36:22 +0000 (23:36 +0100)
this prevents a fd leak to child processes

source4/lib/socket/socket_ip.c
source4/lib/socket/socket_unix.c

index cab51beafb968100224b2ea9f762b63eb8583e5a..d2d57798d4c39bdc246baafcf82230a6ab6fd4e1 100644 (file)
@@ -50,6 +50,8 @@ static NTSTATUS ipv4_init(struct socket_context *sock)
                return map_nt_error_from_unix_common(errno);
        }
 
+       set_close_on_exec(sock->fd);
+
        sock->backend_name = "ipv4";
        sock->family = AF_INET;
 
@@ -610,6 +612,8 @@ static NTSTATUS ipv6_init(struct socket_context *sock)
                return map_nt_error_from_unix_common(errno);
        }
 
+       set_close_on_exec(sock->fd);
+
        sock->backend_name = "ipv6";
        sock->family = AF_INET6;
 
index d492f01268127b5b8879f3f34a31bbc43d6d3f1d..ab9b06df1b9bfee90b8042b3020e430f95822100 100644 (file)
@@ -59,6 +59,8 @@ static NTSTATUS unixdom_init(struct socket_context *sock)
 
        sock->backend_name = "unix";
 
+       set_close_on_exec(sock->fd);
+
        return NT_STATUS_OK;
 }
 
@@ -198,6 +200,8 @@ static NTSTATUS unixdom_accept(struct socket_context *sock,
                }
        }
 
+       set_close_on_exec(new_fd);
+
        (*new_sock) = talloc(NULL, struct socket_context);
        if (!(*new_sock)) {
                close(new_fd);