From: Arvin Schnell Date: Fri, 11 Jan 2013 13:31:42 +0000 (+0100) Subject: - use O_CLOEXEC X-Git-Tag: v0.1.3~60 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a208b0cace6304084b60bacbaa03420411e860e;p=thirdparty%2Fsnapper.git - use O_CLOEXEC --- diff --git a/snapper/AsciiFile.cc b/snapper/AsciiFile.cc index 2e2127e0..13f36db4 100644 --- a/snapper/AsciiFile.cc +++ b/snapper/AsciiFile.cc @@ -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"); diff --git a/snapper/Compare.cc b/snapper/Compare.cc index 84deeb8b..25fa5496 100644 --- a/snapper/Compare.cc +++ b/snapper/Compare.cc @@ -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); diff --git a/snapper/Comparison.cc b/snapper/Comparison.cc index f1bdc90b..dc9e4a72 100644 --- a/snapper/Comparison.cc +++ b/snapper/Comparison.cc @@ -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; diff --git a/snapper/File.cc b/snapper/File.cc index 165639e9..6669e4c5 100644 --- a/snapper/File.cc +++ b/snapper/File.cc @@ -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) << ")"); diff --git a/snapper/FileUtils.cc b/snapper/FileUtils.cc index 4e7b0d53..990fa79e 100644 --- a/snapper/FileUtils.cc +++ b/snapper/FileUtils.cc @@ -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) diff --git a/snapper/Logger.cc b/snapper/Logger.cc index 133812f0..e286e11f 100644 --- a/snapper/Logger.cc +++ b/snapper/Logger.cc @@ -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 lock(mutex); - FILE* f = fopen(filename->c_str(), "a"); + FILE* f = fopen(filename->c_str(), "ae"); if (f) { string tmp = text; diff --git a/snapper/Snapshot.cc b/snapper/Snapshot.cc index 072df17b..2b80a6c2 100644 --- a/snapper/Snapshot.cc +++ b/snapper/Snapshot.cc @@ -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();