]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
I've just discovered that using the saved sessions menu from Unix
authorSimon Tatham <anakin@pobox.com>
Thu, 23 Nov 2006 14:32:11 +0000 (14:32 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 23 Nov 2006 14:32:11 +0000 (14:32 +0000)
PuTTY causes the child process to inherit a lot of socket fds from
its parent, which is a pain if one of them then ends up holding open
a listening socket which the parent was using for port forwarding
after the parent itself is dead.

Therefore, this checkin sprinkles FD_CLOEXEC throughout the Unix
platform directory wherever there looks like being a long-lived fd.

[originally from svn r6917]

unix/uxagentc.c
unix/uxnet.c
unix/uxpty.c
unix/uxser.c

index 826e4394b6d6f7e5b9bb23f547c8129ca0245ffc..7b737d1d5ab7c4ecd592109ba86a92fe3c2a1cfb 100644 (file)
@@ -8,6 +8,7 @@
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <fcntl.h>
 
 #include "putty.h"
 #include "misc.h"
@@ -121,6 +122,8 @@ int agent_query(void *in, int inlen, void **out, int *outlen,
        exit(1);
     }
 
+    fcntl(sock, F_SETFD, FD_CLOEXEC);
+
     addr.sun_family = AF_UNIX;
     strncpy(addr.sun_path, name, sizeof(addr.sun_path));
     if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
index d01a44d9d02dcc0eb5f5ee55c8502e6213b052f6..2b3d8cbc3d36f9b6e7bcf2542777dccaa605f475 100644 (file)
@@ -470,6 +470,8 @@ static int try_connect(Actual_Socket sock)
        goto ret;
     }
 
+    fcntl(s, F_SETFD, FD_CLOEXEC);
+
     if (sock->oobinline) {
        int b = TRUE;
        setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (void *) &b, sizeof(b));
@@ -723,6 +725,8 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, i
        return (Socket) ret;
     }
 
+    fcntl(s, F_SETFD, FD_CLOEXEC);
+
     ret->oobinline = 0;
 
     setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
index 50e5371435458d3234ef1c9179374ef75f5949ad..e47f7981e35db56592a23d2e43f73929e741ea62 100644 (file)
@@ -275,8 +275,10 @@ static void fatal_sig_handler(int signum)
 
 static int pty_open_slave(Pty pty)
 {
-    if (pty->slave_fd < 0)
+    if (pty->slave_fd < 0) {
        pty->slave_fd = open(pty->name, O_RDWR);
+        fcntl(pty->slave_fd, F_SETFD, FD_CLOEXEC);
+    }
 
     return pty->slave_fd;
 }
@@ -307,6 +309,8 @@ static void pty_open_master(Pty pty)
                    strcpy(pty->name, master_name);
                    pty->name[5] = 't'; /* /dev/ptyXX -> /dev/ttyXX */
 
+                    fcntl(pty->master_fd, F_SETFD, FD_CLOEXEC);
+
                    if (pty_open_slave(pty) >= 0 &&
                        access(pty->name, R_OK | W_OK) == 0)
                        goto got_one;
@@ -346,6 +350,8 @@ static void pty_open_master(Pty pty)
        exit(1);
     }
 
+    fcntl(pty->master_fd, F_SETFD, FD_CLOEXEC);
+
     pty->name[FILENAME_MAX-1] = '\0';
     strncpy(pty->name, ptsname(pty->master_fd), FILENAME_MAX-1);
 #endif
index d6471084d56fee296aa45e6a7e2399ff8113b6e9..08f2157544a3ba7e27eebfd5a570ae334a8adebd 100644 (file)
@@ -257,6 +257,8 @@ static const char *serial_init(void *frontend_handle, void **backend_handle,
     if (serial->fd < 0)
        return "Unable to open serial port";
 
+    fcntl(serial->fd, F_SETFD, FD_CLOEXEC);
+
     err = serial_configure(serial, cfg);
     if (err)
        return err;