From fe267afe95a7c1e1a261c78cd5c79dbc3b7f4426 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Wed, 6 Sep 2023 15:05:29 +0800
Subject: [PATCH 140/145] remove usage of strerror with user defined errno

Signed-off-by: haozi007 <liuhao27@huawei.com>
---
 src/cmd/command_parser.c                      | 12 ++++++----
 src/cmd/isula/base/create.c                   |  3 ++-
 src/cmd/isula/isula_host_spec.c               |  9 ++++---
 src/cmd/isulad/main.c                         |  8 ++++---
 src/cmd/options/opt_ulimit.c                  |  6 +++--
 src/daemon/entry/cri/cni_network_plugin.cc    |  9 ++++---
 src/daemon/entry/cri/sysctl_tools.c           | 14 +++++++----
 src/daemon/modules/image/oci/oci_image.c      |  6 +++--
 .../oci/storage/image_store/image_store.c     |  6 +++--
 .../graphdriver/devmapper/deviceset.c         | 19 +++++++++------
 .../storage/layer_store/graphdriver/driver.c  |  9 ++++---
 .../graphdriver/overlay2/driver_overlay2.c    | 17 ++++++++-----
 .../oci/storage/layer_store/layer_store.c     |  6 +++--
 .../remote_layer_support/remote_support.c     |  6 +++--
 .../oci/storage/rootfs_store/rootfs_store.c   |  6 +++--
 .../modules/image/oci/storage/storage.c       |  6 +++--
 src/daemon/modules/plugin/plugin.c            | 24 ++++++++++++-------
 .../modules/service/network_namespace_api.c   |  6 +++--
 src/utils/cutils/utils_file.c                 |  4 +++-
 19 files changed, 117 insertions(+), 59 deletions(-)

diff --git a/src/cmd/command_parser.c b/src/cmd/command_parser.c
index 7c322a44..2b87d321 100644
--- a/src/cmd/command_parser.c
+++ b/src/cmd/command_parser.c
@@ -546,7 +546,8 @@ int command_convert_u16(command_option_t *option, const char *arg)
     }
     ret = util_safe_u16(arg, option->data);
     if (ret != 0) {
-        COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, option->large, strerror(-ret));
+        errno = -ret;
+        CMD_SYSERROR("Invalid value \"%s\" for flag --%s", arg, option->large);
         return EINVALIDARGS;
     }
     return 0;
@@ -561,7 +562,8 @@ int command_convert_llong(command_option_t *opt, const char *arg)
     }
     ret = util_safe_llong(arg, opt->data);
     if (ret != 0) {
-        COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, opt->large, strerror(-ret));
+        errno = -ret;
+        CMD_SYSERROR("Invalid value \"%s\" for flag --%s", arg, opt->large);
         return EINVALIDARGS;
     }
     return 0;
@@ -575,7 +577,8 @@ int command_convert_uint(command_option_t *opt, const char *arg)
     }
     ret = util_safe_uint(arg, opt->data);
     if (ret != 0) {
-        COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, opt->large, strerror(-ret));
+        errno = -ret;
+        CMD_SYSERROR("Invalid value \"%s\" for flag --%s", arg, opt->large);
         return EINVALIDARGS;
     }
     return 0;
@@ -590,7 +593,8 @@ int command_convert_int(command_option_t *option, const char *arg)
     }
     ret = util_safe_int(arg, option->data);
     if (ret != 0) {
-        COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, option->large, strerror(-ret));
+        errno = -ret;
+        CMD_SYSERROR("Invalid value \"%s\" for flag --%s", arg, option->large);
         return EINVALIDARGS;
     }
     return 0;
diff --git a/src/cmd/isula/base/create.c b/src/cmd/isula/base/create.c
index 02838a56..5756e6ad 100644
--- a/src/cmd/isula/base/create.c
+++ b/src/cmd/isula/base/create.c
@@ -1845,7 +1845,8 @@ static int create_check_hugetlbs(const struct client_arguments *args)
         }
         ret = util_parse_byte_size_string(limit, &limitvalue);
         if (ret != 0) {
-            COMMAND_ERROR("Invalid hugetlb limit:%s:%s", limit, strerror(-ret));
+            errno = -ret;
+            CMD_SYSERROR("Invalid hugetlb limit:%s", limit);
             free(dup);
             ret = -1;
             goto out;
diff --git a/src/cmd/isula/isula_host_spec.c b/src/cmd/isula/isula_host_spec.c
index bbcf50de..5a41c55c 100644
--- a/src/cmd/isula/isula_host_spec.c
+++ b/src/cmd/isula/isula_host_spec.c
@@ -66,7 +66,8 @@ static bool parse_restart_policy(const char *policy, host_config_restart_policy
         }
         nret = util_safe_int(dotpos, &(*rp)->maximum_retry_count);
         if (nret != 0) {
-            COMMAND_ERROR("Maximum retry count must be an integer: %s", strerror(-nret));
+            errno = -nret;
+            CMD_SYSERROR("Maximum retry count must be an integer");
             goto cleanup;
         }
     }
@@ -706,7 +707,8 @@ static host_config_hugetlbs_element *pase_hugetlb_limit(const char *input)
 
     ret = util_parse_byte_size_string(limit_value, &tconverted);
     if (ret != 0 || tconverted < 0) {
-        COMMAND_ERROR("Parse limit value: %s failed:%s", limit_value, strerror(-ret));
+        errno = -ret;
+        CMD_SYSERROR("Parse limit value: %s failed", limit_value);
         goto free_out;
     }
     limit = (uint64_t)tconverted;
@@ -715,7 +717,8 @@ static host_config_hugetlbs_element *pase_hugetlb_limit(const char *input)
         tconverted = 0;
         ret = util_parse_byte_size_string(pagesize, &tconverted);
         if (ret != 0 || tconverted < 0) {
-            COMMAND_ERROR("Parse pagesize error.Invalid hugepage size: %s: %s", pagesize, strerror(-ret));
+            errno = -ret;
+            CMD_SYSERROR("Parse pagesize error.Invalid hugepage size: %s", pagesize);
             goto free_out;
         }
         page = (uint64_t)tconverted;
diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c
index 1906feaf..e624cfdd 100644
--- a/src/cmd/isulad/main.c
+++ b/src/cmd/isulad/main.c
@@ -627,8 +627,9 @@ static int parse_time_duration(const char *value, unsigned int *seconds)
     *(num_str + len - 1) = '\0';
     ret = util_safe_uint(num_str, &tmp);
     if (ret < 0) {
-        ERROR("Illegal unsigned integer: %s", num_str);
-        COMMAND_ERROR("Illegal unsigned integer:%s:%s", num_str, strerror(-ret));
+        errno = -ret;
+        SYSERROR("Illegal unsigned integer: %s", num_str);
+        COMMAND_ERROR("Illegal unsigned integer:%s", num_str);
         ret = -1;
         goto out;
     }
@@ -1499,7 +1500,8 @@ static int create_mount_flock_file(const struct service_arguments *args)
         // recreate mount flock file
         // and make file uid/gid and permission correct
         if (!util_force_remove_file(cleanpath, &err)) {
-            ERROR("Failed to delete %s, error: %s. Please delete %s manually.", path, strerror(err), path);
+            errno = err;
+            SYSERROR("Failed to delete %s. Please delete %s manually.", path, path);
             return -1;
         }
     }
diff --git a/src/cmd/options/opt_ulimit.c b/src/cmd/options/opt_ulimit.c
index 55912a16..6853c0d9 100644
--- a/src/cmd/options/opt_ulimit.c
+++ b/src/cmd/options/opt_ulimit.c
@@ -63,7 +63,8 @@ static int parse_soft_hard_ulimit(const char *val, char **limitvals, size_t limi
     // parse soft
     ret = util_safe_llong(limitvals[0], &converted);
     if (ret < 0) {
-        COMMAND_ERROR("Invalid ulimit soft value: \"%s\", parse int64 failed: %s", val, strerror(-ret));
+        errno = -ret;
+        CMD_SYSERROR("Invalid ulimit soft value: \"%s\", parse int64 failed", val);
         ret = -1;
         goto out;
     }
@@ -74,7 +75,8 @@ static int parse_soft_hard_ulimit(const char *val, char **limitvals, size_t limi
         converted = 0;
         ret = util_safe_llong(limitvals[1], &converted);
         if (ret < 0) {
-            COMMAND_ERROR("Invalid ulimit hard value: \"%s\", parse int64 failed: %s", val, strerror(-ret));
+            errno = -ret;
+            CMD_SYSERROR("Invalid ulimit hard value: \"%s\", parse int64 failed", val);
             ret = -1;
             goto out;
         }
diff --git a/src/daemon/entry/cri/cni_network_plugin.cc b/src/daemon/entry/cri/cni_network_plugin.cc
index 8cad0126..8aaf7390 100644
--- a/src/daemon/entry/cri/cni_network_plugin.cc
+++ b/src/daemon/entry/cri/cni_network_plugin.cc
@@ -1003,7 +1003,8 @@ void CniNetworkPlugin::RLockNetworkMap(Errors &error)
     int ret = pthread_rwlock_rdlock(&m_netsLock);
     if (ret != 0) {
         error.Errorf("Failed to get read lock");
-        ERROR("Get read lock failed: %s", strerror(ret));
+        errno = ret;
+        SYSERROR("Get read lock failed");
     }
 }
 
@@ -1012,7 +1013,8 @@ void CniNetworkPlugin::WLockNetworkMap(Errors &error)
     int ret = pthread_rwlock_wrlock(&m_netsLock);
     if (ret != 0) {
         error.Errorf("Failed to get write lock");
-        ERROR("Get write lock failed: %s", strerror(ret));
+        errno = ret;
+        SYSERROR("Get write lock failed");
     }
 }
 
@@ -1021,7 +1023,8 @@ void CniNetworkPlugin::UnlockNetworkMap(Errors &error)
     int ret = pthread_rwlock_unlock(&m_netsLock);
     if (ret != 0) {
         error.Errorf("Failed to unlock");
-        ERROR("Unlock failed: %s", strerror(ret));
+        errno = ret;
+        SYSERROR("Unlock failed");
     }
 }
 
diff --git a/src/daemon/entry/cri/sysctl_tools.c b/src/daemon/entry/cri/sysctl_tools.c
index 847c36e9..ac4fb226 100644
--- a/src/daemon/entry/cri/sysctl_tools.c
+++ b/src/daemon/entry/cri/sysctl_tools.c
@@ -22,6 +22,8 @@
 #include <unistd.h>
 #include <limits.h>
 
+#include <isula_libutils/log.h>
+
 #include "utils.h"
 
 int get_sysctl(const char *sysctl, char **err)
