mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
use close-on-exec flag on fds
This commit is contained in:
@@ -75,10 +75,6 @@ int ret;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* FIXME: using close on exec should be more efficient
|
||||
* than that */
|
||||
clear_lists(s);
|
||||
|
||||
ret = execlp(s->config->disconnect_script, s->config->disconnect_script,
|
||||
proc->username, proc->lease->name, real, local, remote, NULL);
|
||||
if (ret == -1)
|
||||
@@ -98,7 +94,6 @@ int ret, status;
|
||||
if (s->config->connect_script == NULL)
|
||||
return 0;
|
||||
|
||||
/* XXX: close fds */
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
char real[64];
|
||||
@@ -124,8 +119,6 @@ int ret, status;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
clear_lists(s);
|
||||
|
||||
ret = execlp(s->config->connect_script, s->config->connect_script,
|
||||
proc->username, proc->lease->name, real, local, remote, NULL);
|
||||
if (ret == -1)
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <cloexec.h>
|
||||
|
||||
#include <gnutls/x509.h>
|
||||
#include <tlslib.h>
|
||||
@@ -99,6 +100,8 @@ listen_ports(struct cfg_st* config, struct listen_list_st *list, const char *nod
|
||||
perror("socket() failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
#if defined(HAVE_IPV6) && !defined(_WIN32)
|
||||
if (ptr->ai_family == AF_INET6) {
|
||||
y = 1;
|
||||
@@ -131,6 +134,8 @@ listen_ports(struct cfg_st* config, struct listen_list_st *list, const char *nod
|
||||
#endif
|
||||
}
|
||||
|
||||
set_cloexec_flag (s, 1);
|
||||
|
||||
if (bind(s, ptr->ai_addr, ptr->ai_addrlen) < 0) {
|
||||
perror("bind() failed");
|
||||
close(s);
|
||||
@@ -509,6 +514,7 @@ int main(int argc, char** argv)
|
||||
strerror(errno));
|
||||
continue;
|
||||
}
|
||||
set_cloexec_flag (fd, 1);
|
||||
|
||||
if (config.max_clients > 0 && active_clients >= config.max_clients) {
|
||||
close(fd);
|
||||
@@ -558,6 +564,8 @@ fork_failed:
|
||||
|
||||
ctmp->pid = pid;
|
||||
ctmp->fd = cmd_fd[0];
|
||||
set_cloexec_flag (cmd_fd[0], 1);
|
||||
|
||||
list_add(&(ctmp->list), &(clist.list));
|
||||
active_clients++;
|
||||
}
|
||||
@@ -608,4 +616,3 @@ fork_failed:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <cloexec.h>
|
||||
|
||||
#include <vpn.h>
|
||||
#include <tun.h>
|
||||
@@ -380,6 +381,8 @@ int open_tun(const struct cfg_st *config, struct tun_st* tun, struct lease_st**
|
||||
strerror(e));
|
||||
return -1;
|
||||
}
|
||||
|
||||
set_cloexec_flag (tunfd, 1);
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
|
||||
|
||||
Reference in New Issue
Block a user