Just reuse argv instead of duplicating

This commit is contained in:
madmaurice 2021-01-15 20:22:22 +01:00
parent b37648d869
commit 13c7aa2ca4

18
main.c
View file

@ -46,18 +46,7 @@ void forward_signal(int sig)
}
}
char** argdup(int argc, const char** argv)
{
char** newargs = malloc(sizeof(char*) * (argc+1));
for (size_t i = 0; i < argc; i++)
{
newargs[i] = strdup(argv[i]);
}
newargs[argc] = NULL;
return newargs;
}
int main(int argc, const char** argv)
int main(int argc, char* const* argv)
{
int err;
@ -166,10 +155,9 @@ int main(int argc, const char** argv)
{
// First child of init process. do exec here
// use cli arguments for subprocess. skip 0 as it's our programs name.
argv++;
char** newargs = argdup(argc-1, &argv[1]);
if (execvp(newargs[0], newargs) == -1)
if (execvp(argv[0], argv) == -1)
{
fatal("Failed to exec", errno);
}