Update sysinfo crate to 0.29.6 (#685)

* update sysinfo package to fix build error

* update tor process sysinfo calls to new api

* update deprecation warnings

* small logic cleanup

* tweak to retrigger CI

* new_all() not required

* give longer for test thread to stop to hopefully alleviate inconsistent CI failures
This commit is contained in:
Yeastplume 2023-07-26 12:59:36 +01:00 committed by GitHub
parent 0b491fea0f
commit c0b7c68b13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 697 additions and 649 deletions

1312
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -508,8 +508,8 @@ where
.1 .1
.into_iter() .into_iter()
.map(|mut t| { .map(|mut t| {
t.confirmation_ts = Some(Utc.ymd(2019, 1, 15).and_hms(16, 1, 26)); t.confirmation_ts = Some(Utc.with_ymd_and_hms(2019, 1, 15, 16, 1, 26).unwrap());
t.creation_ts = Utc.ymd(2019, 1, 15).and_hms(16, 1, 26); t.creation_ts = Utc.with_ymd_and_hms(2019, 1, 15, 16, 1, 26).unwrap();
t t
}) })
.collect(); .collect();

View file

@ -133,7 +133,7 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// let logging finish // let logging finish
stopper.store(false, Ordering::Relaxed); stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200)); thread::sleep(Duration::from_millis(1000));
Ok(()) Ok(())
} }

View file

@ -32,7 +32,7 @@ x25519-dalek = "0.6"
data-encoding = "2" data-encoding = "2"
regex = "1.3" regex = "1.3"
timer = "0.2" timer = "0.2"
sysinfo = "0.14" sysinfo = "0.29"
base64 = "0.12.0" base64 = "0.12.0"
url = "2.1" url = "2.1"

View file

@ -58,7 +58,7 @@ use std::path::{Path, MAIN_SEPARATOR};
use std::process::{Child, ChildStdout, Command, Stdio}; use std::process::{Child, ChildStdout, Command, Stdio};
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::thread; use std::thread;
use sysinfo::{Process, ProcessExt, Signal}; use sysinfo::{Process, ProcessExt, System, SystemExt};
#[cfg(windows)] #[cfg(windows)]
const TOR_EXE_NAME: &str = "tor.exe"; const TOR_EXE_NAME: &str = "tor.exe";
@ -78,16 +78,6 @@ pub enum Error {
Timeout, Timeout,
} }
#[cfg(windows)]
fn get_process(pid: i32) -> Process {
Process::new(pid as usize, None, 0)
}
#[cfg(not(windows))]
fn get_process(pid: i32) -> Process {
Process::new(pid, None, 0)
}
pub struct TorProcess { pub struct TorProcess {
tor_cmd: String, tor_cmd: String,
args: Vec<String>, args: Vec<String>,
@ -97,6 +87,7 @@ pub struct TorProcess {
working_dir: Option<String>, working_dir: Option<String>,
pub stdout: Option<BufReader<ChildStdout>>, pub stdout: Option<BufReader<ChildStdout>>,
pub process: Option<Child>, pub process: Option<Child>,
sys: System,
} }
impl TorProcess { impl TorProcess {
@ -110,9 +101,15 @@ impl TorProcess {
working_dir: None, working_dir: None,
stdout: None, stdout: None,
process: None, process: None,
sys: System::new(),
} }
} }
fn get_process(&mut self, pid: i32) -> Option<&Process> {
self.sys.refresh_all();
self.sys.process((pid as usize).into())
}
pub fn tor_cmd(&mut self, tor_cmd: &str) -> &mut Self { pub fn tor_cmd(&mut self, tor_cmd: &str) -> &mut Self {
self.tor_cmd = tor_cmd.to_string(); self.tor_cmd = tor_cmd.to_string();
self self
@ -164,8 +161,9 @@ impl TorProcess {
let pid = pid let pid = pid
.parse::<i32>() .parse::<i32>()
.map_err(|err| Error::PID(format!("{:?}", err)))?; .map_err(|err| Error::PID(format!("{:?}", err)))?;
let process = get_process(pid); if let Some(p) = self.get_process(pid) {
let _ = process.kill(Signal::Kill); let _ = p.kill();
}
} }
} }
if let Some(ref torrc_path) = self.torrc_path { if let Some(ref torrc_path) = self.torrc_path {
@ -183,7 +181,7 @@ impl TorProcess {
})?; })?;
if let Some(ref d) = self.working_dir { if let Some(ref d) = self.working_dir {
// split out the process id, so if we don't exit cleanly // Split out the process id, so if we don't exit cleanly
// we can take it down on the next run // we can take it down on the next run
let pid_file_name = format!("{}{}pid", d, MAIN_SEPARATOR); let pid_file_name = format!("{}{}pid", d, MAIN_SEPARATOR);
let mut file = File::create(pid_file_name).map_err(Error::IO)?; let mut file = File::create(pid_file_name).map_err(Error::IO)?;