mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-01 16:54:17 +00:00
kill orphaned pm3 on startup
This commit is contained in:
parent
ed0942e332
commit
64299960a5
24
src/pm3.rs
24
src/pm3.rs
@ -1,4 +1,4 @@
|
||||
use log::{info, trace};
|
||||
use log::{debug, info, trace, warn};
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::process::Stdio;
|
||||
@ -10,6 +10,8 @@ use tokio::sync::broadcast;
|
||||
/// The pm3 binary is ether set in the env var PM3_BIN or found in the path
|
||||
/// The ouput is parsed and send via the `tx` channel
|
||||
pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>> {
|
||||
kill_orphans().await;
|
||||
|
||||
let pm3_path = match env::var("PM3_BIN") {
|
||||
Ok(path) => path,
|
||||
Err(_) => {
|
||||
@ -47,3 +49,23 @@ pub async fn run_pm3(tx: broadcast::Sender<String>) -> Result<(), Box<dyn Error>
|
||||
Err("PM3 exited with a non zero exit code".into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Kills any open pm3 instances
|
||||
/// Also funny name. hehehe.
|
||||
async fn kill_orphans() {
|
||||
let kill_result = Command::new("pkill")
|
||||
.arg("-KILL")
|
||||
.arg("-x")
|
||||
.arg("proxmark3")
|
||||
.output()
|
||||
.await;
|
||||
|
||||
match kill_result {
|
||||
Ok(_) => {
|
||||
debug!("Successfully killed orphaned pm3 instances");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to kill pm3 orphans: {e} Continuing anyway");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user