diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/export_fun.rs | 38 | ||||
| -rw-r--r-- | src/run/mod.rs | 10 |
2 files changed, 24 insertions, 24 deletions
diff --git a/src/export_fun.rs b/src/export_fun.rs index a98699c..fb7911c 100644 --- a/src/export_fun.rs +++ b/src/export_fun.rs @@ -26,8 +26,8 @@ use std::os::unix::net::AncillaryData; use std::os::unix::net::SocketAncillary; use std::os::unix::net::UnixListener; use std::os::unix::net::UnixStream; -use std::path::Path; use std::path::PathBuf; +use std::process::Command; use std::process::exit; use std::sync::Arc; use std::sync::Mutex; @@ -134,6 +134,23 @@ fn handle_client(mut stream: UnixStream) -> io::Result<()> { exit(exit_code) } +pub fn prepare_command(session: Arc<Mutex<Session>>, cmd: &mut Command) { + let Ok(session) = session.lock() else { + return; + }; + + let Some(sr) = session.socket_running.as_ref() else { + return; + }; + + let my_path = std::env::var_os("PATH").expect("no PATH - seriously?"); + let mut new_path = sr.bin_path.as_os_str().as_bytes().to_vec(); + new_path.push(b':'); + new_path.extend_from_slice(my_path.as_bytes()); + cmd.env("PATH", OsStr::from_bytes(&new_path)); + cmd.env("PISH_SOCKET", sr.socket_path.as_os_str()); +} + pub fn maybe_run_defined_function() { if let Some(program_name) = std::env::args_os().next() { let program_name = program_name.as_bytes(); @@ -171,20 +188,11 @@ fn unique_string() -> String { } pub struct SocketRunning { - bin_dir: PathBuf, - path: PathBuf, + bin_path: PathBuf, + socket_path: PathBuf, recv: Receiver<()>, } -impl SocketRunning { - pub fn socket_path(&self) -> &Path { - &self.path - } - pub fn path(&self) -> &Path { - &self.bin_dir - } -} - #[must_use] struct SocketDropper { session: Arc<Mutex<Session>>, @@ -225,8 +233,8 @@ pub fn listen(session: Arc<Mutex<Session>>) -> impl Drop { let mut se = session.lock().unwrap(); assert!(se.socket_running.is_none()); se.socket_running = Some(SocketRunning { - bin_dir, - path: socket_path.clone(), + bin_path: bin_dir, + socket_path: socket_path.clone(), recv, }); } @@ -277,7 +285,7 @@ fn create_function_hook_res( let session = session.lock().map_err(|e| format!("{e:?}"))?; let sock_run = session.socket_running.as_ref().ok_or("no socket running")?; let exe_path = current_exe()?; - let symlink_path = sock_run.bin_dir.join(OsStr::from_bytes(fun_name)); + let symlink_path = sock_run.bin_path.join(OsStr::from_bytes(fun_name)); symlink(exe_path, symlink_path)?; Ok(()) } diff --git a/src/run/mod.rs b/src/run/mod.rs index 5a8370f..c7f4408 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -218,15 +218,7 @@ impl Executor { command.stdin(stdin); command.stdout(stdout); - // TODO: move to export_fun.rs? - if let Some(sr) = self.se.lock().unwrap().socket_running.as_ref() { - let my_path = std::env::var_os("PATH").expect("no PATH - seriously?"); - let mut new_path = sr.path().as_os_str().as_bytes().to_vec(); - new_path.push(b':'); - new_path.extend_from_slice(my_path.as_bytes()); - command.env("PATH", OsStr::from_bytes(&new_path)); - command.env("PISH_SOCKET", sr.socket_path().as_os_str()); - } + crate::export_fun::prepare_command(self.se.clone(), &mut command); match command.spawn() { Ok(c) => SpawnedCmd::Child(c), |
