bugfix: get pid
parent
0f5ef66465
commit
5fa3d2fec8
|
|
@ -1,21 +1,27 @@
|
|||
use crate::options::structs::CustomError;
|
||||
use log::{error, warn};
|
||||
use std::io;
|
||||
use std::process::{Command, Output};
|
||||
use std::sync::Arc;
|
||||
use tokio::time::Duration;
|
||||
|
||||
pub async fn get_pid(name: &str) -> Result<Output, std::io::Error> {
|
||||
let name = Arc::new(name.to_string());
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let res= tokio::task::spawn_blocking(move || {
|
||||
Command::new("pidof")
|
||||
.arg(&*name)
|
||||
.output()
|
||||
// .unwrap_or_else(|_| {
|
||||
// error!("Failed to execute command 'pidof'");
|
||||
// std::process::exit(101);
|
||||
// })
|
||||
})
|
||||
.await?
|
||||
.await?;
|
||||
if let Ok(output) = res {
|
||||
if output.stderr.is_empty() && output.stdout.is_empty() {
|
||||
return Err(io::ErrorKind::NotFound.into());
|
||||
} else {
|
||||
Ok(output)
|
||||
}
|
||||
} else {
|
||||
return Err(io::ErrorKind::NotFound.into());
|
||||
}
|
||||
}
|
||||
// ! can be with bug !!!
|
||||
// * APPROVED
|
||||
|
|
@ -154,8 +160,10 @@ mod process_unittests {
|
|||
async fn pidof_active_process() {
|
||||
assert!(get_pid("systemd").await.is_ok());
|
||||
}
|
||||
|
||||
// broken mechanism need to check
|
||||
#[tokio::test]
|
||||
async fn pidof_disabled_process() {
|
||||
assert!(get_pid("invalid-process-name").await.is_ok());
|
||||
assert!(get_pid("invalid-process-name").await.is_err());
|
||||
}
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ use runner_rs::*;
|
|||
#[test]
|
||||
fn test() {
|
||||
assert_eq!(2, 2);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue