Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

double confirm the process has already been started #286

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct stdio_config {
};

static int hyper_release_exec(struct hyper_exec *);
static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io);
static void hyper_exec_process(struct hyper_exec *exec, int pipe, struct stdio_config *io);

static int send_exec_finishing(uint64_t seq, int len, int code)
{
Expand Down Expand Up @@ -500,7 +500,6 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, int pipe, struct stdio_con

if (hyper_enter_sandbox(exec->pod, pipe) < 0) {
perror("enter pidns of pod init failed");
hyper_send_type(pipe, -1);
goto out;
}

Expand Down Expand Up @@ -530,13 +529,14 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, int pipe, struct stdio_con
else
unsetenv("TERM");

hyper_exec_process(exec, io);
hyper_exec_process(exec, pipe, io);
out:
hyper_send_type(pipe, -1);
_exit(125);
}

// do the exec, no return
static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
static void hyper_exec_process(struct hyper_exec *exec, int pipe, struct stdio_config *io)
{
bool defaultPath = false;
if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) {
Expand All @@ -563,9 +563,12 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)

setsid();

//send success notification before stdio was installed, otherwise the debug log in hyper_send_type() will be sent to user tty.
hyper_send_type(pipe, 0);

if (hyper_install_process_stdio(exec, io) < 0) {
fprintf(stderr, "dup pts to exec stdio failed\n");
goto exit;
goto exit_nosend;
}

if (execvp(exec->argv[0], exec->argv) < 0) {
Expand All @@ -581,6 +584,8 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
}

exit:
hyper_send_type(pipe, -1);
exit_nosend:
fflush(NULL);
_exit(125);
}
Expand Down Expand Up @@ -626,7 +631,7 @@ int hyper_run_process(struct hyper_exec *exec)
{
int pipe[2] = {-1, -1};
int pid, ret = -1;
uint32_t type;
uint32_t cpid, type;
struct stdio_config io = {-1, -1,-1, -1,-1, -1};

if (exec->argv == NULL || exec->seq == 0 || exec->container_id == NULL || strlen(exec->container_id) == 0) {
Expand All @@ -652,14 +657,14 @@ int hyper_run_process(struct hyper_exec *exec)
} else if (pid == 0) {
if (strcmp(exec->container_id, HYPERSTART_EXEC_CONTAINER) == 0) {
hyper_send_type(pipe[1], getpid());
hyper_exec_process(exec, &io);
hyper_exec_process(exec, pipe[1], &io);
_exit(125);
}
hyper_do_exec_cmd(exec, pipe[1], &io);
}
fprintf(stdout, "prerequisite process pid %d\n", pid);

if (hyper_get_type(pipe[0], &type) < 0 || (int)type < 0) {
if (hyper_get_type(pipe[0], &cpid) < 0 || (int)cpid < 0) {
fprintf(stderr, "run process failed\n");
goto close_tty;
}
Expand All @@ -669,7 +674,13 @@ int hyper_run_process(struct hyper_exec *exec)
goto close_tty;
}

exec->pid = type;
if (hyper_get_type(pipe[0], &type) < 0 || (int)type < 0) {
fprintf(stderr, "container process %u exec failed\n", cpid);
goto close_tty;
}

//two message may come back in reversed sequence
exec->pid = (type == 0) ? cpid : type;
Copy link
Contributor

@laijs laijs Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is time for converting success-notification-pipes to eventfd....
(not reqired in this pr)

list_add_tail(&exec->list, &exec->pod->exec_head);
exec->ref++;
fprintf(stdout, "%s process pid %d\n", __func__, exec->pid);
Expand Down