Skip to content

Write to stdout and stderr without a lock for a single write - #408

Merged
sylvestre merged 1 commit into
mainfrom
io-drop-single-write-locks
Nov 8, 2026
Merged

sylvestre merged 1 commit into
mainfrom
io-drop-single-write-locks

Conversation

@pierre-warnier

Copy link
Copy Markdown
Collaborator

Fixes #406

Thanks @oech3 for the report.

A Stdout/Stderr write already takes the lock for itself, so locking around a single writeln! adds code and does nothing else. let _ = error handling is kept everywhere.

Changed (one write per lock):

  • src/bin/shadow-rs.rs: the argv[0] mismatch message (the example in the issue)
  • src/shadow-core/src/pam.rs: the PAM text-info message
  • src/shadow-core/src/tty.rs: the stderr prompt fallback. write_prompt makes one write_all, its flush is a no-op on unbuffered stderr, and the trailing newline is a separate single write
  • src/uu/passwd/src/passwd.rs: passwd: password changed.
  • src/uu/gpasswd/src/gpasswd.rs: the add/remove message. -a and -d are mutually exclusive, so the lock never covered more than one write

Kept (the lock covers several writes): print_multicall_help and print_available_utils in shadow-rs.rs, chage interactive prompts and -l, chsh -l, passwd -S/-Sa, useradd -D, the vipw notice, and the completions generator.

Size of the multicall release binary (cargo build --release --features pam, Debian container): 2,270,440 -> 2,268,072 bytes (-2,368).

Checked in the Debian container: cargo test --workspace (1065 passed, 0 failed), cargo clippy --workspace --all-targets -- -D warnings with and without --features pam, and cargo fmt --all --check.

Reviews welcome. Without objection, this will be merged after 7 days.

A Stdout or Stderr write already takes the lock for itself, so locking
around one writeln! only adds code. The locks that cover several writes
stay, so that their output is not interleaved.

Fixes #406
@sylvestre
sylvestre merged commit 255f0a4 into main Nov 8, 2026
13 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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.

.lock() is not usefu for single writeln! call

2 participants