]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: use O_CLOEXEC
authorKarel Zak <kzak@redhat.com>
Wed, 3 Apr 2013 14:14:03 +0000 (16:14 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 3 Apr 2013 14:14:03 +0000 (16:14 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/lock.c
libmount/src/tab_parse.c
libmount/src/tab_update.c
libmount/src/utils.c

index e5393d0a467b144530c266ad07590a68df69c1b8..9e583cc069d1f515070412319eae4c823edd14bd 100644 (file)
@@ -558,7 +558,7 @@ void increment_data(const char *filename, int verbose, int loopno)
        FILE *f;
        char buf[256];
 
-       if (!(f = fopen(filename, "r")))
+       if (!(f = fopen(filename, "r" UL_CLOEXECSTR)))
                err(EXIT_FAILURE, "%d: failed to open: %s", getpid(), filename);
 
        if (!fgets(buf, sizeof(buf), f))
@@ -567,7 +567,7 @@ void increment_data(const char *filename, int verbose, int loopno)
        fclose(f);
        num = atol(buf) + 1;
 
-       if (!(f = fopen(filename, "w")))
+       if (!(f = fopen(filename, "w" UL_CLOEXECSTR)))
                err(EXIT_FAILURE, "%d: failed to open: %s", getpid(), filename);
 
        fprintf(f, "%ld", num);
index b4b647075e0a2e378fca516f23568396507a1cea..7368d8c988deba7589a29a30cc5ee28c6fc5d947 100644 (file)
@@ -579,7 +579,7 @@ int mnt_table_parse_file(struct libmnt_table *tb, const char *filename)
        if (!filename || !tb)
                return -EINVAL;
 
-       f = fopen(filename, "r");
+       f = fopen(filename, "r" UL_CLOEXECSTR);
        if (f) {
                rc = mnt_table_parse_stream(tb, f, filename);
                fclose(f);
@@ -639,7 +639,7 @@ static int __mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
                    !S_ISREG(st.st_mode))
                        continue;
 
-               f = fopen_at(dd, ".", d->d_name, O_RDONLY, "r");
+               f = fopen_at(dd, ".", d->d_name, O_RDONLY|O_CLOEXEC, "r" UL_CLOEXECSTR);
                if (f) {
                        mnt_table_parse_stream(tb, f, d->d_name);
                        fclose(f);
@@ -679,8 +679,8 @@ static int __mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
                    !S_ISREG(st.st_mode))
                        continue;
 
-               f = fopen_at(dirfd(dir), _PATH_MNTTAB_DIR,
-                                       d->d_name, O_RDONLY, "r");
+               f = fopen_at(dirfd(dir), _PATH_MNTTAB_DIR, d->d_name,
+                               O_RDONLY|O_CLOEXEC, "r" UL_CLOEXECSTR);
                if (f) {
                        mnt_table_parse_stream(tb, f, d->d_name);
                        fclose(f);
index 7ae540abf5ec2ae4e8d6c14b3e14ee2b8797c0d9..044a13f5e0be365644249ea22d34dbe46bc7ae84 100644 (file)
@@ -514,7 +514,7 @@ static int update_table(struct libmnt_update *upd, struct libmnt_table *tb)
        if (fd < 0)
                return fd;      /* error */
 
-       f = fdopen(fd, "w");
+       f = fdopen(fd, "w" UL_CLOEXECSTR);
        if (f) {
                struct stat st;
                struct libmnt_iter itr;
index 5453789e3263ee1fed140527aeeccb6dbb60d75e..c910035df89859cae0671c6d6313e8caa878c92a 100644 (file)
@@ -462,7 +462,7 @@ static int get_filesystems(const char *filename, char ***filesystems, const char
        FILE *f;
        char line[128];
 
-       f = fopen(filename, "r");
+       f = fopen(filename, "r" UL_CLOEXECSTR);
        if (!f)
                return 1;
 
@@ -837,7 +837,7 @@ int mnt_open_uniq_filename(const char *filename, char **name)
         */
        oldmode = umask(S_IRGRP|S_IWGRP|S_IXGRP|
                        S_IROTH|S_IWOTH|S_IXOTH);
-       fd = mkstemp(n);
+       fd = mkostemp(n, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
        umask(oldmode);
 
        if (fd >= 0 && name)
@@ -949,7 +949,7 @@ char *mnt_get_kernel_cmdline_option(const char *name)
        if (!path)
                path = _PATH_PROC_CMDLINE;
 #endif
-       f = fopen(path, "r");
+       f = fopen(path, "r" UL_CLOEXECSTR);
        if (!f)
                return NULL;