From: Daniel Wagner <[email protected]>

Make sure all file descriptor are closed.
---
 src/inet.c     |    2 +-
 src/resolver.c |    2 +-
 src/rfkill.c   |    4 ++--
 src/stats.c    |    2 +-
 src/timezone.c |   10 +++++-----
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/inet.c b/src/inet.c
index 56f29fd..f7f72b8 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;
 
-- 
1.7.7

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to