------------------------------------------------------------
revno: 402
revision-id: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Andrew Tridgell <[EMAIL PROTECTED]>
branch nick: tridge
timestamp: Wed 2007-05-30 15:43:25 +1000
message:
  close sockets when we exec scripts
modified:
  common/ctdb_client.c           ctdb_client.c-20070411010216-3kd8v37k61steeya-1
  common/ctdb_daemon.c           ctdb_daemon.c-20070409200331-3el1kqgdb9m4ib0g-1
  common/ctdb_util.c             ctdb_util.c-20061128065342-to93h6eejj5kon81-3
  include/ctdb_private.h         
ctdb_private.h-20061117234101-o3qt14umlg9en8z0-13
  tcp/tcp_connect.c              tcp_connect.c-20061128004937-x70q1cu5xzg5g2tm-1
=== modified file 'common/ctdb_client.c'
--- a/common/ctdb_client.c      2007-05-29 03:58:41 +0000
+++ b/common/ctdb_client.c      2007-05-30 05:43:25 +0000
@@ -174,6 +174,9 @@
        if (ctdb->daemon.sd == -1) {
                return -1;
        }
+
+       set_nonblocking(ctdb->daemon.sd);
+       set_close_on_exec(ctdb->daemon.sd);
        
        if (connect(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == 
-1) {
                close(ctdb->daemon.sd);

=== modified file 'common/ctdb_daemon.c'
--- a/common/ctdb_daemon.c      2007-05-30 04:35:22 +0000
+++ b/common/ctdb_daemon.c      2007-05-30 05:43:25 +0000
@@ -101,13 +101,6 @@
 }
 
 
-static void set_non_blocking(int fd)
-{
-       unsigned v;
-       v = fcntl(fd, F_GETFL, 0);
-        fcntl(fd, F_SETFL, v | O_NONBLOCK);
-}
-
 static void block_signal(int signum)
 {
        struct sigaction act;
@@ -585,7 +578,9 @@
        if (fd == -1) {
                return;
        }
-       set_non_blocking(fd);
+
+       set_nonblocking(fd);
+       set_close_on_exec(fd);
 
        client = talloc_zero(ctdb, struct ctdb_client);
        client->ctdb = ctdb;
@@ -634,6 +629,9 @@
                return -1;
        }
 
+       set_nonblocking(ctdb->daemon.sd);
+       set_close_on_exec(ctdb->daemon.sd);
+
 #if 0
        /* AIX doesn't like this :( */
        if (fchown(ctdb->daemon.sd, geteuid(), getegid()) != 0 ||
@@ -643,7 +641,7 @@
        }
 #endif
 
-       set_non_blocking(ctdb->daemon.sd);
+       set_nonblocking(ctdb->daemon.sd);
 
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_UNIX;

=== modified file 'common/ctdb_util.c'
--- a/common/ctdb_util.c        2007-05-29 05:15:00 +0000
+++ b/common/ctdb_util.c        2007-05-30 05:43:25 +0000
@@ -217,3 +217,18 @@
        }
 #endif
 }
+
+void set_nonblocking(int fd)
+{
+       unsigned v;
+       v = fcntl(fd, F_GETFL, 0);
+        fcntl(fd, F_SETFL, v | O_NONBLOCK);
+}
+
+void set_close_on_exec(int fd)
+{
+       unsigned v;
+       v = fcntl(fd, F_GETFD, 0);
+        fcntl(fd, F_SETFD, v | FD_CLOEXEC);
+}
+

=== modified file 'include/ctdb_private.h'
--- a/include/ctdb_private.h    2007-05-30 03:26:50 +0000
+++ b/include/ctdb_private.h    2007-05-30 05:43:25 +0000
@@ -955,6 +955,8 @@
                               const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
 void ctdb_release_all_ips(struct ctdb_context *ctdb);
 
+void set_nonblocking(int fd);
+void set_close_on_exec(int fd);
 
 
 #endif

=== modified file 'tcp/tcp_connect.c'
--- a/tcp/tcp_connect.c 2007-05-25 12:07:45 +0000
+++ b/tcp/tcp_connect.c 2007-05-30 05:43:25 +0000
@@ -26,14 +26,6 @@
 #include "../include/ctdb_private.h"
 #include "ctdb_tcp.h"
 
-static void set_nonblocking(int fd)
-{
-       unsigned v;
-       v = fcntl(fd, F_GETFL, 0);
-        fcntl(fd, F_SETFL, v | O_NONBLOCK);
-}
-
-
 /*
   called when a complete packet has come in - should not happen on this socket
  */
@@ -134,6 +126,7 @@
        tnode->fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
        set_nonblocking(tnode->fd);
+       set_close_on_exec(tnode->fd);
 
        ZERO_STRUCT(sock_out);
 #ifdef HAVE_SOCK_SIN_LEN
@@ -213,6 +206,7 @@
        in->ctdb = ctdb;
 
        set_nonblocking(in->fd);
+       set_close_on_exec(in->fd);
 
         setsockopt(in->fd,SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(one));
 
@@ -322,6 +316,8 @@
                return -1;
        }
 
+       set_close_on_exec(ctcp->listen_fd);
+
         setsockopt(ctcp->listen_fd,SOL_SOCKET,SO_REUSEADDR,(char 
*)&one,sizeof(one));
 
        /* we can either auto-bind to the first available address, or we can

Reply via email to