From: Daniel Wagner <[email protected]>
Make sure all file descriptor are closed.
---
plugins/tist.c | 4 ++--
plugins/vpn.c | 4 ++--
src/inet.c | 2 +-
src/resolver.c | 2 +-
src/rfkill.c | 4 ++--
src/stats.c | 2 +-
src/timezone.c | 10 +++++-----
tools/alg-test.c | 2 +-
tools/stats-tool.c | 3 ++-
tools/tap-test.c | 2 +-
tools/wispr.c | 2 +-
11 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/plugins/tist.c b/plugins/tist.c
index b8c89cf..9b0d3f7 100644
--- a/plugins/tist.c
+++ b/plugins/tist.c
@@ -370,7 +370,7 @@ static int install_ldisc(GIOChannel *channel, gboolean
install)
DBG("opening %s custom baud %lu", uart_dev_name, baud_rate);
- uart_fd = open(uart_dev_name, O_RDWR);
+ uart_fd = open(uart_dev_name, O_RDWR | O_CLOEXEC);
if (uart_fd < 0)
return -EIO;
@@ -522,7 +522,7 @@ static int tist_init(void)
return err;
}
- fd = open(TIST_SYSFS_INSTALL, O_RDONLY);
+ fd = open(TIST_SYSFS_INSTALL, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
connman_error("Failed to open TI ST sysfs install file");
return -EIO;
diff --git a/plugins/vpn.c b/plugins/vpn.c
index efeb959..b9b97c1 100644
--- a/plugins/vpn.c
+++ b/plugins/vpn.c
@@ -74,7 +74,7 @@ static int kill_tun(char *tun_name)
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
sprintf(ifr.ifr_name, "%s", tun_name);
- fd = open("/dev/net/tun", O_RDWR);
+ fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
if (fd < 0) {
err = -errno;
connman_error("Failed to open /dev/net/tun to device %s: %s",
@@ -228,7 +228,7 @@ static int vpn_connect(struct connman_provider *provider)
name = connman_provider_get_driver_name(provider);
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- fd = open("/dev/net/tun", O_RDWR);
+ fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
if (fd < 0) {
i = -errno;
connman_error("Failed to open /dev/net/tun: %s",
diff --git a/src/inet.c b/src/inet.c
index d898650..b6b40e3 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -1379,7 +1379,7 @@ int connman_inet_create_tunnel(char **iface)
struct ifreq ifr;
int i, fd;
- fd = open("/dev/net/tun", O_RDWR);
+ fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
if (fd < 0) {
i = -errno;
connman_error("Failed to open /dev/net/tun: %s",
diff --git a/src/resolver.c b/src/resolver.c
index 59defd4..4cc87dd 100644
--- a/src/resolver.c
+++ b/src/resolver.c
@@ -121,7 +121,7 @@ static int resolvfile_export(void)
old_umask = umask(022);
- fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
+ fd = open("/etc/resolv.conf", O_RDWR | O_CREAT | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
err = -errno;
diff --git a/src/rfkill.c b/src/rfkill.c
index 17592da..6ad8279 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -172,7 +172,7 @@ int __connman_rfkill_block(enum connman_service_type type,
connman_bool_t block)
if (rfkill_type == NUM_RFKILL_TYPES)
return -EINVAL;
- fd = open("/dev/rfkill", O_RDWR);
+ fd = open("/dev/rfkill", O_RDWR | O_CLOEXEC);
if (fd < 0)
return fd;
@@ -197,7 +197,7 @@ int __connman_rfkill_init(void)
DBG("");
- fd = open("/dev/rfkill", O_RDWR);
+ fd = open("/dev/rfkill", O_RDWR | O_CLOEXEC);
if (fd < 0) {
connman_error("Failed to open RFKILL control device");
return -EIO;
diff --git a/src/stats.c b/src/stats.c
index df28eb4..828c1ef 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -335,7 +335,7 @@ static int stats_open(struct stats_file *file,
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 < 0) {
connman_error("open error %s for %s",
strerror(errno), file->name);
diff --git a/src/timezone.c b/src/timezone.c
index 1234622..5b17c00 100644
--- a/src/timezone.c
+++ b/src/timezone.c
@@ -49,7 +49,7 @@ static char *read_key_file(const char *pathname, const char
*key)
off_t ptrlen, keylen;
int fd;
- fd = open(pathname, O_RDONLY);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return NULL;
@@ -121,7 +121,7 @@ static int compare_file(void *src_map, struct stat *src_st,
void *dst_map;
int fd, result;
- fd = open(pathname, O_RDONLY);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
@@ -223,7 +223,7 @@ char *__connman_timezone_lookup(void)
DBG("sysconfig zone %s", zone);
- fd = open(ETC_LOCALTIME, O_RDONLY);
+ fd = open(ETC_LOCALTIME, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
g_free(zone);
return NULL;
@@ -283,7 +283,7 @@ static int write_file(void *src_map, struct stat *src_st,
const char *pathname)
unlink(pathname);
}
- fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd < 0)
return -EIO;
@@ -307,7 +307,7 @@ int __connman_timezone_change(const char *zone)
snprintf(pathname, PATH_MAX, "%s/%s", USR_SHARE_ZONEINFO, zone);
- fd = open(pathname, O_RDONLY);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -EINVAL;
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;
--
1.7.6.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman