diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2012-01-13 12:38:26 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2012-01-13 12:38:26 +0400 |
commit | bf1ccc7f6e7a9dc5a8ba3d8d02b25ad446458840 (patch) | |
tree | 4e53a7f2990e40436f6ae98434f72c3db14434c0 /accel-pppd/ppp/ppp.c | |
parent | 03a466f1b0f7549c2ef89c1e544c2c86c3958ad4 (diff) | |
download | accel-ppp-xebd-bf1ccc7f6e7a9dc5a8ba3d8d02b25ad446458840.tar.gz accel-ppp-xebd-bf1ccc7f6e7a9dc5a8ba3d8d02b25ad446458840.zip |
set FD_CLOEXEC on opened file descriptors
Diffstat (limited to 'accel-pppd/ppp/ppp.c')
-rw-r--r-- | accel-pppd/ppp/ppp.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c index acda84e..3ab7166 100644 --- a/accel-pppd/ppp/ppp.c +++ b/accel-pppd/ppp/ppp.c @@ -33,6 +33,7 @@ __export LIST_HEAD(ppp_list); int __export sock_fd; int __export sock6_fd; +int __export urandom_fd; int __export ppp_shutdown; @@ -102,6 +103,8 @@ int __export establish_ppp(struct ppp_t *ppp) log_ppp_error("open(chan) /dev/ppp: %s\n", strerror(errno)); return -1; } + + fcntl(ppp->chan_fd, F_SETFD, fcntl(ppp->chan_fd, F_GETFD) | FD_CLOEXEC); if (ioctl(ppp->chan_fd, PPPIOCATTCHAN, &ppp->chan_idx) < 0) { log_ppp_error("ioctl(PPPIOCATTCHAN): %s\n", strerror(errno)); @@ -113,6 +116,8 @@ int __export establish_ppp(struct ppp_t *ppp) log_ppp_error("open(unit) /dev/ppp: %s\n", strerror(errno)); goto exit_close_chan; } + + fcntl(ppp->unit_fd, F_SETFD, fcntl(ppp->unit_fd, F_GETFD) | FD_CLOEXEC); ppp->unit_idx = -1; if (ioctl(ppp->unit_fd, PPPIOCNEWUNIT, &ppp->unit_idx) < 0) { @@ -756,10 +761,22 @@ static void init(void) perror("socket"); _exit(EXIT_FAILURE); } + + fcntl(sock_fd, F_SETFD, fcntl(sock_fd, F_GETFD) | FD_CLOEXEC); sock6_fd = socket(AF_INET6, SOCK_DGRAM, 0); if (sock6_fd < 0) log_warn("ppp: kernel doesn't support ipv6\n"); + else + fcntl(sock6_fd, F_SETFD, fcntl(sock6_fd, F_GETFD) | FD_CLOEXEC); + + urandom_fd = open("/dev/urandom", O_RDONLY); + if (urandom_fd < 0) { + log_emerg("failed to open /dev/urandom: %s\n", strerror(errno)); + return; + } + + fcntl(urandom_fd, F_SETFD, fcntl(urandom_fd, F_GETFD) | FD_CLOEXEC); opt = conf_get_opt("ppp", "seq-file"); if (!opt) |