Skip to content

Conversation

@sunfishcode
Copy link
Member

Add an fcntl_lock function implementing fcntl-style process-associated locking. Currently this only supports locking the entire file.

Add an `fcntl_lock` function implementing fcntl-style
process-associated locking. Currently this only supports locking the
entire file.
Copy link
Contributor

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Somewhat superficial LGTM

#[cfg(target_pointer_width = "32")]
{
ret(syscall_readonly!(
__NR_fcntl64,
Copy link
Contributor

Choose a reason for hiding this comment

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

How about if cfg!(target_pointer_width = "32") { __NR_fcntl64 } else { __NR_fcntl } here and dedup the blocks?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately syscall_readonly! is a macro that does special things with the first parameter and needs it to be a __NR_* literal.

l_whence: 0,
l_start: 0,
l_len: 0,
..core::mem::zeroed()
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like we could rely on core::mem::zeroed() also handling the zero-init for the other members?

Copy link
Member Author

Choose a reason for hiding this comment

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

Setting l_len to zero is a special case in the documented behavior of fcntl, so I like keeping it explicit. I've now added more comments about this though.

@sunfishcode sunfishcode merged commit 9d2db17 into main Mar 5, 2023
@sunfishcode sunfishcode deleted the sunfishcode/fcntl branch March 5, 2023 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants