Skip to content

Add file mode#9

Merged
propertone merged 1 commit intodeshaw:mainfrom
AdvH039:file-mode
Nov 5, 2025
Merged

Add file mode#9
propertone merged 1 commit intodeshaw:mainfrom
AdvH039:file-mode

Conversation

@AdvH039
Copy link
Copy Markdown
Contributor

@AdvH039 AdvH039 commented Oct 28, 2025

Fixes #8

image

@AdvH039
Copy link
Copy Markdown
Contributor Author

AdvH039 commented Oct 28, 2025

@propertone

Copy link
Copy Markdown
Member

@propertone propertone left a comment

Choose a reason for hiding this comment

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

  • This only handles mode for pipes - we want to handle modes for all FDs
  • Please format with cargo format
  • There is a missing column heading for Mode

src/main.rs Outdated
// Query file descriptors only if necessary (not for --exe/--root/--cwd)
if fd_filter.query_fds() {
for fd in &process.fds {
let mode = if fd.mode() & READ == READ { 'r' } else { 'w' };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mode can also be rw

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Make mode String type then ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes

.then_some(FDTarget::Path(path_buf.clone())),
process::FDTarget::Pipe(inode) => fd_filter.query_pipe().then(|| {
let mode = if fd.mode() & READ == READ { 'r' } else { 'w' };
FDTarget::Pipe(PipeInfo {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's also remove mode from PipeInfo as it's redundant with the fd mode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Idk if we can do this because we're using mode for filtering while doing a lookup, see here

Copy link
Copy Markdown
Member

@propertone propertone Oct 31, 2025

Choose a reason for hiding this comment

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

That refers to PipeTarget not PipeInfo, but we're also using mode in fmt::Display for FDTarget, so that would be more complicated to refactor. So fine to leave it as is for now.

@AdvH039
Copy link
Copy Markdown
Contributor Author

AdvH039 commented Nov 1, 2025

@propertone I made some logical changes in the code to support "rw and to support mode in char type. Might be a little hacky.

process::FDTarget::Pipe(inode) => fd_filter.query_pipe().then(|| {
let mode = if fd.mode() & READ == READ { 'r' } else { 'w' };
let pipe_mode = mode.chars().next().unwrap();
FDTarget::Pipe(PipeInfo {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why don't you make PipeInfo.mode a string as well to simplify this?

Copy link
Copy Markdown
Contributor Author

@AdvH039 AdvH039 Nov 2, 2025

Choose a reason for hiding this comment

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

@propertone
It was better to make the changes like this otherwise we have to refactor many things.

Even if I change Pipeinfo.mode mode still needs to be used as a char type in lookup_pipe2pd, because PipeTarget also uses char type mode.

My humble suggestion is (if we want to refactor) we scrap PipeTarget.mode and convert mode to String everywhere else.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, let's do that

src/main.rs Outdated
Comment on lines +899 to +905
let mode = if fd.mode() & READ == READ {
String::from("r")
} else if fd.mode() & WRITE == WRITE {
String::from("w")
} else {
String::from("rw")
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This logic is wrong - the rw case is never reached

src/main.rs Outdated
targets.retain(|x| !(x.pid == pid && x.fd == fd));
// exclude fds with the same mode
targets.retain(|x| x.mode != mode);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove extra newline

src/main.rs Outdated
Comment on lines +1448 to +1451
let mode_str = match &fd_entry.mode {
Some(mode) => mode,
None => &String::new(),
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can instead do:

Suggested change
let mode_str = match &fd_entry.mode {
Some(mode) => mode,
None => &String::new(),
};
let mode_str = fd_entry.mode.clone().unwrap_or_default();

@AdvH039 AdvH039 force-pushed the file-mode branch 2 times, most recently from 20a50f4 to dcffe02 Compare November 3, 2025 17:24
@AdvH039 AdvH039 requested a review from propertone November 3, 2025 17:26
src/main.rs Outdated
.join(",");

format!("pipe {direction} {joined_endpoints}")
format!("pipe {joined_endpoints}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add an arrow here. The direction is now redundant with the mode, but without the arrow, it's confusing to know what pipe [12] means, for example.

Suggested change
format!("pipe {joined_endpoints}")
format!("pipe -> {joined_endpoints}")

@propertone
Copy link
Copy Markdown
Member

Oh can you also please sign the CLA here: https://www.deshaw.com/oss/cla

Signed-off-by: Adv <adhvaithhundi.221ds003@nitk.edu.in>
@AdvH039
Copy link
Copy Markdown
Contributor Author

AdvH039 commented Nov 4, 2025

Thanks!! Please let me know if there are more issues I can work on.

Copy link
Copy Markdown
Member

@propertone propertone left a comment

Choose a reason for hiding this comment

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

Looks good - thank you for the contribution! I will merge & deploy later this week.

@propertone propertone merged commit 6bba3cb into deshaw:main Nov 5, 2025
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.

Display file mode

2 participants