tty: add missing newline to output#10252
Conversation
| @@ -37,7 +37,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { | |||
| let name = nix::unistd::ttyname(std::io::stdin()); | |||
|
|
|||
| let write_result = match name { | |||
| Ok(name) => stdout.write_all_os(name.as_os_str()), | |||
| Ok(name) => { | |||
| stdout.write_all_os(name.as_os_str())?; | |||
There was a problem hiding this comment.
(/bin/tty >&- 2>/dev/null); echo $?
This command shows what happens when theres an error in writing to stdout, the error code that GNU is expecting is 3, but by adding that ? it will make it handled and return a 1. You can get around this by doing:
Ok(name) => stdout
.write_all_os(name.as_os_str())
.and_then(|_| writeln!(stdout)),
There was a problem hiding this comment.
target/debug/tty > /dev/full silently returns 3. But GNU have tty: write error: No space left on device.
|
@ChrisDryden can you check now, sir? thank you! |
|
Would you add test to check newline (and exit code of |
|
GNU testsuite comparison: |
|
@oech3 Hi, sir! Please check now and let me know. Thank you! Have a nice weekend. :) |
| if write_result.is_err() || stdout.flush().is_err() { | ||
|
|
||
| if let Err(e) = write_result { | ||
| eprintln!("tty: write error: {}", e); |
There was a problem hiding this comment.
Why did you change this?
There was a problem hiding this comment.
@ChrisDryden I removed it because I thought it was redundant (flush was already called in line 37), but I've now restored it to match the original pattern.
There was a problem hiding this comment.
I guess we can extract it from OS provided err message.
(Also please cargo fmt)
|
I changed it to print the error message before exiting (as requested in the previous feedback about matching GNU tty's 'write error' output). However, I notice I removed the separate |
Merging this PR will not alter performance
Comparing Footnotes
|
|
many jobs are failing |
I ran tests locally, and everything worked for me. I don't know why these specific jobs keep failing when I fixed the new line issue. There is no other workaround that I know of, GNU panics if something is wrong but it didn't produce an output so I made custom test like OP mentioned and I don't understand why is it failing now.. Can you suggest fix to this? |
|
I guess you wrote the test writing to I guess it is generic test framefork's issue. |
Thank you, sir. If it's okay on your end, can we close this issue for now and this other issue can be a separate PR? |
|
Please keep open and add |
Understood, sir. Will follow your advice, thank you for the suggestion. |
2c92d38 to
b88708c
Compare
|
@oech3 done, sir. |
|
GNU testsuite comparison: |
|
Some jobs are failing |
|
conflicting. |
What do you suggest to fix this issue? Thank you in advance, sir. 🙏 Best, |
|
Would you rebase agaist |
Yes, sir. Give me some time I will finish today. 🫡 |
|
Do you still want to do this? |
I will clean up today. Thanks! 🙏 will work on it now. After I finish this one, could you please add me to other issues I wanna practice and improve my Rust skills. 🙂 I will check what is the issue, CI/CD tests I think crashing. |
I apologize I was away, I had some private stuff to finish. |
b88708c to
de6e612
Compare
I've rebased against main and resolved all conflicts. The performance regression flagged by CodSpeed has been fixed by combining the tty path and newline into a single buffer before writing: rust |
|
GNU testsuite comparison: |
Fixes #10239