aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJonas Maier <>2026-03-05 19:29:27 +0100
committerJonas Maier <>2026-03-05 19:29:27 +0100
commite79adb55ac3b94bbdd40d8b6e2ed35ab32a5fd9d (patch)
tree88eee8ee654c760533973eeb48ff6e06e4bb6b63 /src/main.rs
parent07c802b93a241d566161d3077b3254df4067fa1e (diff)
downloadpish-e79adb55ac3b94bbdd40d8b6e2ed35ab32a5fd9d.tar.gz
clean up reload logic
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs40
1 files changed, 4 insertions, 36 deletions
diff --git a/src/main.rs b/src/main.rs
index 6687937..b064fcb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,6 +11,7 @@ pub mod panic;
pub mod parse;
pub mod raw;
pub mod run;
+pub mod reload;
use linebuf::LineBuf;
use raw::*;
@@ -248,35 +249,6 @@ fn event_loop() {
se.raw.disable();
}
-#[cfg(debug_assertions)]
-fn reload_shell() {
- use std::{env, ffi::CString, ptr};
-
- // path to this executable
- let exe = env::current_exe().unwrap();
- let exe_c = CString::new(exe.as_os_str().as_bytes()).unwrap();
-
- // argv
- let args: Vec<CString> = env::args().map(|a| CString::new(a).unwrap()).collect();
-
- let mut argv: Vec<*const libc::c_char> = args.iter().map(|a| a.as_ptr()).collect();
- argv.push(ptr::null());
-
- // environment
- let env: Vec<CString> = env::vars()
- .map(|(k, v)| CString::new(format!("{}={}", k, v)).unwrap())
- .collect();
-
- let mut envp: Vec<*const libc::c_char> = env.iter().map(|e| e.as_ptr()).collect();
- envp.push(ptr::null());
-
- unsafe {
- libc::execve(exe_c.as_ptr(), argv.as_ptr(), envp.as_ptr());
- }
-
- eprintln!("exec failed");
-}
-
fn main() {
if !io::stdin().is_terminal() {
println!("need to run in a tty");
@@ -290,14 +262,10 @@ fn main() {
let res = std::panic::catch_unwind(event_loop);
match res {
Ok(_) => break,
- Err(_) =>
- {
+ Err(_) => {
#[cfg(debug_assertions)]
- if run::RELOAD.load(std::sync::atomic::Ordering::SeqCst) {
- reload_shell();
- println!("failed to reload shell");
- }
- }
+ unsafe { reload::continue_reload() }
+ },
}
}