From 4826f90b555f009972276be1fa945d81b435950a Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Sun, 23 Oct 2011 14:16:23 +0200 Subject: [PATCH] tools: Add O_CLOEXEC to open() Make sure all file descriptor are closed. --- tools/alg-test.c | 2 +- tools/stats-tool.c | 3 ++- tools/tap-test.c | 2 +- tools/wispr.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/alg-test.c b/tools/alg-test.c index 33c3975..7ab740e 100644 --- a/tools/alg-test.c +++ b/tools/alg-test.c @@ -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; diff --git a/tools/stats-tool.c b/tools/stats-tool.c index cd48806..0f06d8e 100644 --- a/tools/stats-tool.c +++ b/tools/stats-tool.c @@ -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); diff --git a/tools/tap-test.c b/tools/tap-test.c index c215945..18fc00b 100644 --- a/tools/tap-test.c +++ b/tools/tap-test.c @@ -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; diff --git a/tools/wispr.c b/tools/wispr.c index 0792f5b..1300e40 100644 --- a/tools/wispr.c +++ b/tools/wispr.c @@ -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; -- 2.7.4