]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2)
authorCristian Rodríguez <crrodriguez@opensuse.org>
Fri, 10 Apr 2015 18:57:58 +0000 (15:57 -0300)
committerKarel Zak <kzak@redhat.com>
Wed, 29 Apr 2015 10:36:45 +0000 (12:36 +0200)
"The two descriptors do not share file descriptor flags (the
close-on-exec flag).  The close-on-exec flag  for the duplicate descriptor is off"

lib/sysfs.c

index ac35596190e95c12105618a56ee1cb2d40ea4566..1b2019112d4180e15901a676f8eea25234d18f94 100644 (file)
@@ -246,7 +246,7 @@ DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr)
                 * -- we cannot use cxt->sysfs_fd directly, because closedir()
                 * will close this our persistent file descriptor.
                 */
-               fd = dup(cxt->dir_fd);
+               fd = fcntl(cxt->dir_fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
 
        if (fd < 0)
                return NULL;