From cb5e7254b66a06b78a5659551a6f28fc67e52267 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 11 Jul 2016 15:44:44 -0400 Subject: Modernize AutoCloseFD --- src/libstore/pathlocks.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libstore/pathlocks.cc') diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index d0a0f812e3d2..b9e178d61f3c 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -17,10 +17,10 @@ int openLockFile(const Path & path, bool create) AutoCloseFD fd; fd = open(path.c_str(), O_CLOEXEC | O_RDWR | (create ? O_CREAT : 0), 0600); - if (fd == -1 && (create || errno != ENOENT)) + if (!fd && (create || errno != ENOENT)) throw SysError(format("opening lock file ‘%1%’") % path); - return fd.borrow(); + return fd.release(); } @@ -119,10 +119,10 @@ bool PathLocks::lockPaths(const PathSet & _paths, fd = openLockFile(lockPath, true); /* Acquire an exclusive lock. */ - if (!lockFile(fd, ltWrite, false)) { + if (!lockFile(fd.get(), ltWrite, false)) { if (wait) { if (waitMsg != "") printMsg(lvlError, waitMsg); - lockFile(fd, ltWrite, true); + lockFile(fd.get(), ltWrite, true); } else { /* Failed to lock this path; release all other locks. */ @@ -136,7 +136,7 @@ bool PathLocks::lockPaths(const PathSet & _paths, /* Check that the lock file hasn't become stale (i.e., hasn't been unlinked). */ struct stat st; - if (fstat(fd, &st) == -1) + if (fstat(fd.get(), &st) == -1) throw SysError(format("statting lock file ‘%1%’") % lockPath); if (st.st_size != 0) /* This lock file has been unlinked, so we're holding @@ -149,7 +149,7 @@ bool PathLocks::lockPaths(const PathSet & _paths, } /* Use borrow so that the descriptor isn't closed. */ - fds.push_back(FDPair(fd.borrow(), lockPath)); + fds.push_back(FDPair(fd.release(), lockPath)); lockedPaths.insert(lockPath); } -- cgit 1.4.1