Skip to content

Commit 3fbfad0

Browse files
committed
Fix deadlock for 'list-units()' with '--all' argument
Use 'wait_with_output()' instead of 'wait()' fixes a deadlock, which occurs on my machine with the '--all' argument and no '--state' filters.
1 parent d6fdc0b commit 3fbfad0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ impl SystemCtl {
5757
args: S,
5858
) -> std::io::Result<String> {
5959
let mut child = self.spawn_child(args)?;
60-
match child.wait()?.code() {
60+
let output = child.wait_with_output()?;
61+
match output.status.code() {
6162
Some(0) => {}, // success
6263
Some(1) => {}, // success -> Ok(Unit not found)
6364
Some(3) => {}, // success -> Ok(unit is inactive and/or dead)
@@ -83,8 +84,8 @@ impl SystemCtl {
8384
},
8485
}
8586

86-
let mut stdout: Vec<u8> = Vec::new();
87-
let size = child.stdout.unwrap().read_to_end(&mut stdout)?;
87+
let mut stdout: Vec<u8> = output.stdout;
88+
let size = stdout.len();
8889

8990
if size > 0 {
9091
if let Ok(s) = String::from_utf8(stdout) {

0 commit comments

Comments
 (0)