Compare commits

..

No commits in common. "f2ec93e0f2aa71e637bf00735e9359bffa3029a0" and "80bf7ba82dc428b93f9628ecc61976624c5258fe" have entirely different histories.

4 changed files with 30 additions and 210 deletions

104
Cargo.lock generated
View file

@ -110,15 +110,6 @@ dependencies = [
"winit", "winit",
] ]
[[package]]
name = "addr2line"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]] [[package]]
name = "adler2" name = "adler2"
version = "2.0.0" version = "2.0.0"
@ -233,12 +224,6 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "anyhow"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b964d184e89d9b6b67dd2715bc8e74cf3107fb2b529990c90cf517326150bf4"
[[package]] [[package]]
name = "arboard" name = "arboard"
version = "3.4.1" version = "3.4.1"
@ -490,21 +475,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "backtrace"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets 0.52.6",
]
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.21.7" version = "0.21.7"
@ -1481,12 +1451,6 @@ dependencies = [
"weezl", "weezl",
] ]
[[package]]
name = "gimli"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]] [[package]]
name = "git2" name = "git2"
version = "0.20.0" version = "0.20.0"
@ -1632,16 +1596,13 @@ dependencies = [
name = "hai" name = "hai"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow",
"bunt", "bunt",
"clap", "clap",
"eframe", "eframe",
"egui", "egui",
"egui_extras", "egui_extras",
"env_logger", "env_logger",
"log",
"shadow-rs", "shadow-rs",
"tokio",
] ]
[[package]] [[package]]
@ -2164,17 +2125,6 @@ dependencies = [
"simd-adler32", "simd-adler32",
] ]
[[package]]
name = "mio"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
dependencies = [
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "naga" name = "naga"
version = "24.0.0" version = "24.0.0"
@ -2512,15 +2462,6 @@ dependencies = [
"objc2-foundation", "objc2-foundation",
] ]
[[package]]
name = "object"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.20.3" version = "1.20.3"
@ -2900,12 +2841,6 @@ version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f" checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f"
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]] [[package]]
name = "rustc-hash" name = "rustc-hash"
version = "1.1.0" version = "1.1.0"
@ -3156,16 +3091,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "socket2"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8"
dependencies = [
"libc",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.9.8" version = "0.9.8"
@ -3411,35 +3336,6 @@ dependencies = [
"zerovec", "zerovec",
] ]
[[package]]
name = "tokio"
version = "1.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-macros"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "toml_datetime" name = "toml_datetime"
version = "0.6.8" version = "0.6.8"

View file

@ -7,16 +7,13 @@ publish = false
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
[dependencies] [dependencies]
anyhow = "1.0.96"
bunt = "0.2.8" bunt = "0.2.8"
clap = { version = "4.5.30", features = ["derive"] } clap = { version = "4.5.30", features = ["derive"] }
eframe = { version = "0.31", features = ["default", "__screenshot"] } eframe = { version = "0.31", features = ["default", "__screenshot"] }
egui = "0.31.0" egui = "0.31.0"
egui_extras = { version = "0.31", features = ["default", "image", "all_loaders"] } egui_extras = { version = "0.31", features = ["default", "image", "all_loaders"] }
env_logger = "0.11.6" env_logger = "0.11.6"
log = "0.4.25"
shadow-rs = "0.38" shadow-rs = "0.38"
tokio = { version = "1.43", features = ["full"] }
[build-dependencies] [build-dependencies]
shadow-rs = "0.38" shadow-rs = "0.38"

View file

