From: Ian Jackson Date: Sun, 17 Jul 2022 12:31:28 +0000 (+0100) Subject: prefork-interp: wip args X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=9f7516724eb0b258a6dab39dcaea2c082ed5f370;hp=604cda1caaaf1f4605cc1a9b3ae3f01540621dae;p=chiark-utils.git prefork-interp: wip args Signed-off-by: Ian Jackson --- diff --git a/cprogs/prefork-interp.c b/cprogs/prefork-interp.c index 29d39fe..de2b6f1 100644 --- a/cprogs/prefork-interp.c +++ b/cprogs/prefork-interp.c @@ -353,8 +353,34 @@ static int connect_or_spawn(void) { return fake_pair[0]; } -int main(int argc, const char *const *argv) { - script = process_opts(argc, argv); +static void make_executor_argv(const char *const *argv) { + #define EACH_NEW_ARGV(EACH) { \ + if ((arg = interp)) { EACH; } \ + if ((arg = script)) { EACH; } \ + const char *const *walk = argv; \ + while ((arg = *walk++)) { EACH; } \ + } + + size_t count = 1; + MAKE_NEW_ARGV( count++ ); + + executor_argv = calloc(count, sizeof(char*)); + if (!executor_argv) diee("allocate for arguments"); + + char **out = executor_argv; + MAKE_NEW_ARGV( *out++ = arg ); + *out++ = 0; +} + +int main(int argc_unused, const char *const *argv) { + process_opts(&argv); + + // Now we have + // - possibly interp + // - possibly script + // - remaining args + // which ought to be passed on to the actual executor. + make_new_argv(argv); find_socket_path(); FILLZERO(sun);