зеркало из https://github.com/github/putty.git
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:
Родитель
2226098a9e
Коммит
86eac20abb
|
@ -128,6 +128,9 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *window);
|
|||
void (*putty_signal(int sig, void (*func)(int)))(int);
|
||||
void block_signal(int sig, int block_it);
|
||||
|
||||
/* uxmisc.c */
|
||||
int cloexec(int);
|
||||
|
||||
/*
|
||||
* Exports from unicode.c.
|
||||
*/
|
||||
|
|
|
@ -122,7 +122,7 @@ int agent_query(void *in, int inlen, void **out, int *outlen,
|
|||
exit(1);
|
||||
}
|
||||
|
||||
fcntl(sock, F_SETFD, FD_CLOEXEC);
|
||||
cloexec(sock);
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, name, sizeof(addr.sun_path));
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* PuTTY miscellaneous Unix stuff
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -121,3 +122,14 @@ void pgp_fingerprints(void)
|
|||
"PuTTY Master Key (DSA), 1024-bit:\n"
|
||||
" " PGP_DSA_MASTER_KEY_FP "\n", stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set FD_CLOEXEC on a file descriptor
|
||||
*/
|
||||
int cloexec(int fd) {
|
||||
int fdflags;
|
||||
|
||||
fdflags = fcntl(fd, F_GETFD);
|
||||
if (fdflags == -1) return -1;
|
||||
return fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
|
||||
}
|
||||
|
|
|
@ -470,7 +470,7 @@ static int try_connect(Actual_Socket sock)
|
|||
goto ret;
|
||||
}
|
||||
|
||||
fcntl(s, F_SETFD, FD_CLOEXEC);
|
||||
cloexec(s);
|
||||
|
||||
if (sock->oobinline) {
|
||||
int b = TRUE;
|
||||
|
@ -725,7 +725,7 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, i
|
|||
return (Socket) ret;
|
||||
}
|
||||
|
||||
fcntl(s, F_SETFD, FD_CLOEXEC);
|
||||
cloexec(s);
|
||||
|
||||
ret->oobinline = 0;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -257,7 +257,7 @@ 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);
|
||||
cloexec(serial->fd);
|
||||
|
||||
err = serial_configure(serial, cfg);
|
||||
if (err)
|
||||
|
|
Загрузка…
Ссылка в новой задаче