about summary refs log tree commit diff
path: root/users/Profpatsch/execline
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2024-03-16T21·29+0100
committerclbot <clbot@tvl.fyi>2024-03-16T22·36+0000
commit16461c410031791015fd69ff2bd3084354c2f3c5 (patch)
treebb4e42009e5ff04258fd5c402d479a728a952c77 /users/Profpatsch/execline
parent981c7fef0ec26274fdd93af08064499460fbec77 (diff)
feat(users/Profpatsch/execline): add setsid r/7710
Small wrapper around `setsid(2)` that does not exist in the
execline-style tooling.

Is probably gonna fail iff our process is a session leader already,
but I haven’t tried that out yet.

Change-Id: I1a820f1c6d65ddc29c30995bfd56a760a9d6b341
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11167
Tested-by: BuildkiteCI
Autosubmit: Profpatsch <mail@profpatsch.de>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/execline')
-rw-r--r--users/Profpatsch/execline/default.nix22
1 files changed, 22 insertions, 0 deletions
diff --git a/users/Profpatsch/execline/default.nix b/users/Profpatsch/execline/default.nix
index 47c7f8b74971..04d07895c682 100644
--- a/users/Profpatsch/execline/default.nix
+++ b/users/Profpatsch/execline/default.nix
@@ -39,10 +39,32 @@ let
     }
   '';
 
+  setsid = depot.nix.writers.rustSimple
+    {
+      name = "setsid";
+      dependencies = [
+        depot.users.Profpatsch.execline.exec-helpers
+        depot.third_party.rust-crates.libc
+      ];
+    } ''
+    use std::os::unix::ffi::OsStrExt;
+    use std::ffi::OsStr;
+
+    fn main() {
+      let (args, prog) = exec_helpers::args_for_exec("setsid", 1);
+      let envvar = OsStr::from_bytes(&args.get(0).expect("first argument must be envvar name to set"));
+      let sid: i32 = unsafe { libc::setsid() };
+      std::env::set_var(envvar, format!("{}", sid));
+      let env: Vec<(&[u8], &[u8])> = vec![];
+      exec_helpers::exec_into_args("getid", prog, env);
+    }
+  '';
+
 in
 depot.nix.readTree.drvTargets {
   inherit
     exec-helpers-hs
     print-one-env
+    setsid
     ;
 }