Skip to content

Commit

Permalink
fcntl_lock should be supported on Solaris (#1226)
Browse files Browse the repository at this point in the history
Even when Solaris libc doesn't define LOCK_SH, LOCK_EX, LOCK_NB and LOCK_UN (which are flock() related).
  • Loading branch information
psumbera authored and sunfishcode committed Dec 8, 2024
1 parent 4046ed7 commit 52f1af8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ use crate::fs::AtFlags;
target_os = "vita",
)))]
use crate::fs::FallocateFlags;
#[cfg(not(any(
target_os = "espidf",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
)))]
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))]
use crate::fs::FlockOperation;
#[cfg(any(linux_kernel, target_os = "freebsd"))]
use crate::fs::MemfdFlags;
Expand Down Expand Up @@ -1257,7 +1252,6 @@ pub(crate) fn fcntl_add_seals(fd: BorrowedFd<'_>, seals: SealFlags) -> io::Resul
target_os = "espidf",
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
)))]
Expand Down
34 changes: 28 additions & 6 deletions src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,27 +949,49 @@ bitflags! {
///
/// [`flock`]: crate::fs::flock
/// [`fcntl_lock`]: crate::fs::fcntl_lock
#[cfg(not(any(
target_os = "espidf",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
)))]
// Solaris doesn't support `flock` and doesn't define `LOCK_SH` etc., but we
// reuse this `FlockOperation` enum for `fcntl_lock`, so on Solaris we use
// our own made-up integer values.
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum FlockOperation {
/// `LOCK_SH`
#[cfg(not(target_os = "solaris"))]
LockShared = bitcast!(c::LOCK_SH),
/// `LOCK_SH`
#[cfg(target_os = "solaris")]
LockShared = bitcast!(1),
/// `LOCK_EX`
#[cfg(not(target_os = "solaris"))]
LockExclusive = bitcast!(c::LOCK_EX),
/// `LOCK_EX`
#[cfg(target_os = "solaris")]
LockExclusive = bitcast!(2),
/// `LOCK_UN`
#[cfg(not(target_os = "solaris"))]
Unlock = bitcast!(c::LOCK_UN),
/// `LOCK_UN`
#[cfg(target_os = "solaris")]
Unlock = bitcast!(8),
/// `LOCK_SH | LOCK_NB`
#[cfg(not(target_os = "solaris"))]
NonBlockingLockShared = bitcast!(c::LOCK_SH | c::LOCK_NB),
/// `LOCK_SH | LOCK_NB`
#[cfg(target_os = "solaris")]
NonBlockingLockShared = bitcast!(1 | 4),
/// `LOCK_EX | LOCK_NB`
#[cfg(not(target_os = "solaris"))]
NonBlockingLockExclusive = bitcast!(c::LOCK_EX | c::LOCK_NB),
/// `LOCK_EX | LOCK_NB`
#[cfg(target_os = "solaris")]
NonBlockingLockExclusive = bitcast!(2 | 4),
/// `LOCK_UN | LOCK_NB`
#[cfg(not(target_os = "solaris"))]
NonBlockingUnlock = bitcast!(c::LOCK_UN | c::LOCK_NB),
/// `LOCK_UN | LOCK_NB`
#[cfg(target_os = "solaris")]
NonBlockingUnlock = bitcast!(8 | 4),
}

/// `struct stat` for use with [`statat`] and [`fstat`].
Expand Down
2 changes: 0 additions & 2 deletions src/fs/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
target_os = "espidf",
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
)))]
Expand Down Expand Up @@ -102,7 +101,6 @@ pub fn fcntl_add_seals<Fd: AsFd>(fd: Fd, seals: SealFlags) -> io::Result<()> {
target_os = "espidf",
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
)))]
Expand Down

0 comments on commit 52f1af8

Please sign in to comment.