Skip to content

Conversation

weihanglo
Copy link
Member

Upstream Solaris flock emulation to libstd from cargo.

This is borrowed from
https://github.com/rust-lang/cargo/blob/3b379fcc541b39321a7758552d37e5e0cc4277b9/src/cargo/util/flock.rs#L502-L536 which was implemented by an Oracle employee.
The code has been in cargo since 2022-12.

Python's fcntl.flock emulates like this as well: https://github.com/python/cpython/blob/c919d02edecfe9d75fe374756fb8aa1db8d95f55/Modules/fcntlmodule.c#L337-L400

We did the same thing in

let file = OpenOptions::new()
.read(true)
.write(true)
.create(create)
.mode(libc::S_IRWXU as u32)
.open(p)?;
let lock_type = if exclusive { libc::F_WRLCK } else { libc::F_RDLCK };
let mut flock: libc::flock = unsafe { mem::zeroed() };
#[cfg(not(all(target_os = "hurd", target_arch = "x86")))]
{
flock.l_type = lock_type as libc::c_short;
flock.l_whence = libc::SEEK_SET as libc::c_short;
}
#[cfg(all(target_os = "hurd", target_arch = "x86"))]
{
flock.l_type = lock_type as libc::c_int;
flock.l_whence = libc::SEEK_SET as libc::c_int;
}
flock.l_start = 0;
flock.l_len = 0;
let cmd = if wait { libc::F_SETLKW } else { libc::F_SETLK };
let ret = unsafe { libc::fcntl(file.as_raw_fd(), cmd, &flock) };
if ret == -1 { Err(io::Error::last_os_error()) } else { Ok(Lock { file }) }
}

However, should we just always falls back to fcntl for all Unix, instead of "unsupported"?

try-job: *-solaris

@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 6, 2025
@weihanglo

This comment was marked as outdated.

rust-bors bot added a commit that referenced this pull request Sep 6, 2025
feat(std): emulate flock for solaris via fcntl

try-job: `*-solaris`
@rust-bors

This comment has been minimized.

@weihanglo
Copy link
Member Author

cc @psumbera

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@weihanglo

This comment was marked as outdated.

rust-bors bot added a commit that referenced this pull request Sep 6, 2025
feat(std): emulate flock for solaris via fcntl

try-job: `*-solaris`
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@weihanglo

This comment was marked as outdated.

@rust-bors

This comment was marked as outdated.

@weihanglo

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 6, 2025
feat(std): emulate flock for solaris via fcntl

try-job: `*-solaris`
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@weihanglo weihanglo marked this pull request as draft September 6, 2025 19:15
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2025
@weihanglo
Copy link
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 7, 2025
feat(std): emulate flock for solaris via fcntl

try-job: `*-solaris`
@rust-bors
Copy link

rust-bors bot commented Sep 7, 2025

☀️ Try build successful (CI)
Build commit: bd77cf6 (bd77cf6012347fd5f68759320ff8e2d5dd2cf6a4, parent: 76863e340416e7f21955bdaf0ae9728eb51f5671)

@weihanglo
Copy link
Member Author

@rustbot ready

This should be good for review :)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 7, 2025
@weihanglo weihanglo marked this pull request as ready for review September 7, 2025 04:00
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 7, 2025

📌 Commit 01edb24 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 7, 2025
bors added a commit that referenced this pull request Sep 7, 2025
Rollup of 4 pull requests

Successful merges:

 - #146170 (fix: offline rustdoc html missing favicon)
 - #146209 (Misc LTO cleanups)
 - #146269 (feat(std): emulate flock for solaris via fcntl)
 - #146297 (Introduce PlaceContext::may_observe_address.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e4e4829 into rust-lang:master Sep 7, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Sep 7, 2025
rust-timer added a commit that referenced this pull request Sep 7, 2025
Rollup merge of #146269 - weihanglo:solaris-flock, r=Mark-Simulacrum

feat(std): emulate flock for solaris via fcntl

Upstream Solaris flock emulation to libstd from cargo.

This is borrowed from
https://github.com/rust-lang/cargo/blob/3b379fcc541b39321a7758552d37e5e0cc4277b9/src/cargo/util/flock.rs#L502-L536 which was implemented by an Oracle employee.
The code has been in cargo since 2022-12.

Python's `fcntl.flock` emulates like this as well: https://github.com/python/cpython/blob/c919d02edecfe9d75fe374756fb8aa1db8d95f55/Modules/fcntlmodule.c#L337-L400

We did the same thing in
https://github.com/rust-lang/rust/blob/0d0f4eac8b98133e5da6d3604d86a8f3b5a67844/compiler/rustc_data_structures/src/flock/unix.rs#L13-L39

However, should we just always falls back to fcntl for all Unix, instead of "unsupported"?

try-job: `*-solaris`
@weihanglo weihanglo deleted the solaris-flock branch September 8, 2025 00:13
github-merge-queue bot pushed a commit to rust-lang/cargo that referenced this pull request Sep 8, 2025
### What does this PR try to resolve?

Replace flock with std flock.

### How to test and review this PR?

Given we've supported Oracle since 2022-12 and don't want to break
people,
this is blocked on std supporting flock emulation via fcntl
rust-lang/rust#146269
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Sep 10, 2025
…mulacrum

feat(std): emulate flock for solaris via fcntl

Upstream Solaris flock emulation to libstd from cargo.

This is borrowed from
https://github.com/rust-lang/cargo/blob/3b379fcc541b39321a7758552d37e5e0cc4277b9/src/cargo/util/flock.rs#L502-L536 which was implemented by an Oracle employee.
The code has been in cargo since 2022-12.

Python's `fcntl.flock` emulates like this as well: https://github.com/python/cpython/blob/c919d02edecfe9d75fe374756fb8aa1db8d95f55/Modules/fcntlmodule.c#L337-L400

We did the same thing in
https://github.com/rust-lang/rust/blob/0d0f4eac8b98133e5da6d3604d86a8f3b5a67844/compiler/rustc_data_structures/src/flock/unix.rs#L13-L39

However, should we just always falls back to fcntl for all Unix, instead of "unsupported"?

try-job: `*-solaris`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants