-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
dd: interpret Stdin as File to seek it #3662
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
dd: interpret Stdin as File to seek it #3662
Conversation
Could you please add a test? |
#[cfg(any(target_family = "unix", target_family = "wasi"))] | ||
let mut seekable_src = unsafe { | ||
use std::os::unix::io::{AsRawFd, FromRawFd}; | ||
std::fs::File::from_raw_fd(std::io::stdin().as_raw_fd()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(driveby comment, I don't have much context) Unless seekable_src
is fed to mem::forget
at some point this likely is a bad idea because File::drop
will then close the stdin file descriptor. You should either try_clone
(dup) it or wrap this in a ManuallyDrop
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Will fix it once I figure out why the current solution works if I use dd
in command line and does not work if I run tests from tests/by-utils
.
702588c
to
d5be396
Compare
@@ -1186,3 +1186,16 @@ fn test_final_stats_si_iec() { | |||
let s = result.stderr_str(); | |||
assert!(s.starts_with("2+0 records in\n2+0 records out\n1024 bytes (1 KB, 1024 B) copied,")); | |||
} | |||
|
|||
#[test] | |||
fn test_partial_skip_stdin() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... I added the test, but it does not work as expected and fails with Illegal seek
. As any other test which tries to seek stdin
.
However, it can work outside the test system (for example, if I run tests/misc/head-c.sh
)
I am confused why it does not work in the test system. Let me know if there are any insights on this.
#[cfg(any(target_family = "unix", target_family = "wasi"))] | ||
let mut seekable_src = unsafe { | ||
use std::os::unix::io::{AsRawFd, FromRawFd}; | ||
std::fs::File::from_raw_fd(std::io::stdin().as_raw_fd()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Will fix it once I figure out why the current solution works if I use dd
in command line and does not work if I run tests from tests/by-utils
.
Could you please fix that issue? thanks
|
Fixed. |
a bunch of tests are broken, could you please have a look? thanks |
Yeah. Right. I described why the tests fail in the previous comment. I will try to debug it more, but if there is someone, who is more proficient in the project, I can chat with, that would probably help to fix the issue faster. |
4b406a2
to
34956b5
Compare
b30d43b
to
12a7123
Compare
12a7123
to
44cbf17
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fails to build on a bunch of jobs
@ArtemSkrebkov ping? |
No luck since the last debugging attempt. |
Closing until better times :) |
It fixes a test including
dd
fromtests/misc/head-c.sh
.Corresponding issue: #3008
I expected that
tests/dd/not-rewound.sh
would also be fixed, but unfortunately, it is not the case. It seems that #3626 is still relevant.Background
An attempt to skip bytes by
read_skip
leads to consuming all stdin by a rust application. Another approach to tackle this is to interpretstdin
asFile
. More details in #3008 (comment)