@@ -41,14 +43,16 @@ int get_sysctl(const char *sysctl, char **err)
     ret = -1;
     fd = util_open(fullpath, O_RDONLY, 0);
     if (fd < 0) {
-        if (asprintf(err, "Open %s failed: %s", sysctl, strerror(errno)) < 0) {
+        SYSWARN("Open %s failed", sysctl);
+        if (asprintf(err, "Open %s failed", sysctl) < 0) {
             *err = util_strdup_s("Out of memory");
         }
         goto free_out;
     }
     rsize = util_read_nointr(fd, buff, sizeof(buff) - 1);
     if (rsize <= 0) {
-        if (asprintf(err, "Read file failed: %s", strerror(errno)) < 0) {
+        SYSWARN("Read file: %s failed", sysctl);
+        if (asprintf(err, "Read file: %s failed", sysctl) < 0) {
             *err = util_strdup_s("Out of memory");
         }
         goto free_out;
@@ -93,14 +97,16 @@ int set_sysctl(const char *sysctl, int new_value, char **err)
     ret = -1;
     fd = util_open(fullpath, O_WRONLY, 0);
     if (fd < 0) {
-        if (asprintf(err, "Open %s failed: %s", sysctl, strerror(errno)) < 0) {
+        SYSWARN("Open %s failed", sysctl);
+        if (asprintf(err, "Open %s failed", sysctl) < 0) {
             *err = util_strdup_s("Out of memory");
         }
         goto free_out;
     }
     rsize = util_write_nointr(fd, buff, strlen(buff));
     if (rsize < 0 || (size_t)rsize != strlen(buff)) {
-        if (asprintf(err, "Write new value failed: %s", strerror(errno)) < 0) {
+        SYSWARN("Write new value to %s failed", sysctl);
+        if (asprintf(err, "Write new value to %s failed", sysctl) < 0) {
             *err = util_strdup_s("Out of memory");
         }
         goto free_out;
diff --git a/src/daemon/modules/image/oci/oci_image.c b/src/daemon/modules/image/oci/oci_image.c
index ae260c7d..abca4ed7 100644
--- a/src/daemon/modules/image/oci/oci_image.c
+++ b/src/daemon/modules/image/oci/oci_image.c
@@ -56,7 +56,8 @@ static inline bool oci_remote_lock(pthread_rwlock_t *remote_lock, bool writable)
         nret = pthread_rwlock_rdlock(remote_lock);
     }
     if (nret != 0) {
-        ERROR("Lock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock memory store failed");
         return false;
     }
 
@@ -69,7 +70,8 @@ static inline void oci_remote_unlock(pthread_rwlock_t *remote_lock)
 
     nret = pthread_rwlock_unlock(remote_lock);
     if (nret != 0) {
-        FATAL("Unlock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Unlock memory store failed");
     }
 }
 #endif
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.c b/src/daemon/modules/image/oci/storage/image_store/image_store.c
index abd625f7..99640b59 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.c
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.c
@@ -95,7 +95,8 @@ static inline bool image_store_lock(enum lock_type type)
         nret = pthread_rwlock_wrlock(&g_image_store->rwlock);
     }
     if (nret != 0) {
-        ERROR("Lock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock memory store failed");
         return false;
     }
 
@@ -108,7 +109,8 @@ static inline void image_store_unlock()
 
     nret = pthread_rwlock_unlock(&g_image_store->rwlock);
     if (nret != 0) {
-        FATAL("Unlock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Unlock memory store failed");
     }
 }
 
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
index ee82e32c..76ec09d6 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
@@ -107,8 +107,9 @@ static int handle_dm_min_free_space(char *val, struct device_set *devset)
     long converted = 0;
     int ret = util_parse_percent_string(val, &converted);
     if (ret != 0 || converted >= 100) {
-        ERROR("Invalid min free space: '%s': %s", val, strerror(-ret));
-        isulad_set_error_message("Invalid min free space: '%s': %s", val, strerror(-ret));
+        errno = -ret;
+        SYSERROR("Invalid min free space: '%s'", val);
+        isulad_set_error_message("Invalid min free space: '%s'", val);
         return -1;
     }
     devset->min_free_space_percent = (uint32_t)converted;
@@ -122,8 +123,9 @@ static int handle_dm_basesize(char *val, struct device_set *devset)
     int ret = util_parse_byte_size_string(val, &converted);
 
     if (ret != 0) {
-        ERROR("Invalid size: '%s': %s", val, strerror(-ret));
-        isulad_set_error_message("Invalid size: '%s': %s", val, strerror(-ret));
+        errno = -ret;
+        SYSERROR("Invalid size: '%s'", val);
+        isulad_set_error_message("Invalid size: '%s'", val);
         return -1;
     }
     if (converted <= 0) {
@@ -2722,7 +2724,8 @@ static int determine_driver_capabilities(const char *version, struct device_set
 
     ret = util_parse_byte_size_string(tmp_str[0], &major);
     if (ret != 0) {
-        ERROR("devmapper: invalid size: '%s': %s", tmp_str[0], strerror(-ret));
+        errno = -ret;
+        SYSERROR("devmapper: invalid size: '%s'", tmp_str[0]);
         ret = -1;
         goto out;
     }
@@ -2742,7 +2745,8 @@ static int determine_driver_capabilities(const char *version, struct device_set
 
     ret = util_parse_byte_size_string(tmp_str[1], &minor);
     if (ret != 0) {
-        ERROR("devmapper: invalid size: '%s': %s", tmp_str[1], strerror(-ret));
+        errno = -ret;
+        SYSERROR("devmapper: invalid size: '%s'", tmp_str[1]);
         ret = -1;
         goto out;
     }
@@ -2915,7 +2919,8 @@ static int parse_storage_opt(const json_map_string_string *opts, uint64_t *size)
 
             ret = util_parse_byte_size_string(opts->values[i], &converted);
             if (ret != 0) {
-                ERROR("Invalid size: '%s': %s", opts->values[i], strerror(-ret));
+                errno = -ret;
+                SYSERROR("Invalid size: '%s'", opts->values[i]);
                 ret = -1;
                 goto out;
             }
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
index 71cbbe1c..fb549bae 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
@@ -86,7 +86,8 @@ static inline bool driver_rd_lock()
 
     nret = pthread_rwlock_rdlock(&g_graphdriver->rwlock);
     if (nret != 0) {
-        ERROR("Lock driver memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock driver memory store failed");
         return false;
     }
 
@@ -99,7 +100,8 @@ static inline bool driver_wr_lock()
 
     nret = pthread_rwlock_wrlock(&g_graphdriver->rwlock);
     if (nret != 0) {
-        ERROR("Lock driver memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock driver memory store failed");
         return false;
     }
 
@@ -112,7 +114,8 @@ static inline void driver_unlock()
 
     nret = pthread_rwlock_unlock(&g_graphdriver->rwlock);
     if (nret != 0) {
-        FATAL("Unlock driver memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Unlock driver memory store failed");
     }
 }
 
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
index 510bd079..7517dd43 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
@@ -134,7 +134,8 @@ static int overlay2_parse_options(struct graphdriver *driver, const char **optio
             int64_t converted = 0;
             ret = util_parse_byte_size_string(val, &converted);
             if (ret != 0) {
-                ERROR("Invalid size: '%s': %s", val, strerror(-ret));
+                errno = -ret;
+                SYSERROR("Invalid size: '%s'", val);
                 ret = -1;
                 goto out;
             }
@@ -143,7 +144,8 @@ static int overlay2_parse_options(struct graphdriver *driver, const char **optio
             int64_t converted = 0;
             ret = util_parse_byte_size_string(val, &converted);
             if (ret != 0) {
-                ERROR("Invalid size: '%s': %s", val, strerror(-ret));
+                errno = -ret;
+                SYSERROR("Invalid size: '%s'", val);
                 ret = -1;
                 goto out;
             }
@@ -152,7 +154,8 @@ static int overlay2_parse_options(struct graphdriver *driver, const char **optio
             bool converted_bool = 0;
             ret = util_str_to_bool(val, &converted_bool);
             if (ret != 0) {
-                ERROR("Invalid bool: '%s': %s", val, strerror(-ret));
+                errno = -ret;
+                SYSERROR("Invalid bool: '%s'", val);
                 ret = -1;
                 goto out;
             }
@@ -161,7 +164,8 @@ static int overlay2_parse_options(struct graphdriver *driver, const char **optio
             bool converted_bool = 0;
             ret = util_str_to_bool(val, &converted_bool);
             if (ret != 0) {
-                ERROR("Invalid bool: '%s': %s", val, strerror(-ret));
+                errno = -ret;
+                SYSERROR("Invalid bool: '%s'", val);
                 ret = -1;
                 goto out;
             }
@@ -823,8 +827,9 @@ static int set_layer_quota(const char *dir, const json_map_string_string *opts,
             int64_t converted = 0;
             ret = util_parse_byte_size_string(opts->values[i], &converted);
             if (ret != 0) {
-                ERROR("Invalid size: '%s': %s", opts->values[i], strerror(-ret));
-                isulad_set_error_message("Invalid quota size: '%s': %s", opts->values[i], strerror(-ret));
+                errno = -ret;
+                SYSERROR("Invalid size: '%s'", opts->values[i]);
+                isulad_set_error_message("Invalid quota size: '%s'", opts->values[i]);
                 ret = -1;
                 goto out;
             }
diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
index 64022d89..b8916c76 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
@@ -105,7 +105,8 @@ static inline bool layer_store_lock(bool writable)
         nret = pthread_rwlock_rdlock(&g_metadata.rwlock);
     }
     if (nret != 0) {
-        ERROR("Lock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock memory store failed");
         return false;
     }
 
@@ -118,7 +119,8 @@ static inline void layer_store_unlock()
 
     nret = pthread_rwlock_unlock(&g_metadata.rwlock);
     if (nret != 0) {
-        FATAL("Unlock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Unlock memory store failed");
     }
 }
 
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
index 69022073..eb919321 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
@@ -39,7 +39,8 @@ static inline bool remote_refresh_lock(pthread_rwlock_t *remote_lock, bool writa
         nret = pthread_rwlock_rdlock(remote_lock);
     }
     if (nret != 0) {
-        ERROR("Lock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock memory store failed");
         return false;
     }
 
@@ -52,7 +53,8 @@ static inline void remote_refresh_unlock(pthread_rwlock_t *remote_lock)
 
     nret = pthread_rwlock_unlock(remote_lock);
     if (nret != 0) {
-        FATAL("Unlock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Unlock memory store failed");
     }
 }
 
diff --git a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
index c0a2a400..271158e7 100644
--- a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
+++ b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
@@ -71,7 +71,8 @@ static inline bool rootfs_store_lock(enum lock_type type)
     }
 
     if (nret != 0) {
-        ERROR("Lock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock memory store failed");
         return false;
     }
 
@@ -84,7 +85,8 @@ static inline void rootfs_store_unlock()
 
     nret = pthread_rwlock_unlock(&g_rootfs_store->rwlock);
     if (nret != 0) {
-        FATAL("Unlock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Unlock memory store failed");
     }
 }
 
diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c
index fbaae3fc..255ec89c 100644
--- a/src/daemon/modules/image/oci/storage/storage.c
+++ b/src/daemon/modules/image/oci/storage/storage.c
@@ -61,7 +61,8 @@ static inline bool storage_lock(pthread_rwlock_t *store_lock, bool writable)
         nret = pthread_rwlock_rdlock(store_lock);
     }
     if (nret != 0) {
-        ERROR("Lock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Lock memory store failed");
         return false;
     }
 
@@ -74,7 +75,8 @@ static inline void storage_unlock(pthread_rwlock_t *store_lock)
 
     nret = pthread_rwlock_unlock(store_lock);
     if (nret != 0) {
-        FATAL("Unlock memory store failed: %s", strerror(nret));
+        errno = nret;
+        SYSERROR("Unlock memory store failed");
     }
 }
 
diff --git a/src/daemon/modules/plugin/plugin.c b/src/daemon/modules/plugin/plugin.c
index b4d78dc9..c42cfd21 100644
--- a/src/daemon/modules/plugin/plugin.c
+++ b/src/daemon/modules/plugin/plugin.c
@@ -409,7 +409,8 @@ static void pm_rdlock(void)
 
     errcode = pthread_rwlock_rdlock(&g_plugin_manager->pm_rwlock);
     if (errcode != 0) {
-        ERROR("Read lock failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Read lock failed");
     }
 }
 
@@ -419,7 +420,8 @@ static void pm_wrlock(void)
 
     errcode = pthread_rwlock_wrlock(&g_plugin_manager->pm_rwlock);
     if (errcode != 0) {
-        ERROR("Write lock failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Write lock failed");
     }
 }
 
