feat(users/Profpatsch/execline): add setsid
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>
This commit is contained in:
parent
981c7fef0e
commit
16461c4100
1 changed files with 22 additions and 0 deletions
|
@ -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
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue