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

Set FD_CLOEXEC in a little convenience function that does the right thing

with F_GETFD and F_SETFD.

[originally from svn r6978]
This commit is contained in:
Ben Harris
2006-12-09 15:44:31 +00:00
parent 2226098a9e
commit 86eac20abb
6 changed files with 22 additions and 7 deletions

View File

@ -277,7 +277,7 @@ static int pty_open_slave(Pty pty)
{
if (pty->slave_fd < 0) {
pty->slave_fd = open(pty->name, O_RDWR);
fcntl(pty->slave_fd, F_SETFD, FD_CLOEXEC);
cloexec(pty->slave_fd);
}
return pty->slave_fd;
@ -309,7 +309,7 @@ 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);
cloexec(pty->master_fd);
if (pty_open_slave(pty) >= 0 &&
access(pty->name, R_OK | W_OK) == 0)
@ -350,7 +350,7 @@ static void pty_open_master(Pty pty)
exit(1);
}
fcntl(pty->master_fd, F_SETFD, FD_CLOEXEC);
cloexec(pty->master_fd);
pty->name[FILENAME_MAX-1] = '\0';
strncpy(pty->name, ptsname(pty->master_fd), FILENAME_MAX-1);