From 1945e7e1f4bf5bf72ea50db9d62dc6c538d00b70 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Tue, 6 Jun 2023 12:44:43 +0000
Subject: [PATCH 11/15] !2052 fix some codecheck * fix some codecheck

---
 src/cmd/isulad-shim/main.c                      |  3 +--
 src/cmd/isulad-shim/process.c                   | 10 +++-------
 src/daemon/modules/runtime/isula/isula_rt_ops.c |  9 +++------
 3 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/cmd/isulad-shim/main.c b/src/cmd/isulad-shim/main.c
index e2625aac..ff06a633 100644
--- a/src/cmd/isulad-shim/main.c
+++ b/src/cmd/isulad-shim/main.c
@@ -92,7 +92,6 @@ int main(int argc, char **argv)
     char *rt_name = NULL;
     char *log_level = NULL;
     int ret = SHIM_ERR;
-    int efd = -1;
     process_t *p = NULL;
     // execSync timeout
     uint64_t timeout = 0;
@@ -134,7 +133,7 @@ int main(int argc, char **argv)
      */
     if (!p->state->exec) {
         if (p->state->exit_fifo != NULL) {
-            efd = open_no_inherit("exit_fifo", O_WRONLY, -1);
+            int efd = open_no_inherit("exit_fifo", O_WRONLY, -1);
             if (efd < 0) {
                 write_message(g_log_fd, ERR_MSG, "open exit pipe failed:%d", SHIM_SYS_ERR(errno));
                 exit(EXIT_FAILURE);
diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c
index 138a71fb..11889cce 100644
--- a/src/cmd/isulad-shim/process.c
+++ b/src/cmd/isulad-shim/process.c
@@ -1172,8 +1172,6 @@ static int waitpid_with_timeout(int ctr_pid,  int *status, const uint64_t timeou
 {
     int nret = 0;
     time_t start_time = time(NULL);
-    time_t end_time;
-    double interval;
     int st;
 
     for (;;) {
@@ -1181,8 +1179,8 @@ static int waitpid_with_timeout(int ctr_pid,  int *status, const uint64_t timeou
         if (nret == ctr_pid) {
             break;
         }
-        end_time = time(NULL);
-        interval = difftime(end_time, start_time);
+        time_t end_time = time(NULL);
+        double interval = difftime(end_time, start_time);
         if (nret == 0 && interval >= timeout) {
             return SHIM_ERR_TIMEOUT;
         }
@@ -1216,14 +1214,12 @@ static int waitpid_with_timeout(int ctr_pid,  int *status, const uint64_t timeou
  */
 static int wait_container_process_with_timeout(process_t *p, const uint64_t timeout, int *status)
 {
-    int ret = SHIM_ERR;
-
     if (timeout > 0) {
         return waitpid_with_timeout(p->ctr_pid, status, timeout);
     }
 
     for (;;) {
-        ret = reap_container(p->ctr_pid, status);
+        int ret = reap_container(p->ctr_pid, status);
         if (ret == SHIM_OK) {
             if (*status == CONTAINER_ACTION_REBOOT) {
                 ret = setenv("CONTAINER_ACTION", "reboot", 1);
diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c
index 3fe895f8..dcc1d8ac 100644
--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c
+++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c
@@ -843,7 +843,7 @@ out:
     close(shim_stdout_pipe[0]);
     if (ret != 0) {
         show_shim_runtime_errlog(workdir);
-        if (timeout <= 0) {
+        if (timeout != NULL) {
             kill(pid, SIGKILL); /* can kill other process? */
         }
     }
@@ -1313,9 +1313,6 @@ int rt_isula_attach(const char *id, const char *runtime, const rt_attach_params_
 
 static int to_engine_resources(const host_config *hostconfig, shim_client_cgroup_resources *cr)
 {
-    uint64_t period = 0;
-    int64_t quota = 0;
-
     if (hostconfig == NULL || cr == NULL) {
         return -1;
     }
@@ -1354,13 +1351,13 @@ static int to_engine_resources(const host_config *hostconfig, shim_client_cgroup
     // when --cpus=n is set, nano_cpus = n * 1e9.
     if (hostconfig->nano_cpus > 0) {
         // in the case, period will be set to the default value of 100000(0.1s).
-        period = (uint64_t)(100 * Time_Milli / Time_Micro);
+        uint64_t period = (uint64_t)(100 * Time_Milli / Time_Micro);
         // set quota = period * n, in order to let container process fully occupy n cpus.
         if ((hostconfig->nano_cpus / 1e9)  > (INT64_MAX / (int64_t)period)) {
             ERROR("Overflow of quota");
             return -1;
         }
-        quota = hostconfig->nano_cpus / 1e9 * (int64_t)period;
+        int64_t quota = hostconfig->nano_cpus / 1e9 * (int64_t)period;
         cr->cpu->period = period;
         cr->cpu->quota = quota;
     }
-- 
2.25.1

