1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-02 03:52:49 -05:00

I've just discovered that using the saved sessions menu from Unix

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]
This commit is contained in:
Simon Tatham
2006-11-23 14:32:11 +00:00
parent 230d400ddc
commit fd6d9bd677
4 changed files with 16 additions and 1 deletions

View 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