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

Rework tail plateform module to tackle #2873 #3706

Merged
merged 1 commit into from
Aug 14, 2022

Conversation

anastygnome
Copy link
Contributor

@anastygnome anastygnome commented Jul 8, 2022

For the moment, these are just performance improvements (using the right name, not checking if the fd is negative as that can't be in rust, using the libc value)

The goal of this is to tackle #2873 more easily later on.

@anastygnome anastygnome closed this Jul 8, 2022
@anastygnome anastygnome reopened this Jul 8, 2022
@anastygnome anastygnome marked this pull request as draft July 8, 2022 15:29
@anastygnome anastygnome force-pushed the tail_refactor branch 11 times, most recently from cac7297 to 00dd325 Compare July 14, 2022 09:01
@anastygnome anastygnome force-pushed the tail_refactor branch 3 times, most recently from b8217a4 to a04b29e Compare July 18, 2022 11:29
@anastygnome
Copy link
Contributor Author

anastygnome commented Jul 18, 2022

@sylvestre trying to use isatty on stdin to do the stdin in is_pipe_or_fifo check results in a not implemented error on occasions. I had to use fstat is this a known phenomenon or not ? @tertsdiepraam

@anastygnome anastygnome marked this pull request as ready for review July 18, 2022 15:58
@tertsdiepraam
Copy link
Member

I haven't seen that before. Which isatty were you using? libc, nix or the atty crate?

@anastygnome
Copy link
Contributor Author

anastygnome commented Jul 19, 2022

The problem is at the libc level, I've tried all three

When piping in /dev/null (or stdin was closed), the problem occurred.

@tertsdiepraam
Copy link
Member

Interesting, I can't check for myself right now, but what was the exact error?

@anastygnome
Copy link
Contributor Author

anastygnome commented Jul 19, 2022

Interesting, I can't check for myself right now, but what was the exact error?

It panics with a not yet implemented, which I don't get as we're using it for other utils.

@sylvestre failures are unrelated, so we can merge this, I'll change it to use atty when this will be sorted out
or we can just leave this open

// IFCHR means the file (stdin) is a character input device, which is the case of a terminal.
// We just need to check if stdin is not a character device here, because we are not interested
// in the type of stdin itself.
fstat(libc::STDIN_FILENO).map_or(false, |file| file.st_mode as libc::mode_t & S_IFCHR == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please elaborate why you switched S_IFIFO and S_IFSOCK with S_IFCHR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when stdin is connected to a terminal, it symlinks to /dev/tty

which according to the tty manpage

/dev/tty is a character file with major number 5 and minor number 0, usually with mode 0666 and ownership root:tty.

So we just need to check if stdin is not describing (fd) a character file

@anastygnome
Copy link
Contributor Author

anastygnome commented Jul 19, 2022

Interesting, I can't check for myself right now, but what was the exact error?

@tertsdiepraam @jhscheer This error was due to the not inplemented handling of block devices, it turns out isatty mistakenly reports that stdin is a terminal because rust reopens stdin as /dev/null which is a block device

@jhscheer here's an in-depth post on how to implement this case, which I put here for reference.
https://superuser.com/a/1267407

@anastygnome anastygnome force-pushed the tail_refactor branch 2 times, most recently from ce65376 to d9290d3 Compare July 20, 2022 21:25
Optimize tail plateform module using the libc::stdin fd constant.

Commenting out `is_bad_symlink` as uutils#2873 will not be fixed for the time being.
@sylvestre sylvestre merged commit 38a64bd into uutils:main Aug 14, 2022
@anastygnome anastygnome deleted the tail_refactor branch February 16, 2023 21:24
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.

None yet

4 participants