diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2011-05-17 11:04:53 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2011-05-17 11:04:53 -0700 |
commit | e9a2127e7fc20673e3aa1b09d54743077947c70e (patch) | |
tree | 1df056ff8f61cc7a81b9a42f2395828905e38a63 /src/cstore/unionfs/cstore-unionfs.cpp | |
parent | 9d5b213893a79939ac8f2e871e18ba3163eeab50 (diff) | |
download | vyatta-cfg-e9a2127e7fc20673e3aa1b09d54743077947c70e.tar.gz vyatta-cfg-e9a2127e7fc20673e3aa1b09d54743077947c70e.zip |
reimplement commit locking
Diffstat (limited to 'src/cstore/unionfs/cstore-unionfs.cpp')
-rw-r--r-- | src/cstore/unionfs/cstore-unionfs.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index 6ccdbf2..41ce008 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -63,6 +63,7 @@ const string UnionfsCstore::C_COMMENT_FILE = ".comment"; const string UnionfsCstore::C_TAG_NAME = "node.tag"; const string UnionfsCstore::C_VAL_NAME = "node.val"; const string UnionfsCstore::C_DEF_NAME = "node.def"; +const string UnionfsCstore::C_COMMIT_LOCK_FILE = "/opt/vyatta/config/.lock"; ////// static @@ -696,6 +697,23 @@ UnionfsCstore::commitConfig(commit::PrioNode& node) return true; } +bool +UnionfsCstore::getCommitLock() +{ + int fd = creat(C_COMMIT_LOCK_FILE.c_str(), 0777); + if (fd < 0) { + // should not happen since all commit processes should have write access + output_internal("getCommitLock() failed to open lock file\n"); + return false; + } + if (lockf(fd, F_TLOCK, 0) < 0) { + // locked by someone else + return false; + } + // got the lock + return true; +} + ////// virtual functions defined in base class /* check if current tmpl_path is a valid tmpl dir. |