@@ -429,7 +431,8 @@ static void pm_unlock(void)
 
     errcode = pthread_rwlock_unlock(&g_plugin_manager->pm_rwlock);
     if (errcode != 0) {
-        ERROR("Unlock failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Unlock failed");
     }
 }
 
@@ -659,7 +662,8 @@ static void *plugin_manager_routine(void *arg)
 
     errcode = pthread_detach(pthread_self());
     if (errcode != 0) {
-        ERROR("Detach thread failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Detach thread failed");
         return NULL;
     }
     if (pm_init() < 0) {
@@ -716,7 +720,8 @@ static void plugin_rdlock(plugin_t *plugin)
 
     errcode = pthread_rwlock_rdlock(&plugin->lock);
     if (errcode != 0) {
-        ERROR("Plugin read lock failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Plugin read lock failed");
     }
 }
 
@@ -726,7 +731,8 @@ static void plugin_wrlock(plugin_t *plugin)
 
     errcode = pthread_rwlock_wrlock(&plugin->lock);
     if (errcode != 0) {
-        ERROR("Plugin write lock failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Plugin write lock failed");
     }
 }
 
@@ -736,7 +742,8 @@ static void plugin_unlock(plugin_t *plugin)
 
     errcode = pthread_rwlock_unlock(&plugin->lock);
     if (errcode != 0) {
-        ERROR("Plugin unlock failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Plugin unlock failed");
     }
 }
 
