1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:48:14 +00:00

Kernel: Don't let locks of the same owner conflict with each other

Documentation on POSIX locks seems sparse, but this is how the Linux
kernel implementation handles it.
This commit is contained in:
Tim Schumacher 2022-06-17 19:06:05 +02:00 committed by Brian Gianforcaro
parent dc6016cd18
commit cd189999d1

View file

@ -348,6 +348,10 @@ ErrorOr<void> Inode::get_flock(OpenFileDescription const& description, Userspace
if (!range_overlap(lock.start, lock.len, lookup.l_start, lookup.l_len))
continue;
// Locks with the same owner can't conflict with each other.
if (lock.pid == Process::current().pid())
continue;
if ((lookup.l_type == F_RDLCK && lock.type == F_WRLCK) || lookup.l_type == F_WRLCK) {
lookup = { lock.type, SEEK_SET, lock.start, lock.len, lock.pid };
return copy_to_user(reference_lock, &lookup);