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

Support F_GETFL and F_SETFL for fcntl #4212

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

tiif
Copy link
Contributor

@tiif tiif commented Feb 26, 2025

This PR supports F_SETFL and F_GETFL flags for fcntl. In this implementation, F_SETFL can only set O_NONBLOCK flag.

If setfl is called while a fd is blocking, that fd will not be affected by the new flag value and will continue blocking like normal until a read/write wakes it up (it acts like it never knew the setfl has happened). But any operation after setfl will see the new flag value.

The interaction between these fcntl operations and blocking fd is summarised here.

Fixes #4119

Copy link
Contributor Author

@tiif tiif left a comment

Choose a reason for hiding this comment

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

@rustbot ready

@@ -22,7 +22,7 @@ const MAX_SOCKETPAIR_BUFFER_CAPACITY: usize = 212992;

/// One end of a pair of connected unnamed sockets.
#[derive(Debug)]
struct AnonSocket {
pub struct AnonSocket {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed for

// We only support F_GETFL for socketpair and pipe.
let anonsocket_fd = fd.downcast::<AnonSocket>().ok_or_else(|| {
    err_unsup_format!("fcntl: only socketpair / pipe are supported for F_SETFL")
})?;

let [flag] = check_min_vararg_count(cmd_name, varargs)?;
let flag = this.read_scalar(flag)?.to_i32()?;

// FIXME: File access mode and file creation flags should be ignored.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the man page:

       F_SETFL (int)
              Set the file status flags to the value specified by arg.
              File access mode (O_RDONLY, O_WRONLY, O_RDWR) and file
              creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC)
              in arg are ignored.

There are quite a few file access mode and file creation flags, would prefer to open an issue for this and do it later.

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete labels Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support F_SETFL and F_GETFL
2 participants