tools: Add O_CLOEXEC to open()
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Sun, 23 Oct 2011 12:16:23 +0000 (14:16 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 25 Oct 2011 11:34:06 +0000 (13:34 +0200)
Make sure all file descriptor are closed.

tools/alg-test.c
tools/stats-tool.c
tools/tap-test.c
tools/wispr.c

index 33c3975..7ab740e 100644 (file)
@@ -60,7 +60,7 @@ static int create_hash(int sk, const char *pathname)
        struct stat st;
        int fd;
 
-       fd = open(pathname, O_RDONLY);
+       fd = open(pathname, O_RDONLY | O_CLOEXEC);
        if (fd < 0)
                return -1;
 
index cd48806..0f06d8e 100644 (file)
@@ -470,7 +470,8 @@ static int stats_open(struct stats_file *file, const char *name)
        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);
index c215945..18fc00b 100644 (file)
@@ -80,7 +80,7 @@ static int create_tap(const char *ifname)
        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;
index 0792f5b..1300e40 100644 (file)
@@ -373,7 +373,7 @@ static gboolean user_input(const char *label, gboolean hidden,
        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;