#include "pathlocks.hh" #include "util.hh" #include #include #include #include #include namespace nix { int openLockFile(const Path & path, bool create) { AutoCloseFD fd; fd = open(path.c_str(), O_RDWR | (create ? O_CREAT : 0), 0600); if (fd == -1 && (create || errno != ENOENT)) throw SysError(format("opening lock file `%1%'") % path); closeOnExec(fd); return fd.borrow(); } void deleteLockFile(const Path & path, int fd) { /* Get rid of the lock file. Have to be careful not to introduce races. Write a (meaningless) token to the file to indicate to other processes waiting on this lock that the lock is stale (deleted). */ unlink(path.c_str()); writeFull(fd, "d"); /* Note that the result of unlink() is ignored; removing the lock file is an optimisation, not a necessity. */ } bool lockFile(int fd, LockType lockType, bool wait) { struct flock lock; if (lockType == ltRead) lock.l_type = F_RDLCK; else if (lockType == ltWrite) lock.l_type = F_WRLCK; else if (lockType == ltNone) lock.l_type = F_UNLCK;
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2015-03-29v2.4.19Mihai Bazon
2015-03-29v2.4.18Mihai Bazon
2015-03-18Bump yargs version (for .array arguments)Mihai Bazon
2015-03-11v2.4.17Mihai Bazon
2015-01-01Use yargs instead of optimist.Kenneth Powers
2014-12-09v2.4.16Mihai Bazon
2014-08-04Merge branch 'master' of https://github.com/RReverser/UglifyJS2Mihai Bazon
2014-08-03Added generative testing for AST conversions.Ingvar Stepanyan
2014-07-28Added licensegdw2
2014-07-09v2.4.15Mihai Bazon
2014-07-09Lock source-map to 0.1.34