Make sure all file descriptor are closed.
struct stat st;
int fd;
- fd = open(pathname, O_RDONLY);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
if (name != NULL) {
file->name = g_strdup(name);
- file->fd = TFR(open(file->name, O_RDWR | O_CREAT, 0644));
+ file->fd = TFR(open(file->name,
+ O_RDWR | O_CREAT | O_CLOEXEC, 0644));
if (file->fd == -1) {
fprintf(stderr, "open error %s for %s\n",
strerror(errno), file->name);
struct ifreq ifr;
int fd, val;
- fd = open("/dev/net/tun", O_RDWR);
+ fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
if (fd < 0) {
perror("Failed to open TUN/TAP device");
return -1;
data->user_data = user_data;
data->hidden = hidden;
- data->fd = open("/dev/tty", O_RDWR | O_NOCTTY);
+ data->fd = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC);
if (data->fd < 0)
goto error;