Skip to content

Commit 49e5d24

Browse files
authored
Don't use on Solaris libc::LOCK_* which were removed from libc in ver… (#15143)
Relevant libc change was: rust-lang/libc@251e8e8
2 parents 027b415 + 1cc87c9 commit 49e5d24

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/cargo/util/flock.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -436,24 +436,41 @@ mod sys {
436436
use std::io::{Error, Result};
437437
use std::os::unix::io::AsRawFd;
438438

439+
#[cfg(not(target_os = "solaris"))]
440+
const LOCK_SH: i32 = libc::LOCK_SH;
441+
#[cfg(target_os = "solaris")]
442+
const LOCK_SH: i32 = 1;
443+
#[cfg(not(target_os = "solaris"))]
444+
const LOCK_EX: i32 = libc::LOCK_EX;
445+
#[cfg(target_os = "solaris")]
446+
const LOCK_EX: i32 = 2;
447+
#[cfg(not(target_os = "solaris"))]
448+
const LOCK_NB: i32 = libc::LOCK_NB;
449+
#[cfg(target_os = "solaris")]
450+
const LOCK_NB: i32 = 4;
451+
#[cfg(not(target_os = "solaris"))]
452+
const LOCK_UN: i32 = libc::LOCK_UN;
453+
#[cfg(target_os = "solaris")]
454+
const LOCK_UN: i32 = 8;
455+
439456
pub(super) fn lock_shared(file: &File) -> Result<()> {
440-
flock(file, libc::LOCK_SH)
457+
flock(file, LOCK_SH)
441458
}
442459

443460
pub(super) fn lock_exclusive(file: &File) -> Result<()> {
444-
flock(file, libc::LOCK_EX)
461+
flock(file, LOCK_EX)
445462
}
446463

447464
pub(super) fn try_lock_shared(file: &File) -> Result<()> {
448-
flock(file, libc::LOCK_SH | libc::LOCK_NB)
465+
flock(file, LOCK_SH | LOCK_NB)
449466
}
450467

451468
pub(super) fn try_lock_exclusive(file: &File) -> Result<()> {
452-
flock(file, libc::LOCK_EX | libc::LOCK_NB)
469+
flock(file, LOCK_EX | LOCK_NB)
453470
}
454471

455472
pub(super) fn unlock(file: &File) -> Result<()> {
456-
flock(file, libc::LOCK_UN)
473+
flock(file, LOCK_UN)
457474
}
458475

459476
pub(super) fn error_contended(err: &Error) -> bool {
@@ -493,18 +510,18 @@ mod sys {
493510
l_pid: 0,
494511
l_pad: [0, 0, 0, 0],
495512
};
496-
flock.l_type = if flag & libc::LOCK_UN != 0 {
513+
flock.l_type = if flag & LOCK_UN != 0 {
497514
libc::F_UNLCK
498-
} else if flag & libc::LOCK_EX != 0 {
515+
} else if flag & LOCK_EX != 0 {
499516
libc::F_WRLCK
500-
} else if flag & libc::LOCK_SH != 0 {
517+
} else if flag & LOCK_SH != 0 {
501518
libc::F_RDLCK
502519
} else {
503520
panic!("unexpected flock() operation")
504521
};
505522

506523
let mut cmd = libc::F_SETLKW;
507-
if (flag & libc::LOCK_NB) != 0 {
524+
if (flag & LOCK_NB) != 0 {
508525
cmd = libc::F_SETLK;
509526
}
510527

0 commit comments

Comments
 (0)