Skip to content

Commit 0b16cf0

Browse files
committed
eis: Fix locking of socket .lock files
If we call `UnlinkOnDrop::new` before securing an `flock` lock, we can end up unlinking a lock file owned by a different process.
1 parent b72985a commit 0b16cf0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/util.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ impl LockFile {
121121
.write(true)
122122
.mode(0o660)
123123
.open(&path)?;
124-
let inner = UnlinkOnDrop::new(inner, path);
125-
let locked =
126-
rustix::fs::flock(&inner.inner, FlockOperation::NonBlockingLockExclusive).is_ok();
127-
Ok(Some(inner).filter(|_| locked).map(Self))
124+
let locked = rustix::fs::flock(&inner, FlockOperation::NonBlockingLockExclusive).is_ok();
125+
Ok(if locked {
126+
Some(Self(UnlinkOnDrop::new(inner, path)))
127+
} else {
128+
None
129+
})
128130
}
129131
}
130132

0 commit comments

Comments
 (0)