diff options
author | tv <tv@krebsco.de> | 2016-02-13 16:45:26 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2016-02-13 16:45:26 +0100 |
commit | 49efebaad725fbc3c3e0eae9e97e8311844f262c (patch) | |
tree | fd8a15c9380b65d10b9aa2cdb4c23f61ba92ba7b | |
parent | eb0797b7edcdfd6b01e5c99735799ccfdbf12153 (diff) |
execve: allow argv propagation
-rw-r--r-- | krebs/5pkgs/builders.nix | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/krebs/5pkgs/builders.nix b/krebs/5pkgs/builders.nix index b3cb1c943..43707aeca 100644 --- a/krebs/5pkgs/builders.nix +++ b/krebs/5pkgs/builders.nix @@ -1,19 +1,30 @@ { lib, pkgs, ... }: with lib; -{ - execve = name: { filename, argv, envp ? {}, destination ? "" }: - writeC name { inherit destination; } '' - #include <unistd.h> - int main () { - const char *filename = ${toC filename}; - char *const argv[] = ${toC (argv ++ [null])}; - char *const envp[] = ${toC ( - mapAttrsToList (k: v: "${k}=${v}") envp ++ [null] - )}; - execve(filename, argv, envp); - return -1; - } - ''; +rec { + execve = name: { filename, argv ? null, envp ? {}, destination ? "" }: let + in writeC name { inherit destination; } '' + #include <unistd.h> + + static char *const filename = ${toC filename}; + + ${if argv == null + then /* Propagate arguments */ '' + #define MAIN_ARGS int argc, char **argv + '' + else /* Provide fixed arguments */ '' + #define MAIN_ARGS void + static char *const argv[] = ${toC (argv ++ [null])}; + ''} + + static char *const envp[] = ${toC ( + mapAttrsToList (k: v: "${k}=${v}") envp ++ [null] + )}; + + int main (MAIN_ARGS) { + execve(filename, argv, envp); + return -1; + } + ''; execveBin = name: cfg: execve name (cfg // { destination = "/bin/${name}"; }); |