@ -1,26 +1,20 @@
/* /*
* SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors * SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
*/ */
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
mod bininfo;
mod gui; mod gui;
mod bininfo;
mod pman; mod pman;
use bunt::println; use clap::{Subcommand, Parser};
use clap::{Parser, Subcommand}; use pman::init_process_manager;
use log::info;
use pman::{init_process_manager, ProcessCommand, ProcessManager};
use shadow_rs::shadow; use shadow_rs::shadow;
use std::sync::{Arc, Mutex, OnceLock};
use tokio::{signal, sync::mpsc::Sender};
shadow!(build); shadow!(build);
static PMAN_SENDER: OnceLock<Sender<ProcessCommand>> = OnceLock::new();
/// Simple program to greet a person /// Simple program to greet a person
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
@ -45,26 +39,30 @@ enum Commands {
remote: String, remote: String,
}, },
#[command(about = "List compile time backed info to audit binary")] #[command(about = "List compile time backed info to audit binary")]
Shadow { outfile: Option<String> }, Shadow {
outfile: Option<String>,
},
#[command(about = "Show test gui")] #[command(about = "Show test gui")]
Gui, Gui,
Devtest,
} }
#[tokio::main]
async fn main() {
env_logger::init(); fn main() {
let args = Args::parse(); let args = Args::parse();
let _ = init_process_manager(); init_process_manager();
match args.command { match args.command {
Commands::Clone { remote } => {}
Commands::Clone { remote } => {
}
Commands::Shadow { outfile } => { Commands::Shadow { outfile } => {
bininfo::print_info(); bininfo::print_info();
return; return;
} }
Commands::Gui => { Commands::Gui => {
@ -72,23 +70,7 @@ async fn main() {
if let Err(e) = res { if let Err(e) = res {
println!("{}", e); println!("{}", e);
} }
return;
} }
Commands::Devtest => {
PMAN_SENDER.get().unwrap().send(ProcessCommand::SpawnShellCmd {
cmd: "sleep 100 && echo hello meow".to_string(),
}).await.expect("TODO: panic message");
tokio::select! {
_ = signal::ctrl_c() => {
info!("Ctrl-c received");
let sender = PMAN_SENDER.get().unwrap();
let _ = sender.send(ProcessCommand::Shutdown).await;
}
}
}
}; };
//handling anything here for gui wont work
println!("exit");
} }

View file

@ -1,36 +1,16 @@
/* /*
* SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors * SPDX-FileCopyrightText: 2025 April Faye John <april.john@denic.de> & Contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
*/ */
use crate::PMAN_SENDER; use clap::Command;
use anyhow::{Ok, Result};
use tokio::process::{Child, Command};
use std::sync::{Arc, Mutex};
use log::{debug, info};
use tokio::sync::mpsc;use tokio::sync::mpsc::Receiver;
pub fn init_process_manager() -> Result<()> { pub fn init_process_manager() {
let (tx, mut rx) = mpsc::channel::<ProcessCommand>(32); let ProcessManager = ProcessManager::default();
let mut process_manager = ProcessManager::default();
let _ = PMAN_SENDER.set(tx);
debug!("[pman-main] Spawning pman task");
tokio::spawn(async move {
info!("[pman-task] Hello from Pman");
while process_manager.lifecycle(&mut rx).await.is_ok() {
let result = process_manager.alive_check().await;
if let Err(e) = result {
println!("{}", e);
}
}
});
Ok(())
} }
#[derive(Debug)]
pub struct ProcessManager { pub struct ProcessManager {
processes: Vec<Child>, processes: Vec<Command>
} }
impl Default for ProcessManager { impl Default for ProcessManager {
@ -41,58 +21,23 @@ impl Default for ProcessManager {
} }
} }
#[derive(Debug)]
pub enum ProcessCommand {
SpawnShellCmd { cmd: String },
Shutdown,
}
impl ProcessManager { impl ProcessManager {
fn spawn_shell_command(&mut self, command: String) { fn spawn_shell_command(self, command: String) {
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
return self.spawn_cmd_command(command); return self.spawn_cmd_command(command);
} else if cfg!(target_os = "macos") || cfg!(target_os = "ios") { } else if cfg!(target_os = "macos") {
// TODO: reasearch if ios also has zsh
return self.spawn_zsh_command(command); return self.spawn_zsh_command(command);
} else { } else {
return self.spawn_bash_command(command); return self.spawn_bash_command(command);
} }
} }
fn spawn_bash_command(&mut self, command: String) { fn spawn_bash_command(self, command: String) {
debug!("Spawning bash cmd {}", command);
let mut cmd = Command::new("bash")
.arg("-c")
.arg(command)
.spawn().unwrap();
let _ = tokio::spawn(async move {
cmd.wait().await;
});
// Doesnt make sense to list cmd commands
// self.processes.push(cmd);
} }
fn spawn_cmd_command(&mut self, command: String) {} fn spawn_cmd_command(self, command: String) {
fn spawn_zsh_command(&mut self, command: String) {}
pub async fn lifecycle(&mut self, rx: &mut Receiver<ProcessCommand>) -> Result<()> {
let opt = rx.recv().await;
if let Some(message) = opt {
match message {
ProcessCommand::SpawnShellCmd { cmd } => {
self.spawn_shell_command(cmd);
}
ProcessCommand::Shutdown => {
info!("Close command");
anyhow::bail!("Close command");
}
}
} else {
anyhow::bail!("Channel closed");
}
Ok(())
} }
async fn alive_check(&mut self) -> Result<()> { fn spawn_zsh_command(self, command: String) {
for process in &mut self.processes {
}
Ok(())
} }
} }