]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use O_CLOEXEC
authorArvin Schnell <aschnell@suse.de>
Fri, 11 Jan 2013 13:31:42 +0000 (14:31 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 11 Jan 2013 13:31:42 +0000 (14:31 +0100)
snapper/AsciiFile.cc
snapper/Compare.cc
snapper/Comparison.cc
snapper/File.cc
snapper/FileUtils.cc
snapper/Logger.cc
snapper/Snapshot.cc

index 2e2127e0c2f3a439c2788aeb3e01d20f415cfef4..13f36db47c3bbe2d597d99cf7702d29f5d9a3439 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2004-2012] Novell, Inc.
+ * Copyright (c) [2004-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -60,7 +60,7 @@ namespace snapper
     AsciiFileReader::AsciiFileReader(const string& filename)
        : file(NULL), buffer(NULL), len(0)
     {
-       file = fopen(filename.c_str(), "r");
+       file = fopen(filename.c_str(), "re");
        if (file == NULL)
        {
            y2war("open for '" << filename << "' failed");
index 84deeb8b3e5301261e96338e28af595e839d6a50..25fa54962ddfc557d15947d5d2fa9e3077dbef87 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -58,14 +58,14 @@ namespace snapper
        if ((stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino))
            return true;
 
-       int fd1 = file1.open(O_RDONLY | O_NOFOLLOW | O_NOATIME);
+       int fd1 = file1.open(O_RDONLY | O_NOFOLLOW | O_NOATIME | O_CLOEXEC);
        if (fd1 < 0)
        {
            y2err("open failed path:" << file1.fullname() << " errno:" << errno);
            return false;
        }
 
-       int fd2 = file2.open(O_RDONLY | O_NOFOLLOW | O_NOATIME);
+       int fd2 = file2.open(O_RDONLY | O_NOFOLLOW | O_NOATIME | O_CLOEXEC);
        if (fd2 < 0)
        {
            y2err("open failed path:" << file2.fullname() << " errno:" << errno);
index f1bdc90b6531b7c87da57ef839b004a920b390e4..dc9e4a7270934c9666735748f80886f4beaae9dc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -160,7 +160,7 @@ namespace snapper
            SDir info_dir = SDir(infos_dir, decString(num2));
 
            int fd = info_dir.open("filelist-" + decString(num1) + ".txt", O_RDONLY | O_NOATIME |
-                                  O_NOFOLLOW);
+                                  O_NOFOLLOW | O_CLOEXEC);
            if (fd == -1)
                return false;
 
index 165639e9e3bff8dfe7f94c736fb3593af86f7be6..6669e4c515b9fbaa6bd039024e1cc7c07fa58e20 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -327,7 +327,7 @@ namespace snapper
     bool
     File::createFile(mode_t mode, uid_t owner, gid_t group) const
     {
-       int src_fd = open(getAbsolutePath(LOC_PRE).c_str(), O_RDONLY | O_LARGEFILE);
+       int src_fd = open(getAbsolutePath(LOC_PRE).c_str(), O_RDONLY | O_LARGEFILE | O_CLOEXEC);
        if (src_fd < 0)
        {
            y2err("open failed errno:" << errno << " (" << stringerror(errno) << ")");
@@ -335,7 +335,7 @@ namespace snapper
        }
 
        int dest_fd = open(getAbsolutePath(LOC_SYSTEM).c_str(), O_WRONLY | O_LARGEFILE |
-                          O_CREAT | O_TRUNC, mode);
+                          O_CREAT | O_TRUNC | O_CLOEXEC, mode);
        if (dest_fd < 0)
        {
            y2err("open failed errno:" << errno << " (" << stringerror(errno) << ")");
index 4e7b0d53a65d94d6f1f0f2a9eb6aa5090b11bf1f..990fa79e50af836d2c05465d2d89cc901d409484 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -45,7 +45,7 @@ namespace snapper
     SDir::SDir(const string& base_path)
        : base_path(base_path), path()
     {
-       dirfd = ::open(base_path.c_str(), O_RDONLY | O_NOATIME);
+       dirfd = ::open(base_path.c_str(), O_RDONLY | O_NOATIME | O_CLOEXEC);
        if (dirfd < 0)
        {
            y2err("open failed path:" << base_path << " error:" << stringerror(errno));
@@ -65,7 +65,7 @@ namespace snapper
     SDir::SDir(const SDir& dir, const string& name)
        : base_path(dir.base_path), path(dir.path + "/" + name)
     {
-       dirfd = ::openat(dir.dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME);
+       dirfd = ::openat(dir.dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME | O_CLOEXEC);
        if (dirfd < 0)
        {
            y2err("open failed path:" << dir.fullname(name) << " (" << stringerror(errno) << ")");
@@ -286,7 +286,7 @@ namespace snapper
                v /= 62;
            }
 
-           int fd = open(name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+           int fd = open(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
            if (fd >= 0)
                return fd;
            else if (errno != EEXIST)
index 133812f026496d28f8b5dcb7cd72820a3aefbb16..e286e11f090365d4d7a46c92a3c8de414912ead6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2004-2012] Novell, Inc.
+ * Copyright (c) [2004-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -74,7 +74,7 @@ namespace snapper
 
        boost::lock_guard<boost::mutex> lock(mutex);
 
-       FILE* f = fopen(filename->c_str(), "a");
+       FILE* f = fopen(filename->c_str(), "ae");
        if (f)
        {
            string tmp = text;
index 072df17bd8677fc0e4218c32cd9857ac2dee25b6..2b80a6c2157364ecf8481e3f161835a59abf3bbc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -182,7 +182,7 @@ namespace snapper
            try
            {
                SDir info_dir(infos_dir, *it1);
-               int fd = info_dir.open("info.xml", O_NOFOLLOW);
+               int fd = info_dir.open("info.xml", O_NOFOLLOW | O_CLOEXEC);
                XmlFile file(fd, "");
 
                const xmlNode* root = file.getRootElement();