@@ -758,7 +765,8 @@ plugin_t *plugin_new(const char *name, const char *addr)
 
     errcode = pthread_rwlock_init(&plugin->lock, NULL);
     if (errcode != 0) {
-        ERROR("Plugin init lock failed: %s", strerror(errcode));
+        errno = errcode;
+        SYSERROR("Plugin init lock failed");
         goto bad;
     }
     plugin->name = util_strdup_s(name);
diff --git a/src/daemon/modules/service/network_namespace_api.c b/src/daemon/modules/service/network_namespace_api.c
index 11246ffb..236940fe 100644
--- a/src/daemon/modules/service/network_namespace_api.c
+++ b/src/daemon/modules/service/network_namespace_api.c
@@ -55,7 +55,8 @@ int remove_network_namespace(const char *netns_path)
     }
 
     if (!util_force_remove_file(netns_path, &get_err)) {
-        ERROR("Failed to remove file %s, error: %s", netns_path, strerror(get_err));
+        errno = get_err;
+        SYSERROR("Failed to remove file %s", netns_path);
         return -1;
     }
 
@@ -77,7 +78,8 @@ int remove_network_namespace_file(const char *netns_path)
     }
 
     if (!util_force_remove_file(netns_path, &get_err)) {
-        ERROR("Failed to remove file %s, error: %s", netns_path, strerror(get_err));
+        errno = get_err;
+        SYSERROR("Failed to remove file %s", netns_path);
         return -1;
     }
 
diff --git a/src/utils/cutils/utils_file.c b/src/utils/cutils/utils_file.c
index 749cdb16..f5b645ca 100644
--- a/src/utils/cutils/utils_file.c
+++ b/src/utils/cutils/utils_file.c
@@ -1071,7 +1071,9 @@ char *look_path(const char *file, char **err)
         if (en == 0) {
             return util_strdup_s(file);
         }
-        if (asprintf(err, "find exec %s : %s", file, strerror(en)) < 0) {
+        errno = en;
+        SYSERROR("find exec %s failed", file);
+        if (asprintf(err, "find exec %s failed", file) < 0) {
             *err = util_strdup_s("Out of memory");
         }
         return NULL;
-- 
2.40.1

