execve: allow argv propagation

This commit is contained in:
tv 2016-02-13 16:45:26 +01:00
parent eb0797b7ed
commit 49efebaad7

View File

@ -1,19 +1,30 @@
{ lib, pkgs, ... }: { lib, pkgs, ... }:
with lib; with lib;
{ rec {
execve = name: { filename, argv, envp ? {}, destination ? "" }: execve = name: { filename, argv ? null, envp ? {}, destination ? "" }: let
writeC name { inherit destination; } '' in writeC name { inherit destination; } ''
#include <unistd.h> #include <unistd.h>
int main () {
const char *filename = ${toC filename}; static char *const filename = ${toC filename};
char *const argv[] = ${toC (argv ++ [null])};
char *const envp[] = ${toC ( ${if argv == null
mapAttrsToList (k: v: "${k}=${v}") envp ++ [null] then /* Propagate arguments */ ''
)}; #define MAIN_ARGS int argc, char **argv
execve(filename, argv, envp); ''
return -1; 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}"; }); execveBin = name: cfg: execve name (cfg // { destination = "/bin/${name}"; });