cli: cleanup some process querying code (#170306)

Avoid pulling system info we don't have to.

Minor cleanups while working on https://github.com/microsoft/vscode/pull/170305
This commit is contained in:
Connor Peet 2022-12-30 12:55:57 -08:00 committed by GitHub
parent 6106980525
commit b5ad508dfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 29 deletions

View file

@ -240,15 +240,6 @@ pub enum AnyCodeServer {
Port(PortCodeServer),
}
// impl AnyCodeServer {
// pub fn origin(&mut self) -> &mut CodeServerOrigin {
// match self {
// AnyCodeServer::Socket(p) => &mut p.origin,
// AnyCodeServer::Port(p) => &mut p.origin,
// }
// }
// }
pub enum CodeServerOrigin {
/// A new code server, that opens the barrier when it exits.
New(Box<Child>),

View file

@ -94,9 +94,7 @@ impl HandlerContext {
async fn dispose(self) {
let bridges: ServerBridgeList = {
let mut lock = self.server_bridges.lock().await;
let bridges = lock.take();
*lock = None;
bridges
lock.take()
};
if let Some(b) = bridges {

View file

@ -7,35 +7,30 @@ use std::path::Path;
use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt};
pub fn process_at_path_exists(pid: u32, name: &Path) -> bool {
// TODO https://docs.rs/sysinfo/latest/sysinfo/index.html#usage
let mut sys = System::new_all();
sys.refresh_processes();
let mut sys = System::new();
let pid = Pid::from_u32(pid);
if !sys.refresh_process(pid) {
return false;
}
let name_str = format!("{}", name.display());
match sys.process(Pid::from_u32(pid)) {
Some(process) => {
for cmd in process.cmd() {
if cmd.contains(&name_str) {
return true;
}
if let Some(process) = sys.process(pid) {
for cmd in process.cmd() {
if cmd.contains(&name_str) {
return true;
}
}
None => {
return false;
}
}
false
}
pub fn process_exists(pid: u32) -> bool {
let mut sys = System::new_all();
sys.refresh_processes();
sys.process(Pid::from_u32(pid)).is_some()
let mut sys = System::new();
sys.refresh_process(Pid::from_u32(pid))
}
pub fn find_running_process(name: &Path) -> Option<u32> {
// TODO https://docs.rs/sysinfo/latest/sysinfo/index.html#usage
let mut sys = System::new_all();
let mut sys = System::new();
sys.refresh_processes();
let name_str = format!("{}", name.display());