wip: replace dyn Error with concrete
This commit is contained in:
@@ -6,21 +6,21 @@ use tokio::io::Result as tokio_result;
|
||||
use tokio::time::sleep;
|
||||
use std::time::Duration;
|
||||
use std::process::ExitStatus;
|
||||
use std::error;
|
||||
use nix::sys::signal::{kill, Signal};
|
||||
use nix::errno::Errno;
|
||||
use nix::unistd::Pid;
|
||||
use anyhow::Context;
|
||||
use crate::init::config;
|
||||
use crate::init::error::{NoShellAvailableError, WingmateInitError};
|
||||
use crate::init::error::WingmateInitError;
|
||||
|
||||
|
||||
pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send + Sync>>>, cfg: &config::Config, cancel: CancellationToken)
|
||||
-> Result<(), Box<dyn error::Error>> {
|
||||
pub fn start_services(ts: &mut JoinSet<Result<(), WingmateInitError>>, cfg: &config::Config, cancel: CancellationToken)
|
||||
-> Result<(), WingmateInitError> {
|
||||
|
||||
for svc_ in cfg.get_service_iter() {
|
||||
let mut shell: String = String::new();
|
||||
if let config::Command::ShellPrefixed(_) = svc_ {
|
||||
shell = cfg.get_shell().ok_or::<Box<dyn error::Error>>(NoShellAvailableError.into())?;
|
||||
shell = cfg.get_shell().ok_or::<WingmateInitError>(WingmateInitError::NoShellAvailable)?;
|
||||
}
|
||||
let svc = svc_.clone();
|
||||
let cancel = cancel.clone();
|
||||
@@ -32,7 +32,7 @@ pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send +
|
||||
config::Command::Direct(c) => {
|
||||
let exp_str = c.clone();
|
||||
child = Command::new(c).spawn().map_err(|e| {
|
||||
Box::new(WingmateInitError::SpawnError { source: e, message: exp_str })
|
||||
WingmateInitError::SpawnError { source: e, message: exp_str }
|
||||
})?;
|
||||
},
|
||||
config::Command::ShellPrefixed(s) => {
|
||||
@@ -40,7 +40,7 @@ pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send +
|
||||
let exp_str = s.clone();
|
||||
let exp_shell = shell.clone();
|
||||
child = Command::new(shell).arg(s).spawn().map_err(|e| {
|
||||
Box::new(WingmateInitError::SpawnError { source: e, message: format!("{} {}", exp_shell, exp_str) })
|
||||
WingmateInitError::SpawnError { source: e, message: format!("{} {}", exp_shell, exp_str) }
|
||||
})?;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send +
|
||||
},
|
||||
result = child.wait() => {
|
||||
if let Err(e) = result_match(result) {
|
||||
return Err(e);
|
||||
return Err(WingmateInitError::ChildExit { source: e });
|
||||
}
|
||||
break 'autorestart;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send +
|
||||
},
|
||||
Err(e) => {
|
||||
if e != Errno::ESRCH {
|
||||
return Err(e.into());
|
||||
return Err(WingmateInitError::ChildNotFound);
|
||||
} else {
|
||||
break 'autorestart;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send +
|
||||
},
|
||||
result = child.wait() => {
|
||||
if let Err(e) = result_match(result) {
|
||||
return Err(e);
|
||||
return Err(WingmateInitError::ChildExit { source: e });
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -91,14 +91,14 @@ pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send +
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn result_match(result: tokio_result<ExitStatus>) -> Result<(), Box<dyn error::Error + Send + Sync>> {
|
||||
fn result_match(result: tokio_result<ExitStatus>) -> Result<(), anyhow::Error> {
|
||||
if let Err(e) = result {
|
||||
if let Some(eos) = e.raw_os_error() {
|
||||
if eos != nix::Error::ECHILD as i32 {
|
||||
return Err(e.into());
|
||||
return Err(e).context("unexpected child exit status");
|
||||
}
|
||||
} else {
|
||||
return Err(e.into());
|
||||
return Err(e).context("unexpected child error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user