forked from lix-project/lix
openLockFile: Return an AutoCloseFD
This commit is contained in:
parent
c0f2f4eeef
commit
a55f589720
|
@ -109,7 +109,7 @@ static std::vector<machine> read_conf()
|
||||||
|
|
||||||
static string currentLoad;
|
static string currentLoad;
|
||||||
|
|
||||||
static int openSlotLock(const machine & m, unsigned long long slot)
|
static AutoCloseFD openSlotLock(const machine & m, unsigned long long slot)
|
||||||
{
|
{
|
||||||
std::ostringstream fn_stream(currentLoad, std::ios_base::ate | std::ios_base::out);
|
std::ostringstream fn_stream(currentLoad, std::ios_base::ate | std::ios_base::out);
|
||||||
fn_stream << "/";
|
fn_stream << "/";
|
||||||
|
@ -187,7 +187,7 @@ int main (int argc, char * * argv)
|
||||||
AutoCloseFD free;
|
AutoCloseFD free;
|
||||||
unsigned long long load = 0;
|
unsigned long long load = 0;
|
||||||
for (unsigned long long slot = 0; slot < m.maxJobs; ++slot) {
|
for (unsigned long long slot = 0; slot < m.maxJobs; ++slot) {
|
||||||
AutoCloseFD slotLock = openSlotLock(m, slot);
|
auto slotLock = openSlotLock(m, slot);
|
||||||
if (lockFile(slotLock.get(), ltWrite, false)) {
|
if (lockFile(slotLock.get(), ltWrite, false)) {
|
||||||
if (!free) {
|
if (!free) {
|
||||||
free = std::move(slotLock);
|
free = std::move(slotLock);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
int openLockFile(const Path & path, bool create)
|
AutoCloseFD openLockFile(const Path & path, bool create)
|
||||||
{
|
{
|
||||||
AutoCloseFD fd;
|
AutoCloseFD fd;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ int openLockFile(const Path & path, bool create)
|
||||||
if (!fd && (create || errno != ENOENT))
|
if (!fd && (create || errno != ENOENT))
|
||||||
throw SysError(format("opening lock file ‘%1%’") % path);
|
throw SysError(format("opening lock file ‘%1%’") % path);
|
||||||
|
|
||||||
return fd.release();
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "types.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -9,7 +9,7 @@ namespace nix {
|
||||||
/* Open (possibly create) a lock file and return the file descriptor.
|
/* Open (possibly create) a lock file and return the file descriptor.
|
||||||
-1 is returned if create is false and the lock could not be opened
|
-1 is returned if create is false and the lock could not be opened
|
||||||
because it doesn't exist. Any other error throws an exception. */
|
because it doesn't exist. Any other error throws an exception. */
|
||||||
int openLockFile(const Path & path, bool create);
|
AutoCloseFD openLockFile(const Path & path, bool create);
|
||||||
|
|
||||||
/* Delete an open lock file. */
|
/* Delete an open lock file. */
|
||||||
void deleteLockFile(const Path & path, int fd);
|
void deleteLockFile(const Path & path, int fd);
|
||||||
|
|
Loading…
Reference in a new issue