From 3942bcc4c3a755d33e709046edd358f9af264d11 Mon Sep 17 00:00:00 2001 From: holyfei Date: Wed, 21 Oct 2020 10:00:15 +0800 Subject: [PATCH 03/28] isulad: rt_isula_start should read the isulad-shim pidinfo reason: the ppid of init pid should be isulad-shim, read isulad-shim pidinfo and set the start time for init pidinfo Signed-off-by: yangfeiyu --- .../modules/runtime/isula/isula_rt_ops.c | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c index 6e4512f..82d7aec 100644 --- a/src/daemon/modules/runtime/isula/isula_rt_ops.c +++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c @@ -851,8 +851,13 @@ out: int rt_isula_start(const char *id, const char *runtime, const rt_start_params_t *params, pid_ppid_info_t *pid_info) { char workdir[PATH_MAX] = { 0 }; + char shim_pid_file_name[PATH_MAX] = { 0 }; pid_t pid = 0; + pid_t shim_pid = -1; int ret = 0; + int splice_ret = 0; + proc_t *proc = NULL; + proc_t *p_proc = NULL; if (id == NULL || runtime == NULL || params == NULL || pid_info == NULL) { ERROR("nullptr arguments not allowed"); @@ -863,6 +868,12 @@ int rt_isula_start(const char *id, const char *runtime, const rt_start_params_t return -1; } + splice_ret = snprintf(shim_pid_file_name, sizeof(shim_pid_file_name), "%s/shim-pid", workdir); + if (splice_ret < 0 || splice_ret >= sizeof(shim_pid_file_name)) { + ERROR("%s: wrong shim workdir", id); + return -1; + } + pid = get_container_process_pid(workdir); if (pid < 0) { ret = -1; @@ -870,12 +881,32 @@ int rt_isula_start(const char *id, const char *runtime, const rt_start_params_t goto out; } - if (util_read_pid_ppid_info(pid, pid_info) != 0) { + file_read_int(shim_pid_file_name, &shim_pid); + if (shim_pid < 0) { + ret = -1; + ERROR("%s: failed to read isulad shim pid", id); + goto out; + } + + proc = util_get_process_proc_info(pid); + if (proc == NULL) { ret = -1; - ERROR("%s: failed read pid info", id); + ERROR("%s: failed to read pidinfo", id); goto out; } + p_proc = util_get_process_proc_info(shim_pid); + if (p_proc == NULL) { + ret = -1; + ERROR("%s: failed to read isulad shim pidinfo", id); + goto out; + } + + pid_info->pid = proc->pid; + pid_info->start_time = proc->start_time; + pid_info->ppid = shim_pid; + pid_info->pstart_time = p_proc->start_time; + if (runtime_call_simple(workdir, runtime, "start", NULL, 0, id) != 0) { ERROR("call runtime start id failed"); ret = -1; @@ -888,6 +919,9 @@ out: shim_kill_force(workdir); } + free(proc); + free(p_proc); + return ret; } -- 2.20.1