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 33c397566d0da0ce0f86f9797934a8081719b89a..7ab740e142b99a29666d189c78dc69ace5fceaf1 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 cd48806fd4949abdfe87ad5e0cebfd36a51ab62a..0f06d8e660d24fe4327b4f841c8d3f06f1191733 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 c215945c44b65f48a73fe7113a808f912e6868f2..18fc00bc765f2819a260da57015da93f1713346f 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 0792f5b1007f720cb6b1ca2daf96c9f09fb5ca53..1300e40d3a2eb0065e5f7b95bbec66a16ca6ca30 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;