Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Open the lock files close-on-exec
Each exec filter and snapshot compressor a fill runs inherited the slot's lock descriptor beside the stdout it writes into. An flock lasts until its last copy closes and nothing waits for a process a filter leaves behind, so a fill killed before its rename could leave the slot locked, and served stale or uncached, for as long as such a process lived. The scan holds its lock across no exec and opens the same way so that the two stay alike.
Diffstat (limited to '')
-rw-r--r--source/cache.c4
1 file changed, 3 insertions, 1 deletion
diff --git a/source/cache.c b/source/cache.c
index 4802ab5..12151b8 100644
--- a/source/cache.c
+++ b/source/cache.c
@@ -202,7 +202,9 @@ static int lock_slot(struct cache_slot *slot)
{
struct stat held, named;
- slot->lock_fd = open(slot->lock_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+ // Close-on-exec, so that a program the fill runs gets the file only
+ // as its stdout, and holds the lock no longer than it can write there.
+ slot->lock_fd = open(slot->lock_path, O_RDWR | O_CREAT | O_CLOEXEC, S_IRUSR | S_IWUSR);
if (slot->lock_fd == -1)
return errno;
// An flock rather than a POSIX record lock. The descriptor is put on