-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: fix GNU test 'dd/skip-seek-past-dev' #4527
Conversation
Because there are currently some attempts to work around the missing Rust feature to seek stdin/stdout/stderr, I found this open issue (actually a comment for another workaround implementation: rust-lang/rust#72802 (comment)). I am currently not sure why skipping a non-seekable stdin does not return exit code 1: |
GNU testsuite comparison:
|
@jfinkels: your implementation helps to fix my targeted problem. I had a similar implementation as you but observed a couple of illegal seeks and broken pipes. I think as long as there is no "safe Rust way" to do a seek on stdin/stdout, we should do some UNIX-specific workarounds to avoid the errors. I guess the correct way would be to find out if stdin is something "seekable" (e.g. a regular file), which could by done by using fstat on the fd of the stream, or using stat on /dev/std{in,out}. I guess a stat would also help to solve my problem. My problem in short: if stdin or stdout has a known size, and we want so skip/seek past the size, a special error message is shown. I tried to avoid to add too much UNIX-specific stuff, but I guess these problems/features are very UNIX-specific, therefore it should be ok. |
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.
I tried to replicate the error messages you test for with GNU and I just get the error messages that we already have. So, I'm not sure this change makes sense? You mentioned some GNU test, which one is that? I'm using GNU coreutils 9.1 if that matters.
tests/by-util/test_dd.rs
Outdated
.set_stdout(File::open(at.plus("f")).unwrap()) | ||
.args(&["bs=1", "seek=10000000000000000000", "count=0", "status=noxfer"]) | ||
.run() | ||
.stderr_is("dd: 'standard output': cannot seek: Invalid argument\n0+0 records in\n0+0 records out\n") |
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.
For this case I get from GNU:
dd: invalid number: ‘10000000000000000000’: Value too large for defined data type
Which is more informative and has nothing to do with the length of the target file.
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.
Hey, sorry was a little bit busy last week. The mentioned test is a "root test" and can be found here: tests/dd/skip-seek-past-dev.sh
. It takes a block device as stdin/-out and therefore requires root. I try to "simulate" this by using a normal file, which unfortunately behaves not quite similar.
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.
So the error message should come when the position to skip to is "past" the device. My idea was to take a "high enough number" to skip past "every" device, but it seem to work not always as expected.
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.
I guess I will adapt my implementation to be more specific and only work with block devices.
tests/by-util/test_dd.rs
Outdated
.set_stdin(File::open(at.plus("f")).unwrap()) | ||
.args(&["bs=1", "skip=5", "count=0", "status=noxfer"]) | ||
.run() | ||
.stderr_is("dd: 'standard input': cannot skip: Invalid argument\n0+0 records in\n0+0 records out\n") |
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.
For this case I get:
dd: 'standard input': cannot skip to specified offset
GNU testsuite comparison:
|
Sorry but Clippy is complaining about:
|
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.
ping ?
Heyho, sorry for the late response. I will look into run_ucmd_as_root() to try to set up a test working with a block device. Otherwise the implementation might currently not make really sense. |
c7fdae1
to
45a328e
Compare
This enables to give path to files (as str) which are then used as either stdin or stdout.
These tests try to read or write past a block device, where the block device is either given as stdin or stdout. It requires access to the block device, and therefore is executed as root. For now, it is assumed that a block device "/dev/sda1" with a size smaller than 10000000000000000 exists.
45a328e
to
17f4d17
Compare
seems that it is fixed :) it was failing with but it now passes:
|
The GNU test suggests that GNU's variant is trying to seek stdin/stdout s.t. it can abort early if the respective fd is seekable and does not have enough length to do the requested skip/seek.
Draft for now to signalize that I am working on it.
There are some small open points, e.g. recognize this better:
vs
and obviously add tests :)