Adapt UserService to trixie, make failure output work
This commit is contained in:
parent
d01c3f84cc
commit
4cbcb4ddd5
1 changed files with 9 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::async_utils::sleep;
|
use crate::async_utils::sleep;
|
||||||
use crate::command_runner::{CommandRunner, SetuidCommandRunner};
|
use crate::command_runner::{CommandRunner, StdCommandRunner, SetuidCommandRunner};
|
||||||
use crate::symbols::Symbol;
|
use crate::symbols::Symbol;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
@ -12,6 +12,7 @@ pub struct UserService<'a, S: AsRef<Path>, U: AsRef<str>> {
|
||||||
socket_path: S,
|
socket_path: S,
|
||||||
service_name: &'a str,
|
service_name: &'a str,
|
||||||
command_runner: SetuidCommandRunner<U>,
|
command_runner: SetuidCommandRunner<U>,
|
||||||
|
root_command_runner: StdCommandRunner,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: AsRef<Path>, U: AsRef<str>> UserService<'static, S, U> {
|
impl<S: AsRef<Path>, U: AsRef<str>> UserService<'static, S, U> {
|
||||||
|
|
@ -20,13 +21,14 @@ impl<S: AsRef<Path>, U: AsRef<str>> UserService<'static, S, U> {
|
||||||
socket_path,
|
socket_path,
|
||||||
service_name,
|
service_name,
|
||||||
command_runner: SetuidCommandRunner::new(user_name),
|
command_runner: SetuidCommandRunner::new(user_name),
|
||||||
|
root_command_runner: StdCommandRunner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: AsRef<Path>, U: AsRef<str>> UserService<'_, S, U> {
|
impl<S: AsRef<Path>, U: AsRef<str>> UserService<'_, S, U> {
|
||||||
async fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result<String, Box<dyn Error>> {
|
async fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result<String, Box<dyn Error>> {
|
||||||
let mut tries = 5;
|
let mut tries = 10;
|
||||||
loop {
|
loop {
|
||||||
let result = self.command_runner.run_with_args("systemctl", args).await?;
|
let result = self.command_runner.run_with_args("systemctl", args).await?;
|
||||||
if result.status.success() {
|
if result.status.success() {
|
||||||
|
|
@ -34,14 +36,15 @@ impl<S: AsRef<Path>, U: AsRef<str>> UserService<'_, S, U> {
|
||||||
}
|
}
|
||||||
let raw_stderr = std::str::from_utf8(&result.stderr)?;
|
let raw_stderr = std::str::from_utf8(&result.stderr)?;
|
||||||
let stderr = raw_stderr.trim_end();
|
let stderr = raw_stderr.trim_end();
|
||||||
if stderr != "Failed to connect to bus: No such file or directory" {
|
if stderr != "Failed to connect to bus: No such file or directory" &&
|
||||||
|
stderr != "Failed to connect to user scope bus via local transport: No such file or directory" {
|
||||||
return Err(stderr.into());
|
return Err(stderr.into());
|
||||||
}
|
}
|
||||||
tries -= 1;
|
tries -= 1;
|
||||||
if tries == 0 {
|
if tries == 0 {
|
||||||
return Err("Gave up waiting for dbus to appear".to_string().into());
|
return Err("Gave up waiting for dbus to appear".to_string().into());
|
||||||
}
|
}
|
||||||
sleep(Duration::from_millis(500)).await;
|
sleep(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,10 +66,10 @@ impl<S: AsRef<Path>, U: AsRef<str>> UserService<'_, S, U> {
|
||||||
return Err(
|
return Err(
|
||||||
std::str::from_utf8(
|
std::str::from_utf8(
|
||||||
&self
|
&self
|
||||||
.command_runner
|
.root_command_runner
|
||||||
.get_output(
|
.get_output(
|
||||||
"journalctl",
|
"journalctl",
|
||||||
args!["--user", format!("--user-unit={}", self.service_name)],
|
args![ /*"--user", format!("--user-unit={}", self.service_name)*/ ],
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
)?
|
)?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue