diff options
author | eldritch horrors <pennae@lix.systems> | 2024-03-18 14:52:04 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-03-18 15:42:52 -0600 |
commit | f38ae92a38a66b597dbd6975219d6ddb4f52fa4f (patch) | |
tree | be6e1ed225e3d77a3c1fbcef1778169878326cbe /src/libstore/pathlocks.cc | |
parent | 0f518f44e289114eb4828c8232bc0b79c7a85ac7 (diff) |
libutil: make AutoCloseFD a better resource
add a reset() method to close the wrapped fd instead of assigning magic
constants. also make the from-fd constructor explicit so you can't
accidentally assign the *wrong* magic constant, or even an unrelated
integer that also just happens to be an fd by pure chance.
Change-Id: I51311b0f6e040240886b5103d39d1794a6acc325
Diffstat (limited to 'src/libstore/pathlocks.cc')
-rw-r--r-- | src/libstore/pathlocks.cc | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 955ae3a34..3e654c1c9 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -17,9 +17,7 @@ namespace nix { AutoCloseFD openLockFile(const Path & path, bool create) { - AutoCloseFD fd; - - fd = open(path.c_str(), O_CLOEXEC | O_RDWR | (create ? O_CREAT : 0), 0600); + AutoCloseFD fd{open(path.c_str(), O_CLOEXEC | O_RDWR | (create ? O_CREAT : 0), 0600)}; if (!fd && (create || errno != ENOENT)) throw SysError("opening lock file '%1%'", path); |