From c0d6f09ce24d05b9d6cc82bb3394dab0f74a5d57 Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Tue, 10 Mar 2026 15:24:19 +0100 Subject: export fun concentrated in its own module --- src/export_fun.rs | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/export_fun.rs') 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>, 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>, @@ -225,8 +233,8 @@ pub fn listen(session: Arc>) -> 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(()) } -- cgit v1.2.3