Skip to content

Commit 52f1af8

Browse files
psumberasunfishcode
authored andcommitted
fcntl_lock should be supported on Solaris (#1226)
Even when Solaris libc doesn't define LOCK_SH, LOCK_EX, LOCK_NB and LOCK_UN (which are flock() related).
1 parent 4046ed7 commit 52f1af8

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ use crate::fs::AtFlags;
3636
target_os = "vita",
3737
)))]
3838
use crate::fs::FallocateFlags;
39-
#[cfg(not(any(
40-
target_os = "espidf",
41-
target_os = "solaris",
42-
target_os = "vita",
43-
target_os = "wasi"
44-
)))]
39+
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))]
4540
use crate::fs::FlockOperation;
4641
#[cfg(any(linux_kernel, target_os = "freebsd"))]
4742
use crate::fs::MemfdFlags;
@@ -1257,7 +1252,6 @@ pub(crate) fn fcntl_add_seals(fd: BorrowedFd<'_>, seals: SealFlags) -> io::Resul
12571252
target_os = "espidf",
12581253
target_os = "fuchsia",
12591254
target_os = "redox",
1260-
target_os = "solaris",
12611255
target_os = "vita",
12621256
target_os = "wasi"
12631257
)))]

src/backend/libc/fs/types.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -949,27 +949,49 @@ bitflags! {
949949
///
950950
/// [`flock`]: crate::fs::flock
951951
/// [`fcntl_lock`]: crate::fs::fcntl_lock
952-
#[cfg(not(any(
953-
target_os = "espidf",
954-
target_os = "solaris",
955-
target_os = "vita",
956-
target_os = "wasi"
957-
)))]
952+
// Solaris doesn't support `flock` and doesn't define `LOCK_SH` etc., but we
953+
// reuse this `FlockOperation` enum for `fcntl_lock`, so on Solaris we use
954+
// our own made-up integer values.
955+
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))]
958956
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
959957
#[repr(u32)]
960958
pub enum FlockOperation {
961959
/// `LOCK_SH`
960+
#[cfg(not(target_os = "solaris"))]
962961
LockShared = bitcast!(c::LOCK_SH),
962+
/// `LOCK_SH`
963+
#[cfg(target_os = "solaris")]
964+
LockShared = bitcast!(1),
963965
/// `LOCK_EX`
966+
#[cfg(not(target_os = "solaris"))]
964967
LockExclusive = bitcast!(c::LOCK_EX),
968+
/// `LOCK_EX`
969+
#[cfg(target_os = "solaris")]
970+
LockExclusive = bitcast!(2),
965971
/// `LOCK_UN`
972+
#[cfg(not(target_os = "solaris"))]
966973
Unlock = bitcast!(c::LOCK_UN),
974+
/// `LOCK_UN`
975+
#[cfg(target_os = "solaris")]
976+
Unlock = bitcast!(8),
967977
/// `LOCK_SH | LOCK_NB`
978+
#[cfg(not(target_os = "solaris"))]
968979
NonBlockingLockShared = bitcast!(c::LOCK_SH | c::LOCK_NB),
980+
/// `LOCK_SH | LOCK_NB`
981+
#[cfg(target_os = "solaris")]
982+
NonBlockingLockShared = bitcast!(1 | 4),
969983
/// `LOCK_EX | LOCK_NB`
984+
#[cfg(not(target_os = "solaris"))]
970985
NonBlockingLockExclusive = bitcast!(c::LOCK_EX | c::LOCK_NB),
986+
/// `LOCK_EX | LOCK_NB`
987+
#[cfg(target_os = "solaris")]
988+
NonBlockingLockExclusive = bitcast!(2 | 4),
971989
/// `LOCK_UN | LOCK_NB`
990+
#[cfg(not(target_os = "solaris"))]
972991
NonBlockingUnlock = bitcast!(c::LOCK_UN | c::LOCK_NB),
992+
/// `LOCK_UN | LOCK_NB`
993+
#[cfg(target_os = "solaris")]
994+
NonBlockingUnlock = bitcast!(8 | 4),
973995
}
974996

975997
/// `struct stat` for use with [`statat`] and [`fstat`].

src/fs/fcntl.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
target_os = "espidf",
99
target_os = "fuchsia",
1010
target_os = "redox",
11-
target_os = "solaris",
1211
target_os = "vita",
1312
target_os = "wasi"
1413
)))]
@@ -102,7 +101,6 @@ pub fn fcntl_add_seals<Fd: AsFd>(fd: Fd, seals: SealFlags) -> io::Result<()> {
102101
target_os = "espidf",
103102
target_os = "fuchsia",
104103
target_os = "redox",
105-
target_os = "solaris",
106104
target_os = "vita",
107105
target_os = "wasi"
108106
)))]

0 commit comments

Comments
 (0)