Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements cargo file locking using fcntl on Solaris. #11439

Merged
merged 1 commit into from
Dec 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/cargo/util/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,38 @@ mod sys {

#[cfg(target_os = "solaris")]
fn flock(file: &File, flag: libc::c_int) -> Result<()> {
// Solaris lacks flock(), so simply succeed with a no-op
Ok(())
// Solaris lacks flock(), so try to emulate using fcntl()
let mut flock = libc::flock {
l_type: 0,
l_whence: 0,
l_start: 0,
l_len: 0,
l_sysid: 0,
l_pid: 0,
l_pad: [0, 0, 0, 0],
};
flock.l_type = if flag & libc::LOCK_UN != 0 {
libc::F_RDLCK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be F_UNLCK?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my, I didn't catch that. @psumbera can you follow up with a PR to update this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it. Sorry I didn't catch that. Since I have tested it this doesn't cause the problem with use in cargo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if flag & libc::LOCK_EX != 0 {
libc::F_WRLCK
} else if flag & libc::LOCK_SH != 0 {
libc::F_RDLCK
} else {
panic!("unexpected flock() operation")
};

let mut cmd = libc::F_SETLKW;
if (flag & libc::LOCK_NB) != 0 {
cmd = libc::F_SETLK;
}

let ret = unsafe { libc::fcntl(file.as_raw_fd(), cmd, &flock) };

if ret < 0 {
Err(Error::last_os_error())
} else {
Ok(())
}
}
}

Expand Down