8000 dd: interpret Stdin as File to seek it by ArtemSkrebkov · Pull Request #3662 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Closed

Conversation

ArtemSkrebkov
Copy link
@ArtemSkrebkov ArtemSkrebkov commented Jun 22, 2022

It fixes a test including dd from tests/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 interpret stdin as File. More details in #3008 (comment)

8000

@sylvestre
Copy link
Contributor

Could you please add a test?
We have plenty of tests in tests/by-util/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())
Copy link

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.

Copy link
Author

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.

@ArtemSkrebkov ArtemSkrebkov force-pushed the stop_dd_consume_whole_stdin branch 2 times, most recently from 702588c to d5be396 Compare June 23, 2022 18:47
@@ -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() {
Copy link
Author
@ArtemSkrebkov ArtemSkrebkov Jun 23, 2022

Choose a reason for hiding this comment

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

@sylvestre

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())
Copy link
Author

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.

@sylvestre
Copy link
Contributor

Could you please fix that issue? thanks


error[E0425]: cannot find value `i` in this scope
  --> src\uu\dd\src/dd.rs:93:12
   |
93 |         Ok(i)
   |            ^ not found in this scope

@ArtemSkrebkov
Copy link
Author

Could you please fix that issue? thanks


error[E0425]: cannot find value `i` in this scope
  --> src\uu\dd\src/dd.rs:93:12
   |
93 |         Ok(i)
   |            ^ not found in this scope

Fixed.

@sylvestre
Copy link
Contributor

a bunch of tests are broken, could you please have a look? thanks

@ArtemSkrebkov
Copy link
Author

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.

@sylvestre sylvestre force-pushed the stop_dd_consume_whole_stdin branch 2 times, most recently from 4b406a2 to 34956b5 Compare July 6, 2022 07:42
@sylvestre sylvestre force-pushed the stop_dd_consume_whole_stdin branch 2 times, most recently from b30d43b to 12a7123 Compare July 11, 2022 20:59
@sylvestre sylvestre force-pushed the stop_dd_consume_whole_stdin branch from 12a7123 to 44cbf17 Compare August 2, 2022 20:22
Copy link
Contributor
@sylvestre sylvestre left a 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

@sylvestre
Copy link
Contributor

@ArtemSkrebkov ping?

@ArtemSkrebkov
Copy link
Author

No luck since the last debugging attempt.
I believe, we probably can close until better times.

@tertsdiepraam
Copy link
Member

Closing until better times :)

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.

4 participants
0