Just reuse argv instead of duplicating
This commit is contained in:
parent
b37648d869
commit
13c7aa2ca4
1 changed files with 3 additions and 15 deletions
18
main.c
18
main.c
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue