aboutsummaryrefslogtreecommitdiffstats
path: root/src/export_fun.rs
diff options
context:
space:
mode:
authorJonas Maier <jonas@x77.dev>2026-03-09 19:01:43 +0100
committerJonas Maier <jonas@x77.dev>2026-03-09 19:01:43 +0100
commit1df979235a5b9c36f0c6bbd32d80c715325a4009 (patch)
tree52ee2ef1e97dceb43f12e5fa03e3b98dfc4ae246 /src/export_fun.rs
parent91250e99f113fa754f40d1d26afd774bbb25a438 (diff)
downloadpish-1df979235a5b9c36f0c6bbd32d80c715325a4009.tar.gz
export fun client
Diffstat (limited to 'src/export_fun.rs')
-rw-r--r--src/export_fun.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/export_fun.rs b/src/export_fun.rs
index 934b81c..006bec3 100644
--- a/src/export_fun.rs
+++ b/src/export_fun.rs
@@ -5,6 +5,7 @@ use std::env::current_exe;
use std::ffi::OsStr;
use std::fs;
use std::io;
+use std::io::Read;
use std::io::Write;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::fs::symlink;
@@ -22,23 +23,31 @@ fn handle_server(session: Arc<Mutex<Session>>, stream: UnixStream) -> io::Result
todo!()
}
-fn handle_client(stream: UnixStream) -> io::Result<()> {
+fn handle_client(mut stream: UnixStream) -> io::Result<()> {
println!("uhh hi");
- todo!()
-}
-
-fn user_function_res(sock: &OsStr) -> io::Result<()> {
- let sock = UnixStream::connect(sock)?;
+ // give up all my file descriptors descriptors
let mut ancillary_buffer = [0; 128];
let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
ancillary.add_fds(&[0, 1, 2]);
- let buf = [0; 8];
- let mut bufs = &mut [io::IoSlice::new(&buf[..])][..];
- sock.send_vectored_with_ancillary(bufs, &mut ancillary)?;
+ // cli params
+ let buf = crate::serialization::serialize_cli_args();
+ let bufs = &mut [io::IoSlice::new(&buf[..])][..];
- todo!()
+ // send
+ stream.send_vectored_with_ancillary(bufs, &mut ancillary)?;
+
+ // recv exit code
+ let mut exit_buf = [0; 4];
+ let res = stream.read_exact(&mut exit_buf);
+
+ let exit_code = match res {
+ Ok(_) => i32::from_le_bytes(exit_buf),
+ Err(_) => -2,
+ };
+
+ exit(exit_code)
}
pub fn maybe_run_defined_function() {