Skip to content

Commit

Permalink
Use write_all() instead of write()
Browse files Browse the repository at this point in the history
write() is allowed to write only partial data. Good luck debugging why
some part of the log message is missing. This commit changes the logging
to use write_all() instead, which ensures everything is written.

This might end up doing multiple writes to /dev/kmsg, which would turn
into multiple log records. I think that is still better than silently
discarding some data.

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information
psychon committed Nov 18, 2023
1 parent 602529a commit 5a0e4c0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn log_impl(msg: Arguments<'_>) {
match OpenOptions::new().write(true).open("/dev/kmsg") {
Ok(mut file) => {
msg.push('\n');
file.write(msg.as_bytes()).ok();
file.write_all(msg.as_bytes()).ok();
}
Err(_) => {
println!(
Expand Down

0 comments on commit 5a0e4c0

Please sign in to comment.