From 99d1061e7662b35f811fab2c9a3dfad670db7718 Mon Sep 17 00:00:00 2001 From: Rishabh Das Date: Sat, 8 Feb 2025 19:23:40 +0530 Subject: [PATCH] Document that `Err(io::Errno::INVAL)` is returned when `FlockType` is unlocked in `fcntl_getlk` --- src/backend/libc/process/syscalls.rs | 2 ++ src/process/fcntl_getlk.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/libc/process/syscalls.rs b/src/backend/libc/process/syscalls.rs index 79642b790..a39e770af 100644 --- a/src/backend/libc/process/syscalls.rs +++ b/src/backend/libc/process/syscalls.rs @@ -666,6 +666,8 @@ pub(crate) fn getgroups(buf: &mut [Gid]) -> io::Result { )))] #[inline] pub(crate) fn fcntl_getlk(fd: BorrowedFd<'_>, lock: &Flock) -> io::Result> { + // In order to guarantee consistent behavior across all POSIX platforms, return `EINVAL` when + // `flock.l_type` is `F_UNLCK` if lock.typ == crate::process::FlockType::Unlocked { return Err(io::Errno::INVAL); } diff --git a/src/process/fcntl_getlk.rs b/src/process/fcntl_getlk.rs index 6020a893d..c592db7ce 100644 --- a/src/process/fcntl_getlk.rs +++ b/src/process/fcntl_getlk.rs @@ -2,7 +2,10 @@ use super::Flock; use crate::fd::AsFd; use crate::{backend, io}; -/// `fcntl(fd, F_GETLK)`—Get the first lock that blocks the lock description pointed to by the argument `lock`. If no such lock is found, then `None` is returned +/// `fcntl(fd, F_GETLK)`—Get the first lock that blocks the lock description pointed to by the +/// argument `lock`. If no such lock is found, then `None` is returned +/// +/// If `lock.typ` is `FlockType::Unlocked`, then `Err(io::Errno::INVAL)` is returned /// /// # References /// - [POSIX]