Commit 7adff31c by Daniel Lezcano

fork/exec after attach

The command to attach has to be fork/exec. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 91480a0f
......@@ -25,6 +25,9 @@
#include <errno.h>
#include <sys/param.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "commands.h"
#include "arguments.h"
#include "namespace.h"
......@@ -106,6 +109,32 @@ int main(int argc, char *argv[], char *envp[])
return -1;
}
pid = fork();
if (pid < 0) {
SYSERROR("failed to fork");
return -1;
}
if (pid) {
int status;
again:
if (waitpid(pid, &status, 0) < 0) {
if (errno == EINTR)
goto again;
SYSERROR("failed to wait '%d'", pid);
return -1;
}
if (WIFEXITED(status))
return WEXITSTATUS(status);
return -1;
}
if (!pid) {
if (my_args.argc) {
execve(my_args.argv[0], my_args.argv, envp);
SYSERROR("failed to exec '%s'", my_args.argv[0]);
......@@ -116,7 +145,8 @@ int main(int argc, char *argv[], char *envp[])
passwd = getpwuid(uid);
if (!passwd) {
SYSERROR("failed to get passwd entry for uid '%d'", uid);
SYSERROR("failed to get passwd " \
"entry for uid '%d'", uid);
return -1;
}
......@@ -131,5 +161,7 @@ int main(int argc, char *argv[], char *envp[])
return -1;
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment