Don't double fork command when running as systemd service since it's not necessary
This commit is contained in:
parent
69a2b9be16
commit
c79d031fe7
1 changed files with 33 additions and 30 deletions
|
@ -477,14 +477,7 @@ impl EventReader {
|
||||||
};
|
};
|
||||||
if let Some(user) = user {
|
if let Some(user) = user {
|
||||||
for command in command_list {
|
for command in command_list {
|
||||||
let cmd = if running_as_root {
|
if running_as_root {
|
||||||
let cmd = format!("runuser {} -c '{}'", user, command);
|
|
||||||
cmd
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let cmd = format!("systemd-run --user -M {}@ {}", user, command);
|
|
||||||
cmd
|
|
||||||
};
|
|
||||||
match fork() {
|
match fork() {
|
||||||
Ok(Fork::Child) => {
|
Ok(Fork::Child) => {
|
||||||
match fork() {
|
match fork() {
|
||||||
|
@ -492,7 +485,7 @@ impl EventReader {
|
||||||
setsid().unwrap();
|
setsid().unwrap();
|
||||||
Command::new("sh")
|
Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(cmd)
|
.arg(format!("runuser {} -c '{}'", user, command))
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
|
@ -507,6 +500,16 @@ impl EventReader {
|
||||||
Ok(Fork::Parent(_)) => (),
|
Ok(Fork::Parent(_)) => (),
|
||||||
Err(_) => std::process::exit(1),
|
Err(_) => std::process::exit(1),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(format!("systemd-run --user -M {}@ {}", user, command))
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue