]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- set CLOEXEC on fd duplication
authorArvin Schnell <aschnell@suse.de>
Fri, 31 May 2013 13:38:53 +0000 (15:38 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 31 May 2013 13:40:00 +0000 (15:40 +0200)
snapper/FileUtils.cc

index 55e4e96e2c4b093df2a2c7e07aad37afcf603383..5aeebe5d6a7de57ad81f8f87e8b08c49e5ec5152 100644 (file)
@@ -68,6 +68,7 @@ namespace snapper
            y2err("not a directory path:" << base_path);
            throw IOErrorException();
        }
+
 #ifdef ENABLE_XATTRS
        setXaStatus();
 #endif
@@ -95,6 +96,7 @@ namespace snapper
            close(dirfd);
            throw IOErrorException();
        }
+
 #ifdef ENABLE_XATTRS
        xastatus = dir.xastatus;
 #endif
@@ -104,12 +106,13 @@ namespace snapper
     SDir::SDir(const SDir& dir)
        : base_path(dir.base_path), path(dir.path)
     {
-       dirfd = dup(dir.dirfd);
+       dirfd = fcntl(dir.dirfd, F_DUPFD_CLOEXEC, 0);
        if (dirfd == -1)
        {
-           y2err("dup failed" << " error:" << stringerror(errno));
+           y2err("fcntl(F_DUPFD_CLOEXEC) failed error:" << stringerror(errno));
            throw IOErrorException();
        }
+
 #ifdef ENABLE_XATTRS
        xastatus = dir.xastatus;
 #endif
@@ -121,16 +124,17 @@ namespace snapper
     {
        if (this != &dir)
        {
-#ifdef ENABLE_XATTRS
-           xastatus = dir.xastatus;
-#endif
            ::close(dirfd);
-           dirfd = dup(dir.dirfd);
+           dirfd = fcntl(dir.dirfd, F_DUPFD_CLOEXEC, 0);
            if (dirfd == -1)
            {
-               y2err("dup failed" << " error:" << stringerror(errno));
+               y2err("fcntl(F_DUPFD_CLOEXEC) failed error:" << stringerror(errno));
                throw IOErrorException();
            }
+
+#ifdef ENABLE_XATTRS
+           xastatus = dir.xastatus;
+#endif
        }
 
        return *this;
@@ -185,10 +189,10 @@ namespace snapper
     vector<string>
     SDir::entries(entries_pred_t pred) const
     {
-       int fd = dup(dirfd);
+       int fd = fcntl(dirfd, F_DUPFD_CLOEXEC, 0);
        if (fd == -1)
        {
-           y2err("dup failed" << " error:" << stringerror(errno));
+           y2err("fcntl(F_DUPFD_CLOEXEC) failed error:" << stringerror(errno));
            throw IOErrorException();
        }