kill: report write errors when listing signals instead of panicking#13300
Conversation
| if let Some(signal_name) = signal_list_name_by_value(signal_value) { | ||
| println!("{signal_value: >#2} {signal_name}"); | ||
| writeln!(out, "{signal_value: >#2} {signal_name}") | ||
| .map_err_context(|| translate!("kill-error-write-error"))?; |
There was a problem hiding this comment.
Please extract error from OS instead of using translate!, or error message would be incorrect.
There was a problem hiding this comment.
Done — added a stdout_write_error helper that interpolates the OS error via uucore::error::strip_errno(&err) into the message (ftl key is now write error: { $err }), matching the head idiom. Output is unchanged: kill: write error: No space left on device.
| } | ||
| } | ||
| out.flush() | ||
| .map_err_context(|| translate!("kill-error-write-error")) |
There was a problem hiding this comment.
Should be done after writeln!, not here.
There was a problem hiding this comment.
The OS-error extraction is now applied consistently with .map_err(stdout_write_error) on each writeln! as well as the final flush. I kept the BufWriter because head's line path does the same (BufWriter::with_capacity(BUF_SIZE, stdout.lock())) — buffering makes the failed write surface as one clean error at flush; writing unbuffered per line reintroduces the runtime's Error flushing stdout message on top of ours.
`kill -l`, `kill -l <sig>`, `kill --list`, and `kill --table` printed their output with `println!`, whose internal `io::stdout().write_fmt().unwrap()` aborts the process (SIGABRT, exit 134) when the stdout write fails — e.g. `kill -l TERM > /dev/full`. Write the signal listing to a buffered stdout and propagate the `io::Error` via `?`, so a failed write reports `kill: write error: <reason>` and exits 1, matching procps-ng `kill` (GNU coreutils ships no standalone `kill`). Add a `kill-error-write-error` locale key (en-US, fr-FR) and a regression test that lists signals to `/dev/full`.
10a6213 to
b873bc4
Compare
|
Thanks! |
Fixes #13297
kill -l,kill -l <sig>,kill --list, andkill --tableprint their outputwith
println!, whose internalio::stdout().write_fmt().unwrap()aborts theprocess (SIGABRT, exit 134) when the stdout write fails.
Adds a
kill-error-write-errorlocale key (en-US, fr-FR) and a regression testthat lists signals to
/dev/full.