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.
git-svn-id: svn://svn.tartarus.org/sgt/putty@6917
cda61777-01e9-0310-a592-
d414129be87e
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <fcntl.h>
#include "putty.h"
#include "misc.h"
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) {
goto ret;
}
+ fcntl(s, F_SETFD, FD_CLOEXEC);
+
if (sock->oobinline) {
int b = TRUE;
setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (void *) &b, sizeof(b));
return (Socket) ret;
}
+ fcntl(s, F_SETFD, FD_CLOEXEC);
+
ret->oobinline = 0;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
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;
}
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;
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
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;