mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-09-06 13:41:44 +00:00
watch up pty fd before exec cmd
exec cmd may exit before hyper init watching it's ptmx fd, so the hup event of ptmx may miss, this will cause the eof message fail to send out. Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
+7
-5
@@ -525,6 +525,11 @@ int hyper_start_container(struct hyper_container *container,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (hyper_watch_exec_pty(&container->exec, pod) < 0) {
|
||||
fprintf(stderr, "faile to watch container pty\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* wait for ready message */
|
||||
if (hyper_get_type(arg.pipe[0], &type) < 0 || type != READY) {
|
||||
fprintf(stderr, "wait for container started failed\n");
|
||||
@@ -534,17 +539,14 @@ int hyper_start_container(struct hyper_container *container,
|
||||
close(arg.pipe[0]);
|
||||
close(arg.pipe[1]);
|
||||
|
||||
if (hyper_watch_exec_pty(&container->exec, pod) < 0) {
|
||||
fprintf(stderr, "faile to watch container pty\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fprintf(stdout, "container %s init pid is %d\n", container->id, pid);
|
||||
return 0;
|
||||
fail:
|
||||
close(arg.pipe[0]);
|
||||
close(arg.pipe[1]);
|
||||
close(container->ns);
|
||||
hyper_reset_event(&container->exec.e);
|
||||
hyper_reset_event(&container->exec.errev);
|
||||
container->ns = -1;
|
||||
fprintf(stdout, "container %s init exit code %d\n", container->id, -1);
|
||||
container->exec.code = -1;
|
||||
|
||||
+2
-3
@@ -14,8 +14,9 @@ void hyper_reset_event(struct hyper_event *de)
|
||||
{
|
||||
free(de->rbuf.data);
|
||||
free(de->wbuf.data);
|
||||
|
||||
close(de->fd);
|
||||
memset(de, 0, sizeof(*de));
|
||||
de->fd = -1;
|
||||
}
|
||||
|
||||
int hyper_init_event(struct hyper_event *de, struct hyper_event_ops *ops, void *arg)
|
||||
@@ -219,8 +220,6 @@ void hyper_event_hup(struct hyper_event *de, int efd)
|
||||
{
|
||||
if (epoll_ctl(efd, EPOLL_CTL_DEL, de->fd, NULL) < 0)
|
||||
perror("epoll_ctl del epoll event failed");
|
||||
close(de->fd);
|
||||
de->fd = -1;
|
||||
hyper_reset_event(de);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -370,6 +370,11 @@ static int hyper_do_exec_cmd(void *data)
|
||||
} else if (pid > 0) {
|
||||
uint32_t type;
|
||||
|
||||
if (hyper_watch_exec_pty(exec, pod) < 0) {
|
||||
fprintf(stderr, "add pts master event failed\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (hyper_get_type(pipe[0], &type) < 0 || type != READY) {
|
||||
fprintf(stderr, "hyper init doesn't get execcmd ready message\n");
|
||||
hyper_send_type(arg->pipe[1], ERROR);
|
||||
@@ -380,11 +385,6 @@ static int hyper_do_exec_cmd(void *data)
|
||||
exec->pid = pid;
|
||||
fprintf(stdout, "create exec cmd %s pid %d\n", exec->argv[0], pid);
|
||||
|
||||
if (hyper_watch_exec_pty(exec, pod) < 0) {
|
||||
fprintf(stderr, "add pts master event failed\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
list_add_tail(&exec->list, &pod->exec_head);
|
||||
ret = 0;
|
||||
goto out;
|
||||
|
||||
@@ -227,6 +227,7 @@ static int hyper_parse_container(struct hyper_pod *pod, struct hyper_container *
|
||||
c->exec.code = -1;
|
||||
c->exec.e.fd = -1;
|
||||
c->exec.ptyfd = -1;
|
||||
c->exec.errfd = -1;
|
||||
c->ns = -1;
|
||||
|
||||
next_container = toks[i].size;
|
||||
|
||||
Reference in New Issue
Block a user