From 8553460afe2e27d11ae691f3496ec62f594f8586 Mon Sep 17 00:00:00 2001 From: Gao feng Date: Sat, 10 Oct 2015 13:50:52 +0800 Subject: [PATCH] return fail if start container failed Signed-off-by: Gao feng --- src/container.c | 5 ++++- src/init.c | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/container.c b/src/container.c index daa2a02..343583a 100644 --- a/src/container.c +++ b/src/container.c @@ -491,8 +491,10 @@ 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) + 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; @@ -503,6 +505,7 @@ fail: container->ns = -1; fprintf(stdout, "container %s init exit code %d\n", container->id, -1); container->exec.code = -1; + container->exec.seq = 0; return -1; } diff --git a/src/init.c b/src/init.c index c758bb8..0a91ebb 100644 --- a/src/init.c +++ b/src/init.c @@ -39,6 +39,7 @@ struct hyper_ctl ctl; static struct hyper_event_ops hyper_signal_ops; static int hyper_handle_exit(struct hyper_pod *pod); +static int hyper_stop_pod(struct hyper_pod *pod); static int hyper_set_win_size(char *json, int length) { @@ -453,7 +454,10 @@ static int hyper_do_start_containers(void *data) for (i = 0; i < pod->c_num; i++) { c = &pod->c[i]; list_add_tail(&c->exec.list, &pod->exec_head); - hyper_start_container(c, utsns, ipcns, pod); + if (hyper_start_container(c, utsns, ipcns, pod) < 0) { + fprintf(stderr, "fail to start container\n"); + goto out; + } } ret = 0; @@ -555,6 +559,7 @@ static int hyper_setup_container(struct hyper_pod *pod) goto out; } + ctl.ctl.fd = arg.ctl_pipe[0]; arg.pod = pod; pod->init_pid = clone(hyper_pod_init, stack + stacksize, flags, &arg); @@ -586,7 +591,6 @@ static int hyper_setup_container(struct hyper_pod *pod) goto out; } - ctl.ctl.fd = arg.ctl_pipe[0]; fprintf(stdout, "hyper_init_event hyper ctl pipe fd %d\n", ctl.ctl.fd); if (hyper_init_event(&ctl.ctl, &hyper_ctl_pipe_ops, pod) < 0 || hyper_add_event(ctl.efd, &ctl.ctl, EPOLLIN) < 0) { @@ -598,6 +602,7 @@ out: close(arg.ctl_pipe[1]); if (ret < 0) { close(arg.ctl_pipe[0]); + hyper_stop_pod(pod); } return ret; }