--- This will be used by the new version of vsockserver, which will use an argz vector to build up the command line it will exec into. exec.c | 22 ++++++++++++++++++++++ exec.h | 7 +++++++ 2 files changed, 29 insertions(+) create mode 100644 exec.c create mode 100644 exec.h diff --git a/exec.c b/exec.c new file mode 100644 index 0000000..cc55200 --- /dev/null +++ b/exec.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> + +#define _GNU_SOURCE + +#include <argz.h> +#include <stdlib.h> +#include <unistd.h> + +#include "exec.h" + +// Like execvp, but takes an argz vector instead of an argv array. +int execzp(const char *file, const char *argz, size_t len) +{ + char **argv = calloc(argz_count(argz, len) + 1, sizeof(char *)); + if (!argv) + return -1; + + argz_extract(argz, len, argv); + + return execvp(file, argv); +} diff --git a/exec.h b/exec.h new file mode 100644 index 0000000..261e113 --- /dev/null +++ b/exec.h @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> + +#include <stddef.h> + +// Like execvp, but takes an argz vector instead of an argv array. +int execzp(const char *file, const char *argz, size_t len); -- 2.30.0