From 3536723347722180d8964edf7687bef6343edc77 Mon Sep 17 00:00:00 2001 From: haozi007 Date: Mon, 4 Sep 2023 10:44:35 +0800 Subject: [PATCH 09/33] remove unneccessary strerror 1. use SYS-log to replace log; 2. remove unuseful strerror; Signed-off-by: haozi007 --- src/cmd/isula/base/create.c | 4 +- src/cmd/isula/base/start.c | 2 +- src/cmd/isula/extend/export.c | 2 +- src/cmd/isula/images/images.c | 2 +- src/cmd/isula/images/import.c | 2 +- src/cmd/isula/images/load.c | 2 +- src/cmd/isula/images/login.c | 6 +- src/cmd/isula/isula_host_spec.c | 2 +- src/cmd/isula/stream/attach.c | 2 +- src/cmd/isula/stream/exec.c | 4 +- src/cmd/isulad/main.c | 18 +-- src/daemon/common/cgroup.c | 4 +- src/daemon/common/sysinfo.c | 6 +- src/daemon/entry/connect/grpc/grpc_service.cc | 2 +- src/daemon/entry/connect/rest/rest_service.c | 4 +- .../entry/cri/streams/websocket/ws_server.cc | 8 +- .../cri_pod_sandbox_manager_service.cc | 2 +- src/daemon/executor/container_cb/execution.c | 8 +- .../container_cb/execution_information.c | 2 +- .../executor/container_cb/execution_stream.c | 20 +-- .../container/container_gc/containers_gc.c | 4 +- src/daemon/modules/container/container_unix.c | 2 +- .../container/leftover_cleanup/cleanup.c | 2 +- .../modules/container/supervisor/supervisor.c | 6 +- src/daemon/modules/events/monitord.c | 8 +- .../modules/events_sender/event_sender.c | 2 +- .../modules/image/embedded/db/sqlite_common.c | 2 +- src/daemon/modules/image/external/ext_image.c | 2 +- .../modules/image/image_rootfs_handler.c | 4 +- src/daemon/modules/image/oci/oci_load.c | 2 +- .../modules/image/oci/registry/registry.c | 11 +- .../graphdriver/devmapper/deviceset.c | 10 +- .../graphdriver/devmapper/wrapper_devmapper.c | 4 +- .../oci/storage/layer_store/layer_store.c | 10 +- .../modules/image/oci/storage/storage.c | 2 +- src/daemon/modules/image/oci/utils_images.c | 6 +- src/daemon/modules/log/log_gather.c | 18 +-- .../network/cni_operator/libcni/libcni_conf.c | 2 +- .../modules/runtime/engines/lcr/lcr_rt_ops.c | 6 +- .../modules/runtime/isula/isula_rt_ops.c | 10 +- .../modules/runtime/shim/shim_rt_monitor.cc | 2 +- src/daemon/modules/runtime/shim/shim_rt_ops.c | 4 +- src/daemon/modules/service/io_handler.c | 4 +- .../modules/service/service_container.c | 13 +- src/daemon/modules/service/service_network.c | 6 +- src/daemon/modules/spec/specs.c | 2 +- src/daemon/modules/spec/specs_mount.c | 2 +- src/daemon/modules/spec/verify.c | 6 +- src/daemon/modules/volume/local.c | 12 +- src/daemon/sandbox/sandbox.cc | 2 +- src/utils/console/console.c | 16 +-- src/utils/cutils/network_namespace.c | 2 +- src/utils/cutils/path.c | 4 +- src/utils/cutils/utils.c | 12 +- src/utils/cutils/utils_aes.c | 16 +-- src/utils/cutils/utils_base64.c | 4 +- src/utils/cutils/utils_file.c | 80 ++++++------ src/utils/cutils/utils_fs.c | 12 +- src/utils/cutils/utils_port.c | 14 +-- src/utils/cutils/utils_verify.c | 2 +- src/utils/http/http.c | 2 +- src/utils/sha256/sha256.c | 8 +- src/utils/tar/isulad_tar.c | 12 +- src/utils/tar/util_archive.c | 118 ++++++++---------- src/utils/tar/util_gzip.c | 12 +- 65 files changed, 282 insertions(+), 300 deletions(-) diff --git a/src/cmd/isula/base/create.c b/src/cmd/isula/base/create.c index ecb197bc..aa90c5d6 100644 --- a/src/cmd/isula/base/create.c +++ b/src/cmd/isula/base/create.c @@ -1945,7 +1945,7 @@ static int check_hook_spec_file(const char *hook_spec) return -1; } if (stat(hook_spec, &hookstat)) { - COMMAND_ERROR("Stat hook spec file failed: %s", strerror(errno)); + CMD_SYSERROR("Stat hook spec file failed"); return -1; } if ((hookstat.st_mode & S_IFMT) != S_IFREG) { @@ -1987,7 +1987,7 @@ static int create_check_rootfs(struct client_arguments *args) if (args->create_rootfs != NULL) { char real_path[PATH_MAX] = { 0 }; if (realpath(args->create_rootfs, real_path) == NULL) { - COMMAND_ERROR("Failed to get rootfs '%s': %s", args->create_rootfs, strerror(errno)); + CMD_SYSERROR("Failed to get rootfs '%s'.", args->create_rootfs); ret = -1; goto out; } diff --git a/src/cmd/isula/base/start.c b/src/cmd/isula/base/start.c index ca3634e1..1d0f1256 100644 --- a/src/cmd/isula/base/start.c +++ b/src/cmd/isula/base/start.c @@ -200,7 +200,7 @@ void client_wait_fifo_exit(const struct client_arguments *args) void client_restore_console(bool reset_tty, const struct termios *oldtios, struct command_fifo_config *console_fifos) { if (reset_tty && tcsetattr(0, TCSAFLUSH, oldtios) < 0) { - WARN("Failed to reset terminal properties: %s.", strerror(errno)); + SYSWARN("Failed to reset terminal properties."); } free_command_fifo_config(console_fifos); sem_destroy(&g_console_waitopen_sem); diff --git a/src/cmd/isula/extend/export.c b/src/cmd/isula/extend/export.c index 68d17c82..d8f3574c 100644 --- a/src/cmd/isula/extend/export.c +++ b/src/cmd/isula/extend/export.c @@ -114,7 +114,7 @@ int cmd_export_main(int argc, const char **argv) int sret; char cwd[PATH_MAX] = { 0 }; if (!getcwd(cwd, sizeof(cwd))) { - COMMAND_ERROR("get cwd failed:%s", strerror(errno)); + CMD_SYSERROR("get cwd failed"); exit(ECOMMON); } sret = snprintf(file, sizeof(file), "%s/%s", cwd, g_cmd_export_args.file); diff --git a/src/cmd/isula/images/images.c b/src/cmd/isula/images/images.c index bff07f76..bd9dc18b 100644 --- a/src/cmd/isula/images/images.c +++ b/src/cmd/isula/images/images.c @@ -65,7 +65,7 @@ static char *trans_time(int64_t created) time_t created_time = (time_t)created; if (!localtime_r(&created_time, &t)) { - ERROR("translate time for created failed: %s", strerror(errno)); + SYSERROR("translate time for created failed."); return NULL; } diff --git a/src/cmd/isula/images/import.c b/src/cmd/isula/images/import.c index 7b6eb2a9..f28fe04c 100644 --- a/src/cmd/isula/images/import.c +++ b/src/cmd/isula/images/import.c @@ -126,7 +126,7 @@ int cmd_import_main(int argc, const char **argv) int len = 0; if (!getcwd(cwd, sizeof(cwd))) { - COMMAND_ERROR("get cwd failed:%s", strerror(errno)); + CMD_SYSERROR("get cwd failed"); exit(exit_code); } diff --git a/src/cmd/isula/images/load.c b/src/cmd/isula/images/load.c index 688edd02..314e5d5e 100644 --- a/src/cmd/isula/images/load.c +++ b/src/cmd/isula/images/load.c @@ -150,7 +150,7 @@ int cmd_load_main(int argc, const char **argv) int len; if (!getcwd(cwd, sizeof(cwd))) { - COMMAND_ERROR("get cwd failed:%s", strerror(errno)); + CMD_SYSERROR("get cwd failed"); exit(exit_code); } diff --git a/src/cmd/isula/images/login.c b/src/cmd/isula/images/login.c index c35cb579..1c3b06ea 100644 --- a/src/cmd/isula/images/login.c +++ b/src/cmd/isula/images/login.c @@ -99,7 +99,7 @@ static int get_password_from_notty(struct client_arguments *args) return -1; } if (n < 0) { - COMMAND_ERROR("Get password from notty stdin failed: %s", strerror(errno)); + CMD_SYSERROR("Get password from notty stdin failed"); return -1; } args->password = util_strdup_s(password); @@ -126,7 +126,7 @@ static int get_auth_from_terminal(struct client_arguments *args) COMMAND_ERROR("Error: Cannot perform an interactive login from a non TTY device"); return -1; } - COMMAND_ERROR("Get username failed: %s", strerror(errno)); + CMD_SYSERROR("Get username failed"); return -1; } args->username = util_strdup_s(username); @@ -145,7 +145,7 @@ static int get_auth_from_terminal(struct client_arguments *args) COMMAND_ERROR("Error: Cannot perform an interactive login from a non TTY device"); return -1; } - COMMAND_ERROR("Get password failed: %s", strerror(errno)); + CMD_SYSERROR("Get password failed"); return -1; } args->password = util_strdup_s(password); diff --git a/src/cmd/isula/isula_host_spec.c b/src/cmd/isula/isula_host_spec.c index 765c44c0..9fa08bd2 100644 --- a/src/cmd/isula/isula_host_spec.c +++ b/src/cmd/isula/isula_host_spec.c @@ -771,7 +771,7 @@ uint64_t get_proc_mem_size(const char *item) fp = util_fopen("/proc/meminfo", "r"); if (fp == NULL) { - ERROR("Failed to open /proc/meminfo: %s", strerror(errno)); + SYSERROR("Failed to open /proc/meminfo"); return sysmem_limit; } diff --git a/src/cmd/isula/stream/attach.c b/src/cmd/isula/stream/attach.c index 02c67e30..ff49af92 100644 --- a/src/cmd/isula/stream/attach.c +++ b/src/cmd/isula/stream/attach.c @@ -376,7 +376,7 @@ static int client_attach(struct client_arguments *args, uint32_t *exit_code) if (errno == ETIMEDOUT) { COMMAND_ERROR("Wait container status timeout."); } else { - COMMAND_ERROR("Failed to wait sem: %s", strerror(errno)); + CMD_SYSERROR("Failed to wait sem"); } ret = ECOMMON; goto out; diff --git a/src/cmd/isula/stream/exec.c b/src/cmd/isula/stream/exec.c index bd8bd49a..209610be 100644 --- a/src/cmd/isula/stream/exec.c +++ b/src/cmd/isula/stream/exec.c @@ -356,7 +356,7 @@ static int remote_cmd_exec(const struct client_arguments *args, uint32_t *exit_c out: if (reset_tty && tcsetattr(0, TCSAFLUSH, &oldtios) < 0) { - WARN("Failed to reset terminal properties: %s.", strerror(errno)); + SYSWARN("Failed to reset terminal properties."); } if (response->exit_code != 0) { *exit_code = response->exit_code; @@ -387,7 +387,7 @@ out: sem_destroy(&g_command_waitopen_sem); sem_destroy(&g_command_waitexit_sem); if (reset_tty && tcsetattr(0, TCSAFLUSH, &oldtios) < 0) { - WARN("Failed to reset terminal properties: %s.", strerror(errno)); + SYSWARN("Failed to reset terminal properties."); } return ret; } diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c index b32b6626..39cde6aa 100644 --- a/src/cmd/isulad/main.c +++ b/src/cmd/isulad/main.c @@ -179,7 +179,7 @@ static int mount_rootfs_mnt_dir(const char *mountdir) if (info == NULL) { ret = mount(rootfsdir, rootfsdir, "bind", MS_BIND | MS_REC, NULL); if (ret < 0) { - ERROR("Failed to mount parent directory %s:%s", rootfsdir, strerror(errno)); + SYSERROR("Failed to mount parent directory %s.", rootfsdir); goto out; } } @@ -212,7 +212,7 @@ static int umount_rootfs_mnt_dir(const char *mntdir) ret = umount(dir); if (ret < 0 && errno != EINVAL) { - WARN("Failed to umount parent directory %s:%s", dir, strerror(errno)); + SYSWARN("Failed to umount parent directory %s.", dir); goto out; } @@ -252,7 +252,7 @@ static void clean_residual_files() if (checked_flag == NULL) { ERROR("Failed to get image checked flag file path"); } else if (unlink_ignore_enoent(checked_flag)) { - ERROR("Unlink file: %s error: %s", checked_flag, strerror(errno)); + SYSERROR("Unlink file: %s.", checked_flag); } free(checked_flag); @@ -261,7 +261,7 @@ static void clean_residual_files() if (fname == NULL) { ERROR("Failed to get isulad pid file path"); } else if (unlink(fname) && errno != ENOENT) { - WARN("Unlink file: %s error: %s", fname, strerror(errno)); + SYSWARN("Unlink file: %s.", fname); } free(fname); } @@ -472,7 +472,7 @@ int check_and_save_pid(const char *fn) ret = ftruncate(fd, 0); if (ret != 0) { - ERROR("Failed to truncate pid file:%s to 0: %s", fn, strerror(errno)); + SYSERROR("Failed to truncate pid file:%s to 0.", fn); ret = -1; goto out; } @@ -486,7 +486,7 @@ int check_and_save_pid(const char *fn) len = util_write_nointr(fd, pidbuf, strlen(pidbuf)); if (len < 0 || (size_t)len != strlen(pidbuf)) { - ERROR("Failed to write pid to file:%s: %s", fn, strerror(errno)); + SYSERROR("Failed to write pid to file:%s.", fn); ret = -1; } out: @@ -527,7 +527,7 @@ static int check_hook_spec_file(const char *hook_spec) return -1; } if (stat(hook_spec, &hookstat)) { - ERROR("Stat hook spec file failed: %s", strerror(errno)); + SYSERROR("Stat hook spec file failed."); return -1; } if ((hookstat.st_mode & S_IFMT) != S_IFREG) { @@ -589,7 +589,7 @@ static void update_isulad_rlimits() limit.rlim_cur = RLIM_INFINITY; limit.rlim_max = RLIM_INFINITY; if (setrlimit(RLIMIT_CORE, &limit)) { - SYSWARN("Can not set ulimit of RLIMIT_CORE"); + SYSWARN("Can not set ulimit of RLIMIT_CORE."); } } @@ -813,7 +813,7 @@ static int overlay_supports_selinux(bool *supported) *supported = false; fp = fopen("/proc/kallsyms", "re"); if (fp == NULL) { - ERROR("Failed to open /proc/kallsyms: %s", strerror(errno)); + SYSERROR("Failed to open /proc/kallsyms."); return -1; } __fsetlocking(fp, FSETLOCKING_BYCALLER); diff --git a/src/daemon/common/cgroup.c b/src/daemon/common/cgroup.c index a351704b..2d1cabb2 100644 --- a/src/daemon/common/cgroup.c +++ b/src/daemon/common/cgroup.c @@ -596,7 +596,7 @@ int common_get_cgroup_version(void) struct statfs fs = { 0 }; if (statfs(CGROUP_MOUNTPOINT, &fs) != 0) { - ERROR("failed to statfs %s: %s", CGROUP_MOUNTPOINT, strerror(errno)); + SYSERROR("failed to statfs %s", CGROUP_MOUNTPOINT); return -1; } @@ -649,7 +649,7 @@ static int cgroup2_enable_all() ret = util_write_file(CGROUP2_SUBTREE_CONTROLLER_PATH, enable_controllers, strlen(enable_controllers), DEFAULT_CGROUP_FILE_MODE); if (ret != 0) { - ERROR("write %s to %s failed: %s", enable_controllers, CGROUP2_SUBTREE_CONTROLLER_PATH, strerror(errno)); + SYSERROR("write %s to %s failed", enable_controllers, CGROUP2_SUBTREE_CONTROLLER_PATH); goto out; } diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c index c83ff12f..957b370b 100644 --- a/src/daemon/common/sysinfo.c +++ b/src/daemon/common/sysinfo.c @@ -108,7 +108,7 @@ uint64_t get_default_total_mem_size(void) fp = util_fopen("/proc/meminfo", "r"); if (fp == NULL) { - ERROR("Failed to open /proc/meminfo: %s", strerror(errno)); + SYSERROR("Failed to open /proc/meminfo."); return sysmem_limit; } @@ -148,10 +148,10 @@ char *get_operating_system(void) fp = fopen(etcOsRelease, "r"); if (fp == NULL) { - INFO("Failed to open %s :%s", etcOsRelease, strerror(errno)); + SYSINFO("Failed to open %s.", etcOsRelease); fp = fopen(altOsRelease, "r"); if (fp == NULL) { - ERROR("Failed to open %s :%s", altOsRelease, strerror(errno)); + SYSERROR("Failed to open %s.", altOsRelease); goto out; } } diff --git a/src/daemon/entry/connect/grpc/grpc_service.cc b/src/daemon/entry/connect/grpc/grpc_service.cc index 5adfd964..4e1ae019 100644 --- a/src/daemon/entry/connect/grpc/grpc_service.cc +++ b/src/daemon/entry/connect/grpc/grpc_service.cc @@ -117,7 +117,7 @@ public: for (const auto &address : m_socketPath) { if (address.find(UNIX_SOCKET_PREFIX) == 0) { if (unlink(address.c_str() + strlen(UNIX_SOCKET_PREFIX)) < 0 && errno != ENOENT) { - WARN("Failed to remove '%s':%s", address.c_str(), strerror(errno)); + SYSWARN("Failed to remove '%s'.", address.c_str()); } } } diff --git a/src/daemon/entry/connect/rest/rest_service.c b/src/daemon/entry/connect/rest/rest_service.c index 818e729d..c73fed66 100644 --- a/src/daemon/entry/connect/rest/rest_service.c +++ b/src/daemon/entry/connect/rest/rest_service.c @@ -149,7 +149,7 @@ int rest_server_init(const char *socket, daemon_shutdown_cb_t shutdown_cb) } if (unlink(g_socketpath + strlen(UNIX_SOCKET_PREFIX)) < 0 && errno != ENOENT) { - ERROR("Failed to remove '%s':%s, abort", strerror(errno), g_socketpath); + SYSERROR("Failed to remove '%s', abort", g_socketpath); goto error_out; } @@ -190,7 +190,7 @@ void rest_server_shutdown(void) if (g_socketpath != NULL) { if (unlink(g_socketpath + strlen(UNIX_SOCKET_PREFIX)) < 0 && errno != ENOENT) { - ERROR("Failed to remove '%s':%s", g_socketpath, strerror(errno)); + SYSERROR("Failed to remove '%s'.", g_socketpath); } } } diff --git a/src/daemon/entry/cri/streams/websocket/ws_server.cc b/src/daemon/entry/cri/streams/websocket/ws_server.cc index 3bb619d8..972c971f 100644 --- a/src/daemon/entry/cri/streams/websocket/ws_server.cc +++ b/src/daemon/entry/cri/streams/websocket/ws_server.cc @@ -133,7 +133,7 @@ int WebsocketServer::CreateContext() newLimit.rlim_max = WS_ULIMIT_FDS; int limited = prlimit(0, RLIMIT_NOFILE, &newLimit, &oldLimit); if (limited != 0) { - WARN("Can not set ulimit of RLIMIT_NOFILE: %s", strerror(errno)); + SYSWARN("Can not set ulimit of RLIMIT_NOFILE"); } m_context = lws_create_context(&info); if (m_context == nullptr) { @@ -142,7 +142,7 @@ int WebsocketServer::CreateContext() } if (limited == 0) { if (setrlimit(static_cast(RLIMIT_NOFILE), &oldLimit) != 0) { - WARN("Can not set ulimit of RLIMIT_NOFILE: %s", strerror(errno)); + SYSWARN("Can not set ulimit of RLIMIT_NOFILE"); } } @@ -441,7 +441,7 @@ void WebsocketServer::Receive(int socketID, void *in, size_t len, bool complete) DEBUG("Receive remaning stdin data with length %zu", len); // Too much data may cause error 'resource temporarily unavaliable' by using 'write' if (util_write_nointr_in_total(m_wsis[socketID]->pipes.at(1), static_cast(in), len) < 0) { - ERROR("Sub write over! err msg: %s", strerror(errno)); + SYSERROR("Sub write over!"); } goto out; } @@ -458,7 +458,7 @@ void WebsocketServer::Receive(int socketID, void *in, size_t len, bool complete) if (*static_cast(in) == WebsocketChannel::STDINCHANNEL) { if (util_write_nointr_in_total(m_wsis[socketID]->pipes.at(1), static_cast(in) + 1, len - 1) < 0) { - ERROR("Sub write over! err msg: %s", strerror(errno)); + SYSERROR("Sub write over!"); } goto out; } diff --git a/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc b/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc index c24c1f69..6e8f40b9 100644 --- a/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc +++ b/src/daemon/entry/cri/v1alpha/cri_pod_sandbox_manager_service.cc @@ -853,7 +853,7 @@ auto PodSandboxManagerService::ClearCniNetwork(const std::string &realSandboxID, } // umount netns when cni removed network successfully if (remove_network_namespace(netnsPath.c_str()) != 0) { - ERROR("Failed to umount directory %s:%s", netnsPath.c_str(), strerror(errno)); + SYSERROR("Failed to umount directory %s.", netnsPath.c_str()); } } diff --git a/src/daemon/executor/container_cb/execution.c b/src/daemon/executor/container_cb/execution.c index dbfec59e..d3571b7f 100644 --- a/src/daemon/executor/container_cb/execution.c +++ b/src/daemon/executor/container_cb/execution.c @@ -277,7 +277,7 @@ static int prepare_start_io(container_t *cont, const container_start_request *re *sync_fd = eventfd(0, EFD_CLOEXEC); if (*sync_fd < 0) { - ERROR("Failed to create eventfd: %s", strerror(errno)); + SYSERROR("Failed to create eventfd."); ret = -1; goto out; } @@ -344,13 +344,13 @@ static int maybe_create_cpu_realtime_file(int64_t value, const char *file, const fd = util_open(fpath, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0700); if (fd < 0) { - ERROR("Failed to open file: %s: %s", fpath, strerror(errno)); + SYSERROR("Failed to open file: %s.", fpath); isulad_set_error_message("Failed to open file: %s: %s", fpath, strerror(errno)); return -1; } nwrite = util_write_nointr(fd, buf, strlen(buf)); if (nwrite < 0 || (size_t)nwrite != strlen(buf)) { - ERROR("Failed to write %s to %s: %s", buf, fpath, strerror(errno)); + SYSERROR("Failed to write %s to %s.", buf, fpath); isulad_set_error_message("Failed to write '%s' to '%s': %s", buf, fpath, strerror(errno)); return -1; } @@ -485,7 +485,7 @@ static void handle_start_io_thread_by_cc(uint32_t cc, int sync_fd, pthread_t thr } else { if (sync_fd >= 0) { if (eventfd_write(sync_fd, 1) < 0) { - ERROR("Failed to write eventfd: %s", strerror(errno)); + SYSERROR("Failed to write eventfd."); } } if (thread_id > 0) { diff --git a/src/daemon/executor/container_cb/execution_information.c b/src/daemon/executor/container_cb/execution_information.c index 93e5032e..2f3d3627 100644 --- a/src/daemon/executor/container_cb/execution_information.c +++ b/src/daemon/executor/container_cb/execution_information.c @@ -522,7 +522,7 @@ void execute_ps_command(char **args, const char *pid_args, size_t args_len) execvp("ps", params); - COMMAND_ERROR("Cannot get ps info with '%s':%s", pid_args, strerror(errno)); + CMD_SYSERROR("Cannot get ps info with '%s'.", pid_args); out: exit(EXIT_FAILURE); diff --git a/src/daemon/executor/container_cb/execution_stream.c b/src/daemon/executor/container_cb/execution_stream.c index 244ec6a0..7e84cca3 100644 --- a/src/daemon/executor/container_cb/execution_stream.c +++ b/src/daemon/executor/container_cb/execution_stream.c @@ -265,7 +265,7 @@ static int attach_prepare_console(const container_t *cont, const container_attac *sync_fd = eventfd(0, EFD_CLOEXEC); if (*sync_fd < 0) { - ERROR("Failed to create eventfd: %s", strerror(errno)); + SYSERROR("Failed to create eventfd."); ret = -1; goto out; } @@ -295,7 +295,7 @@ static void handle_attach_io_thread_by_cc(uint32_t cc, int sync_fd, pthread_t th } else { if (sync_fd >= 0) { if (eventfd_write(sync_fd, 1) < 0) { - ERROR("Failed to write eventfd: %s", strerror(errno)); + SYSERROR("Failed to write eventfd."); } } if (thread_id > 0) { @@ -535,7 +535,7 @@ static container_path_stat *do_container_stat_path(const char *rootpath, const c nret = lstat(resolvedpath, &st); if (nret < 0) { - ERROR("lstat %s: %s", resolvedpath, strerror(errno)); + SYSERROR("lstat %s failed.", resolvedpath); isulad_set_error_message("lstat %s: %s", resolvedpath, strerror(errno)); goto cleanup; } @@ -921,7 +921,7 @@ static int copy_to_container_check_path_valid(const container_t *cont, const cha nret = lstat(resolvedpath, &st); if (nret < 0) { - ERROR("lstat %s: %s", resolvedpath, strerror(errno)); + SYSERROR("lstat %s failed", resolvedpath); isulad_set_error_message("lstat %s: %s", resolvedpath, strerror(errno)); goto cleanup; } @@ -1092,11 +1092,11 @@ static int64_t do_read_log_file(const char *path, int64_t require_line, long pos util_usleep_nointerupt(1000); } if (fp == NULL) { - ERROR("open file: %s failed: %s", path, strerror(errno)); + SYSERROR("open file: %s failed.", path); return -1; } if (pos > 0 && fseek(fp, pos, SEEK_SET) != 0) { - ERROR("fseek to %ld failed: %s", pos, strerror(errno)); + SYSERROR("fseek to %ld failed.", pos); read_lines = -1; goto out; } @@ -1211,12 +1211,12 @@ static int do_tail_find(FILE *fp, int64_t require_line, int64_t *get_line, long int ret = -1; if (fseek(fp, 0L, SEEK_END) != 0) { - ERROR("Fseek failed: %s", strerror(errno)); + SYSERROR("Fseek failed"); goto out; } len = ftell(fp); if (len < 0) { - ERROR("Ftell failed: %s", strerror(errno)); + SYSERROR("Ftell failed"); goto out; } if (len < SECTION_SIZE) { @@ -1228,7 +1228,7 @@ static int do_tail_find(FILE *fp, int64_t require_line, int64_t *get_line, long } while (true) { if (fseek(fp, pos, SEEK_SET) != 0) { - ERROR("Fseek failed: %s", strerror(errno)); + SYSERROR("Fseek failed"); goto out; } read_size = fread(buffer, sizeof(char), (size_t)step_size, fp); @@ -1275,7 +1275,7 @@ static int util_find_tail_position(const char *file_name, int64_t require_line, fp = util_fopen(file_name, "rb"); if (fp == NULL) { - ERROR("open file: %s failed: %s", file_name, strerror(errno)); + SYSERROR("open file: %s failed.", file_name); return -1; } diff --git a/src/daemon/modules/container/container_gc/containers_gc.c b/src/daemon/modules/container/container_gc/containers_gc.c index 9feb6d3c..8d0647ab 100644 --- a/src/daemon/modules/container/container_gc/containers_gc.c +++ b/src/daemon/modules/container/container_gc/containers_gc.c @@ -83,14 +83,14 @@ static int save_gc_config(const char *json_gc_config) fd = util_open(filename, O_CREAT | O_TRUNC | O_CLOEXEC | O_WRONLY, CONFIG_FILE_MODE); if (fd == -1) { - ERROR("Create file %s failed: %s", filename, strerror(errno)); + SYSERROR("Create file %s failed.", filename); ret = -1; goto out; } nret = util_write_nointr(fd, json_gc_config, strlen(json_gc_config)); if (nret < 0 || (size_t)nret != strlen(json_gc_config)) { - ERROR("write %s failed: %s", filename, strerror(errno)); + SYSERROR("write %s failed.", filename); ret = -1; } close(fd); diff --git a/src/daemon/modules/container/container_unix.c b/src/daemon/modules/container/container_unix.c index 07d9a0e8..e8c98441 100644 --- a/src/daemon/modules/container/container_unix.c +++ b/src/daemon/modules/container/container_unix.c @@ -517,7 +517,7 @@ static int save_json_config_file(const char *id, const char *rootpath, const cha nret = util_atomic_write_file(filename, json_data, strlen(json_data), CONFIG_FILE_MODE, false); if (nret != 0) { - ERROR("Write file %s failed: %s", filename, strerror(errno)); + SYSERROR("Write file %s failed.", filename); isulad_set_error_message("Write file '%s' failed: %s", filename, strerror(errno)); ret = -1; } diff --git a/src/daemon/modules/container/leftover_cleanup/cleanup.c b/src/daemon/modules/container/leftover_cleanup/cleanup.c index c86e3db9..9a38ffc2 100644 --- a/src/daemon/modules/container/leftover_cleanup/cleanup.c +++ b/src/daemon/modules/container/leftover_cleanup/cleanup.c @@ -158,7 +158,7 @@ static bool walk_isulad_tmpdir_cb(const char *path_name, const struct dirent *su if (util_detect_mounted(tmpdir)) { if (umount(tmpdir) != 0) { - ERROR("Failed to umount target %s, error: %s", tmpdir, strerror(errno)); + SYSERROR("Failed to umount target %s", tmpdir); } } diff --git a/src/daemon/modules/container/supervisor/supervisor.c b/src/daemon/modules/container/supervisor/supervisor.c index 3ce4ec1e..829e48b1 100644 --- a/src/daemon/modules/container/supervisor/supervisor.c +++ b/src/daemon/modules/container/supervisor/supervisor.c @@ -104,7 +104,7 @@ char *container_exit_fifo_create(const char *cont_state_path) ret = mknod(fifo_path, S_IFIFO | S_IRUSR | S_IWUSR, (dev_t)0); if (ret < 0 && errno != EEXIST) { - ERROR("Failed to mknod exit monitor fifo %s: %s.", fifo_path, strerror(errno)); + SYSERROR("Failed to mknod exit monitor fifo %s.", fifo_path); return NULL; } @@ -128,7 +128,7 @@ int container_exit_fifo_open(const char *cont_exit_fifo) ret = util_open(cont_exit_fifo, O_RDONLY | O_NONBLOCK, 0); if (ret < 0) { - ERROR("Failed to open exit monitor FIFO %s: %s.", cont_exit_fifo, strerror(errno)); + SYSERROR("Failed to open exit monitor FIFO %s.", cont_exit_fifo); ret = -1; goto out; } @@ -324,7 +324,7 @@ restart: if (ret == 0) { goto restart; } - ERROR("Mainloop returned an error: %s", strerror(errno)); + SYSERROR("Mainloop returned an error"); epoll_loop_close(&g_supervisor_descr); diff --git a/src/daemon/modules/events/monitord.c b/src/daemon/modules/events/monitord.c index 775fb9ab..9edded7a 100644 --- a/src/daemon/modules/events/monitord.c +++ b/src/daemon/modules/events/monitord.c @@ -113,18 +113,18 @@ static void *monitored(void *arg) mhandler.fifo_path = fifo_file_path; if (mknod(fifo_file_path, S_IFIFO | S_IRUSR | S_IWUSR, (dev_t)0) && errno != EEXIST) { - ERROR("Create monitored fifo file failed: %s", strerror(errno)); + SYSERROR("Create monitored fifo file failed"); goto err; } mhandler.fifo_fd = util_open(fifo_file_path, O_RDWR | O_NONBLOCK | O_CLOEXEC, 0); if (mhandler.fifo_fd == -1) { - ERROR("Open monitored fifo file failed: %s", strerror(errno)); + SYSERROR("Open monitored fifo file failed"); goto err; } if (fcntl(mhandler.fifo_fd, F_SETPIPE_SZ, EVENTS_FIFO_SIZE) == -1) { - ERROR("Set events fifo buffer size failed: %s\n", strerror(errno)); + SYSERROR("Set events fifo buffer size failed"); goto err; } @@ -150,7 +150,7 @@ static void *monitored(void *arg) ret = epoll_loop(&descr, -1); } while (ret == 0); - ERROR("Mainloop returned an error: %s", strerror(errno)); + SYSERROR("Mainloop returned an error"); goto err2; err: diff --git a/src/daemon/modules/events_sender/event_sender.c b/src/daemon/modules/events_sender/event_sender.c index a3903f3e..13f3c3e3 100644 --- a/src/daemon/modules/events_sender/event_sender.c +++ b/src/daemon/modules/events_sender/event_sender.c @@ -52,7 +52,7 @@ static void isulad_monitor_fifo_send(const struct monitord_msg *msg) goto out; } - ERROR("Failed to open fifo to send message: %s.", strerror(errno)); + SYSERROR("Failed to open fifo to send message."); goto out; } diff --git a/src/daemon/modules/image/embedded/db/sqlite_common.c b/src/daemon/modules/image/embedded/db/sqlite_common.c index 42fdf6d9..89f834a0 100644 --- a/src/daemon/modules/image/embedded/db/sqlite_common.c +++ b/src/daemon/modules/image/embedded/db/sqlite_common.c @@ -49,7 +49,7 @@ int db_sqlite_init(const char *dbpath) goto cleanup; } if (chmod(dbpath, DEFAULT_SECURE_FILE_MODE) != 0) { - ERROR("Change mode of db file failed: %s", strerror(errno)); + SYSERROR("Change mode of db file failed."); goto cleanup; } return 0; diff --git a/src/daemon/modules/image/external/ext_image.c b/src/daemon/modules/image/external/ext_image.c index d918f4ce..10af82a3 100644 --- a/src/daemon/modules/image/external/ext_image.c +++ b/src/daemon/modules/image/external/ext_image.c @@ -65,7 +65,7 @@ int ext_prepare_rf(const im_prepare_request *request, char **real_rootfs) return -1; } if (realpath(request->rootfs, real_path) == NULL) { - ERROR("Failed to clean rootfs path '%s': %s", request->rootfs, strerror(errno)); + SYSERROR("Failed to clean rootfs path '%s'", request->rootfs); isulad_set_error_message("Failed to clean rootfs path '%s': %s", request->rootfs, strerror(errno)); return -1; } diff --git a/src/daemon/modules/image/image_rootfs_handler.c b/src/daemon/modules/image/image_rootfs_handler.c index 1275658e..1a3f4307 100644 --- a/src/daemon/modules/image/image_rootfs_handler.c +++ b/src/daemon/modules/image/image_rootfs_handler.c @@ -434,7 +434,7 @@ static int read_user_file(const char *basefs, const char *user_path, FILE **stre *stream = util_fopen(real_path, "r"); if (*stream == NULL) { - WARN("Failed to open %s: %s", real_path, strerror(errno)); + SYSWARN("Failed to open %s.", real_path); ret = 0; goto out; } @@ -455,7 +455,7 @@ static int resolve_basefs(const char *basefs, char **resolved_basefs) } if (stat(real_path, &s) < 0) { - ERROR("stat failed, error: %s", strerror(errno)); + SYSERROR("stat failed."); return -1; } diff --git a/src/daemon/modules/image/oci/oci_load.c b/src/daemon/modules/image/oci/oci_load.c index 4385e55e..d2efab81 100644 --- a/src/daemon/modules/image/oci/oci_load.c +++ b/src/daemon/modules/image/oci/oci_load.c @@ -1045,7 +1045,7 @@ static char *oci_load_path_create() } if (mkdtemp(tmp_dir) == NULL) { - ERROR("make temporary dir failed: %s", strerror(errno)); + SYSERROR("make temporary dir failed"); isulad_try_set_error_message("make temporary dir failed: %s", strerror(errno)); ret = -1; goto out; diff --git a/src/daemon/modules/image/oci/registry/registry.c b/src/daemon/modules/image/oci/registry/registry.c index 62d0c35e..5c660bc9 100644 --- a/src/daemon/modules/image/oci/registry/registry.c +++ b/src/daemon/modules/image/oci/registry/registry.c @@ -445,7 +445,7 @@ static int add_cached_layer(char *blob_digest, char *file, thread_fetch_info *in } if (link(src_file, file) != 0) { - ERROR("link %s to %s failed: %s", src_file, file, strerror(errno)); + SYSERROR("link %s to %s failed", src_file, file); ret = -1; goto out; } @@ -1147,7 +1147,7 @@ static void set_cached_layers_info(char *blob_digest, char *diffid, int result, continue; } if (link(src_file, elem->file) != 0) { - ERROR("link %s to %s failed: %s", src_file, elem->file, strerror(errno)); + SYSERROR("link %s to %s failed", src_file, elem->file); info->desc->cancel = true; continue; } @@ -1429,8 +1429,7 @@ static void *register_layers_in_thread(void *arg) // here we can't just break and cleanup resources because threads are running. // desc is freed if we break and then isulad crash. sleep some time // instead to avoid cpu full running and then retry. - ERROR("condition wait for layer %zu to complete failed, ret %d, error: %s", i, cond_ret, - strerror(errno)); + SYSERROR("condition wait for layer %zu to complete failed, ret %d", i, cond_ret); sleep(10); continue; } @@ -1615,7 +1614,7 @@ static int fetch_all(pull_descriptor *desc) // here we can't just break and cleanup resources because threads are running. // desc is freed if we break and then isulad crash. sleep some time // instead to avoid cpu full running and then retry. - ERROR("condition wait for all layers to complete failed, ret %d, error: %s", cond_ret, strerror(errno)); + SYSERROR("condition wait for all layers to complete failed, ret %d", cond_ret); sleep(10); continue; } @@ -1909,7 +1908,7 @@ static int prepare_pull_desc(pull_descriptor *desc, registry_pull_options *optio } if (mkdtemp(blobpath) == NULL) { - ERROR("make temporary direcory failed: %s", strerror(errno)); + SYSERROR("make temporary direcory failed"); ret = -1; goto out; } 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 e2fcf37c..81e53ea7 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 @@ -780,7 +780,7 @@ static int device_file_walk(struct device_set *devset) } if (stat(fname, &st) != 0) { - ERROR("devmapper: get %s stat error:%s", fname, strerror(errno)); + SYSERROR("devmapper: get %s stat failed", fname); ret = -1; goto out; } @@ -2202,7 +2202,7 @@ static int grow_fs(struct device_set *devset, image_devmapper_device_info *info) clean_mount: if (umount2(FS_MOUNT_POINT, MNT_DETACH) < 0 && errno != EINVAL) { - WARN("Failed to umount directory %s:%s", FS_MOUNT_POINT, strerror(errno)); + SYSWARN("Failed to umount directory %s", FS_MOUNT_POINT); } out: @@ -3148,7 +3148,7 @@ int unmount_device(const char *hash, const char *mount_path, struct device_set * } if (umount2(mount_path, MNT_DETACH) < 0 && errno != EINVAL) { - ERROR("Failed to umount directory %s:%s", mount_path, strerror(errno)); + SYSERROR("Failed to umount directory %s", mount_path); ret = -1; goto free_out; } @@ -3405,7 +3405,7 @@ static int umount_deactivate_dev_all(const struct device_set *devset) } if (stat(fname, &st) != 0) { - ERROR("devmapper: get %s stat error:%s", fname, strerror(errno)); + SYSERROR("devmapper: get %s stat failed", fname); continue; } @@ -3415,7 +3415,7 @@ static int umount_deactivate_dev_all(const struct device_set *devset) } if (umount2(fname, MNT_DETACH) < 0 && errno != EINVAL) { - ERROR("Failed to umount directory %s:%s", fname, strerror(errno)); + SYSERROR("Failed to umount directory %s", fname); } device_info = lookup_device(devset, entry->d_name); diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c index fc22bcfd..e91ddd1e 100644 --- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c +++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c @@ -448,7 +448,7 @@ void dev_udev_wait(uint32_t cookie) } if (pthread_create(&tid, NULL, udev_wait_process, uwait) != 0) { - ERROR("devmapper: create udev wait process thread error:%s", strerror(errno)); + SYSERROR("devmapper: create udev wait process thread error"); free_udev_wait_pth_t(uwait); return; } @@ -1191,7 +1191,7 @@ void dev_check_sem_set_stat(int *semusz, int *semmni) } if (semctl(0, 0, SEM_INFO, &sinfo) != 0) { - WARN("Get devmapper library version err:%s", strerror(errno)); + SYSWARN("Get devmapper library version err"); return; } 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 ae1aba9c..ddf3a62c 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 @@ -1844,7 +1844,7 @@ static int file_crc64(char *file, uint64_t *crc, uint64_t policy) fd = util_open(file, O_RDONLY, 0); if (fd < 0) { - ERROR("Open file: %s, failed: %s", file, strerror(errno)); + SYSERROR("Open file: %s, failed", file); return -1; } @@ -1866,7 +1866,7 @@ static int file_crc64(char *file, uint64_t *crc, uint64_t policy) while (true) { size = util_read_nointr(fd, buffer, BLKSIZE); if (size < 0) { - ERROR("read file %s failed: %s", file, strerror(errno)); + SYSERROR("read file %s failed", file); ret = -1; break; } else if (size == 0) { @@ -1914,7 +1914,7 @@ static int valid_crc64(storage_entry *entry, char *rootfs) if (fname != NULL && util_has_prefix(fname, ".wh.")) { goto out; } - ERROR("stat file or dir: %s, failed: %s", file, strerror(errno)); + SYSERROR("stat file or dir: %s, failed", file); ret = -1; } else { if (strlen(entry->payload) != PAYLOAD_CRC_LEN) { @@ -1981,7 +1981,7 @@ static tar_split *new_tar_split(layer_t *l, const char *tspath) ts->tmp_file = fopen(path, "w+"); if (ts->tmp_file == NULL) { - ERROR("create tmpfile failed: %s", strerror(errno)); + SYSERROR("create tmpfile failed"); ret = -1; goto out; } @@ -2019,7 +2019,7 @@ static int next_tar_split_entry(tar_split *ts, storage_entry **entry) if (errno == 0) { *entry = NULL; } else { - ERROR("error read line from tar split: %s", strerror(errno)); + SYSERROR("error read line from tar split"); ret = -1; } goto out; diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c index 07c3830b..d5e79207 100644 --- a/src/daemon/modules/image/oci/storage/storage.c +++ b/src/daemon/modules/image/oci/storage/storage.c @@ -1444,7 +1444,7 @@ static int do_add_checked_layer(const char *lid, int fd, map_t *checked_layers) // save checked layer ids into file nret = util_write_nointr(fd, buf, strlen(lid) + 1); if (nret < 0 || (size_t)nret != strlen(lid) + 1) { - ERROR("Write checked layer data failed: %s", strerror(errno)); + SYSERROR("Write checked layer data failed"); ret = -1; goto out; } diff --git a/src/daemon/modules/image/oci/utils_images.c b/src/daemon/modules/image/oci/utils_images.c index ad7fe0f4..a233c2b1 100644 --- a/src/daemon/modules/image/oci/utils_images.c +++ b/src/daemon/modules/image/oci/utils_images.c @@ -560,7 +560,7 @@ static int makesure_path_is_dir(char *path) if (errno == ENOENT) { return util_mkdir_p(path, TEMP_DIRECTORY_MODE); } - ERROR("lstat %s failed: %s", path, strerror(errno)); + SYSERROR("lstat %s failed.", path); return -1; } @@ -620,7 +620,7 @@ int makesure_isulad_tmpdir_perm_right(const char *root_dir) } if (lstat(isulad_tmpdir, &st) != 0) { - ERROR("lstat %s failed: %s", isulad_tmpdir, strerror(errno)); + SYSERROR("lstat %s failed.", isulad_tmpdir); ret = -1; goto out; } @@ -631,7 +631,7 @@ int makesure_isulad_tmpdir_perm_right(const char *root_dir) ret = 0; goto out; } else { - ERROR("lchown %s failed: %s", isulad_tmpdir, strerror(errno)); + SYSERROR("lchown %s failed", isulad_tmpdir); } out: diff --git a/src/daemon/modules/log/log_gather.c b/src/daemon/modules/log/log_gather.c index 9b400f00..773526a8 100644 --- a/src/daemon/modules/log/log_gather.c +++ b/src/daemon/modules/log/log_gather.c @@ -66,7 +66,7 @@ static int file_rotate_gz(const char *file_name, int i) } if (rename(from_path, to_path) < 0 && errno != ENOENT) { - WARN("Rename file: %s error: %s", from_path, strerror(errno)); + SYSWARN("Rename file: %s failed", from_path); return -1; } @@ -85,7 +85,7 @@ static int file_rotate_me(const char *file_name) } if (rename(file_name, tmp_path) < 0 && errno != ENOENT) { - WARN("Rename file: %s error: %s", file_name, strerror(errno)); + SYSWARN("Rename file: %s failed", file_name); return -1; } @@ -142,7 +142,7 @@ static int create_fifo() ret = mknod(g_fifo_path, S_IFIFO | S_IRUSR | S_IWUSR, (dev_t)0); if (ret != 0 && errno != EEXIST) { - COMMAND_ERROR("mknod failed: %s", strerror(errno)); + CMD_SYSERROR("mknod failed"); } else { ret = 0; } @@ -157,12 +157,12 @@ static int open_log(bool change_size) fd = util_open(g_fifo_path, O_RDWR | O_CLOEXEC, 0); if (fd == -1) { - COMMAND_ERROR("open fifo %s failed: %s", g_fifo_path, strerror(errno)); + CMD_SYSERROR("open fifo %s failed", g_fifo_path); return fd; } if (change_size && fcntl(fd, F_SETPIPE_SZ, LOG_FIFO_SIZE) == -1) { - COMMAND_ERROR("set fifo buffer size failed: %s", strerror(errno)); + CMD_SYSERROR("set fifo buffer size failed"); close(fd); return -1; } @@ -262,7 +262,7 @@ void main_loop() int len = (int)util_read_nointr(g_fifo_fd, rev_buf, REV_BUF_SIZE); if (len < 0) { if (ecount < 2) { - COMMAND_ERROR("%d: Read message failed: %s", ecount++, strerror(errno)); + CMD_SYSERROR("%d: Read message failed", ecount++); } continue; } @@ -270,7 +270,7 @@ void main_loop() rev_buf[len] = '\0'; if (g_save_log_op(rev_buf, (size_t)len) < 0) { - COMMAND_ERROR("write message failed: %s", strerror(errno)); + CMD_SYSERROR("write message failed"); } } } @@ -289,14 +289,14 @@ static int log_file_open() } fd = util_open(g_log_file, O_CREAT | O_WRONLY | O_APPEND, g_log_mode); if (fd == -1) { - COMMAND_ERROR("Open %s failed: %s", g_log_file, strerror(errno)); + CMD_SYSERROR("Open %s failed", g_log_file); ret = -1; goto out; } /* change log file mode to config, if log file exist and with different mode */ if (fchmod(fd, g_log_mode) != 0) { - COMMAND_ERROR("Change mode of log file: %s failed: %s", g_log_file, strerror(errno)); + CMD_SYSERROR("Change mode of log file: %s failed", g_log_file); close(fd); ret = -1; goto out; diff --git a/src/daemon/modules/network/cni_operator/libcni/libcni_conf.c b/src/daemon/modules/network/cni_operator/libcni/libcni_conf.c index 7489f8f3..cad92ce8 100644 --- a/src/daemon/modules/network/cni_operator/libcni/libcni_conf.c +++ b/src/daemon/modules/network/cni_operator/libcni/libcni_conf.c @@ -90,7 +90,7 @@ static char *do_get_cni_net_confs_json(const char *filename) content = util_read_text_file(filename); if (content == NULL) { - ERROR("Read file %s failed: %s", filename, strerror(errno)); + SYSERROR("Read file %s failed", filename); } return content; diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c index 2b9cf39c..e985cfc1 100644 --- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c @@ -88,7 +88,7 @@ static int parse_container_pid(const char *S, pid_ppid_info_t *pid_info) num = sscanf(S, "%d %Lu %d %Lu", &pid_info->pid, &pid_info->start_time, &pid_info->ppid, &pid_info->pstart_time); if (num != 4) { // args num to read is 4 - ERROR("Call sscanf error: %s", errno ? strerror(errno) : ""); + SYSERROR("Call sscanf failed."); return -1; } @@ -210,7 +210,7 @@ static int remove_container_rootpath(const char *id, const char *root_path) ret = util_recursive_rmdir(cont_root_path, 0); if (ret != 0) { const char *tmp_err = (errno != 0) ? strerror(errno) : "error"; - ERROR("Failed to delete container's root directory %s: %s", cont_root_path, tmp_err); + SYSERROR("Failed to delete container's root directory %s.", cont_root_path); isulad_set_error_message("Failed to delete container's root directory %s: %s", cont_root_path, tmp_err); ret = -1; goto out; @@ -750,7 +750,7 @@ int rt_lcr_kill(const char *id, const char *runtime, const rt_kill_params_t *par } else { int ret = kill(params->pid, (int)params->signal); if (ret < 0) { - ERROR("Can not kill process (pid=%d) with signal %u: %s", params->pid, params->signal, strerror(errno)); + SYSERROR("Can not kill process (pid=%d) with signal %u.", params->pid, params->signal); return -1; } } diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c index 5a62cc37..786071a7 100644 --- a/src/daemon/modules/runtime/isula/isula_rt_ops.c +++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c @@ -390,7 +390,7 @@ static bool shim_alive(const char *workdir) ret = kill(pid, 0); if (ret != 0) { - INFO("kill 0 shim-pid with error: %s", strerror(errno)); + SYSINFO("kill 0 shim-pid with error."); } return ret == 0; } @@ -780,7 +780,7 @@ static int shim_create(bool fg, const char *id, const char *workdir, const char pid = fork(); if (pid < 0) { - ERROR("Failed fork for shim parent %s", strerror(errno)); + SYSERROR("Failed fork for shim parent"); close(shim_stderr_pipe[0]); close(shim_stderr_pipe[1]); close(shim_stdout_pipe[0]); @@ -856,7 +856,7 @@ realexec: status = util_wait_for_pid_status(pid); if (status < 0) { - ERROR("Failed wait shim-parent %d exit %s", pid, strerror(errno)); + SYSERROR("Failed wait shim-parent %d exit", pid); ret = -1; goto out; } @@ -1699,7 +1699,7 @@ int rt_isula_exec_resize(const char *id, const char *runtime, const rt_exec_resi } if (kill(pid, SIGWINCH) < 0) { - ERROR("can't kill process (pid=%d) with signal %u: %s", pid, SIGWINCH, strerror(errno)); + SYSERROR("can't kill process (pid=%d) with signal %u", pid, SIGWINCH); ret = -1; goto out; } @@ -1727,7 +1727,7 @@ int rt_isula_kill(const char *id, const char *runtime, const rt_kill_params_t *p } else { int ret = kill(params->pid, (int)params->signal); if (ret < 0) { - ERROR("Can not kill process (pid=%d) with signal %u: %s", params->pid, params->signal, strerror(errno)); + SYSERROR("Can not kill process (pid=%d) with signal %u", params->pid, params->signal); return -1; } } diff --git a/src/daemon/modules/runtime/shim/shim_rt_monitor.cc b/src/daemon/modules/runtime/shim/shim_rt_monitor.cc index 3b6274ea..f5178c26 100644 --- a/src/daemon/modules/runtime/shim/shim_rt_monitor.cc +++ b/src/daemon/modules/runtime/shim/shim_rt_monitor.cc @@ -114,7 +114,7 @@ private: exit_fifo_fd = util_open(exit_fifo.c_str(), O_WRONLY | O_NONBLOCK, 0); if (exit_fifo_fd < 0) { - ERROR("Failed to open exit FIFO %s: %s.", exit_fifo.c_str(), strerror(errno)); + SYSERROR("Failed to open exit FIFO %s.", exit_fifo.c_str()); return -1; } diff --git a/src/daemon/modules/runtime/shim/shim_rt_ops.c b/src/daemon/modules/runtime/shim/shim_rt_ops.c index 73d5de1c..d348dfe1 100644 --- a/src/daemon/modules/runtime/shim/shim_rt_ops.c +++ b/src/daemon/modules/runtime/shim/shim_rt_ops.c @@ -210,7 +210,7 @@ static int shim_bin_v2_create(const char *runtime, const char *id, const char *w pid = fork(); if (pid < 0) { - ERROR("Failed to fork for shim parent %s", strerror(errno)); + SYSERROR("Failed to fork for shim parent"); ret = -1; goto out; } @@ -264,7 +264,7 @@ static int shim_bin_v2_create(const char *runtime, const char *id, const char *w status = util_wait_for_pid_status(pid); if (status < 0) { - ERROR("failed to wait shim-parent %d exit %s", pid, strerror(errno)); + SYSERROR("failed to wait shim-parent %d exit", pid); ret = -1; goto out; } diff --git a/src/daemon/modules/service/io_handler.c b/src/daemon/modules/service/io_handler.c index 0cb9fda9..474fa650 100644 --- a/src/daemon/modules/service/io_handler.c +++ b/src/daemon/modules/service/io_handler.c @@ -330,7 +330,7 @@ static ssize_t write_to_fifo(void *context, const void *data, size_t len) fd = *(int *)context; ret = util_write_nointr_in_total(fd, data, len); if ((ret <= 0) || (ret != (ssize_t)len)) { - ERROR("Failed to write %d: %s", fd, strerror(errno)); + SYSERROR("Failed to write %d", fd); return -1; } return ret; @@ -341,7 +341,7 @@ static ssize_t write_to_fd(void *context, const void *data, size_t len) ssize_t ret; ret = util_write_nointr(*(int *)context, data, len); if (ret < 0 || (size_t)ret != len) { - ERROR("Failed to write: %s", strerror(errno)); + SYSERROR("Failed to write"); return -1; } return ret; diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c index c4ee0223..483670de 100644 --- a/src/daemon/modules/service/service_container.c +++ b/src/daemon/modules/service/service_container.c @@ -575,7 +575,7 @@ static int umount_dev_tmpfs_for_system_container(const container_t *cont) return -1; } if (umount(rootfs_dev_path) < 0 && errno != ENOENT) { - WARN("Failed to umount dev tmpfs: %s, error: %s", rootfs_dev_path, strerror(errno)); + SYSWARN("Failed to umount dev tmpfs: %s", rootfs_dev_path); } } return 0; @@ -595,7 +595,7 @@ static int valid_mount_point(container_config_v2_common_config_mount_points_elem } if (lstat(mp->source, &st) != 0) { - ERROR("lstat %s: %s", mp->source, strerror(errno)); + SYSERROR("lstat %s failed", mp->source); isulad_set_error_message("lstat %s: %s", mp->source, strerror(errno)); return -1; } @@ -679,8 +679,7 @@ static void wait_exit_fifo(const char *id, const int exit_fifo_fd) descr.timeout_cbdata = container_id; nret = epoll_loop(&descr, WAIT_TIMEOUT); if (nret != 0) { - ERROR("Wait container %s 's monitor on fd %d error: %s", id, exit_fifo_fd, - errno ? strerror(errno) : ""); + SYSERROR("Wait container %s 's monitor on fd %d failed", id, exit_fifo_fd); goto out; } @@ -1266,7 +1265,7 @@ static int do_delete_container(container_t *cont) } ret = util_recursive_rmdir(container_state, 0); if (ret != 0) { - ERROR("Failed to delete container's state directory %s: %s", container_state, strerror(errno)); + SYSERROR("Failed to delete container's state directory %s", container_state); ret = -1; goto out; } @@ -1399,7 +1398,7 @@ static int send_signal_to_process(pid_t pid, unsigned long long start_time, uint } else { int ret = kill(pid, (int)signal); if (ret < 0) { - ERROR("Can not kill process (pid=%d) with signal %u: %s", pid, signal, strerror(errno)); + SYSERROR("Can not kill process (pid=%d) with signal %u", pid, signal); return -1; } } @@ -2157,7 +2156,7 @@ static void exec_container_end(container_exec_response *response, const containe } if (sync_fd >= 0 && cc != ISULAD_SUCCESS) { if (eventfd_write(sync_fd, 1) < 0) { - ERROR("Failed to write eventfd: %s", strerror(errno)); + SYSERROR("Failed to write eventfd"); } } if (thread_id > 0) { diff --git a/src/daemon/modules/service/service_network.c b/src/daemon/modules/service/service_network.c index c617852f..5502bcbd 100644 --- a/src/daemon/modules/service/service_network.c +++ b/src/daemon/modules/service/service_network.c @@ -961,7 +961,7 @@ static int do_update_internal_file(const char *id, const char *file_path, WARN("failed to write file %s in readonly file system", file_path); ret = 0; } else { - ERROR("Failed to write file %s: %s", file_path, strerror(errno)); + SYSERROR("Failed to write file %s", file_path); isulad_set_error_message("Failed to write file %s: %s", file_path, strerror(errno)); ret = -1; } @@ -1179,7 +1179,7 @@ static int do_drop_internal_file(const char *id, const char *file_path, const de WARN("failed to open file %s in readonly file system", file_path); goto out; } else { - ERROR("Failed to open %s: %s", file_path, strerror(errno)); + SYSERROR("Failed to open %s", file_path); isulad_set_error_message("Failed to open %s: %s", file_path, strerror(errno)); ret = -1; goto out; @@ -1212,7 +1212,7 @@ static int do_drop_internal_file(const char *id, const char *file_path, const de ret = util_write_file(file_path, str, strlen(str), NETWORK_MOUNT_FILE_MODE); if (ret != 0) { - ERROR("Failed to write file %s: %s", file_path, strerror(errno)); + SYSERROR("Failed to write file %s", file_path); isulad_set_error_message("Failed to write file %s: %s", file_path, strerror(errno)); goto out; } diff --git a/src/daemon/modules/spec/specs.c b/src/daemon/modules/spec/specs.c index d5bb68f4..3454a8c6 100644 --- a/src/daemon/modules/spec/specs.c +++ b/src/daemon/modules/spec/specs.c @@ -2405,7 +2405,7 @@ int save_oci_config(const char *id, const char *rootpath, const oci_runtime_spec if (util_atomic_write_file(file_path, json_container, strlen(json_container), DEFAULT_SECURE_FILE_MODE, false) != 0) { - ERROR("write json container failed: %s", strerror(errno)); + SYSERROR("write json container failed"); ret = -1; goto out_free; } diff --git a/src/daemon/modules/spec/specs_mount.c b/src/daemon/modules/spec/specs_mount.c index dc1ca1f1..ade22a02 100644 --- a/src/daemon/modules/spec/specs_mount.c +++ b/src/daemon/modules/spec/specs_mount.c @@ -1430,7 +1430,7 @@ static int copy_data_to_volume(char *base_fs, defs_mount *mnt) if (errno == ENOENT) { goto out; } - ERROR("stat for copy data to volume failed: %s", strerror(errno)); + SYSERROR("stat for copy data to volume failed"); ret = -1; goto out; } diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c index e384b8cc..6180b887 100644 --- a/src/daemon/modules/spec/verify.c +++ b/src/daemon/modules/spec/verify.c @@ -248,7 +248,7 @@ static bool check_kernel_version_ge4() ret = uname(&uts); if (ret < 0) { - WARN("Can not get kernel version: %s", strerror(errno)); + SYSWARN("Can not get kernel version"); } else { /* greater or equal than 4.0.0, check first part is enough */ return atoi(uts.release) >= 4; @@ -1332,7 +1332,7 @@ static int get_source_mount(const char *src, char **srcpath, char **optional) char *dname = NULL; if (realpath(src, real_path) == NULL) { - ERROR("Failed to get real path for %s : %s", src, strerror(errno)); + SYSERROR("Failed to get real path for %s", src); return -1; } @@ -1535,7 +1535,7 @@ static int verify_custom_mount(defs_mount **mounts, size_t len) #else if (!util_file_exists(iter->source) && util_mkdir_p(iter->source, mode)) { #endif - ERROR("Failed to create directory '%s': %s", iter->source, strerror(errno)); + SYSERROR("Failed to create directory '%s'", iter->source); isulad_try_set_error_message("Failed to create directory '%s': %s", iter->source, strerror(errno)); ret = -1; goto out; diff --git a/src/daemon/modules/volume/local.c b/src/daemon/modules/volume/local.c index 994ed96a..7f95757d 100644 --- a/src/daemon/modules/volume/local.c +++ b/src/daemon/modules/volume/local.c @@ -165,7 +165,7 @@ static int init_volume_root_dir(struct volumes_info *vols_info, const char *root ret = util_mkdir_p(root_dir, LOCAL_VOLUME_ROOT_DIR_MODE); if (ret != 0) { - ERROR("create volume directory %s failed: %s", root_dir, strerror(errno)); + SYSERROR("create volume directory %s failed", root_dir); goto out; } @@ -229,7 +229,7 @@ static char *build_and_valid_data_dir(const char *root_dir, const char *name) } if (lstat(tmp_dir, &st) != 0) { - ERROR("lstat %s: %s", tmp_dir, strerror(errno)); + SYSERROR("lstat %s failed", tmp_dir); ret = -1; goto out; } @@ -388,7 +388,7 @@ static struct volume *volume_create_nolock(char *name) ret = util_mkdir_p(v->path, LOCAL_VOLUME_DIR_MODE); if (ret != 0) { - ERROR("failed to create %s for volume %s: %s", v->path, v->name, strerror(errno)); + SYSERROR("failed to create %s for volume %s", v->path, v->name); goto out; } @@ -556,14 +556,14 @@ static int remove_volume_dir(char *path) // remain untouched if we remove the data directory failed. ret = util_recursive_rmdir(path, 0); if (ret != 0) { - ERROR("failed to remove volume data dir %s: %s", path, strerror(errno)); + SYSERROR("failed to remove volume data dir %s", path); isulad_try_set_error_message("failed to remove volume data dir %s: %s", path, strerror(errno)); goto out; } ret = util_recursive_rmdir(vol_dir, 0); if (ret != 0) { - ERROR("failed to remove volume dir %s: %s", vol_dir, strerror(errno)); + SYSERROR("failed to remove volume dir %s", vol_dir); isulad_try_set_error_message("failed to remove volume dir %s: %s", vol_dir, strerror(errno)); goto out; } @@ -586,7 +586,7 @@ static int volume_remove_nolock(char *name) } if (remove_volume_dir(v->path) != 0) { - ERROR("failed to remove volume dir %s: %s", v->path, strerror(errno)); + SYSERROR("failed to remove volume dir %s", v->path); return -1; } diff --git a/src/daemon/sandbox/sandbox.cc b/src/daemon/sandbox/sandbox.cc index 94c2684a..d3fc7eea 100644 --- a/src/daemon/sandbox/sandbox.cc +++ b/src/daemon/sandbox/sandbox.cc @@ -833,7 +833,7 @@ auto Sandbox::SaveNetworkSetting(Errors &error) -> bool nret = util_atomic_write_file(path.c_str(), m_networkSettings.c_str(), m_networkSettings.length(), CONFIG_FILE_MODE, false); if (nret != 0) { - ERROR("Failed to write file %s: %s", path.c_str(), strerror(errno)); + SYSERROR("Failed to write file %s", path.c_str()); error.Errorf("Failed to write file %s: %s", path.c_str(), strerror(errno)); return false; } diff --git a/src/utils/console/console.c b/src/utils/console/console.c index a160d685..568832e8 100644 --- a/src/utils/console/console.c +++ b/src/utils/console/console.c @@ -36,7 +36,7 @@ static ssize_t fd_write_function(void *context, const void *data, size_t len) ret = util_write_nointr_in_total(*(int *)context, data, len); if ((ret <= 0) || (ret != (ssize_t)len)) { - ERROR("Failed to write: %s", strerror(errno)); + SYSERROR("Failed to write"); return -1; } return ret; @@ -100,7 +100,7 @@ static int console_writer_write_data(const struct io_write_wrapper *writer, cons } ret = writer->write_func(writer->context, buf, (size_t)len); if (ret <= 0 || ret != len) { - ERROR("Failed to write, type: %d, expect: %zd, wrote: %zd, error: %s!", writer->io_type, len, ret, strerror(errno)); + SYSERROR("Failed to write, type: %d, expect: %zd, wrote: %zd!", writer->io_type, len, ret); return -1; } return 0; @@ -187,7 +187,7 @@ int console_fifo_name(const char *rundir, const char *subpath, const char *stdfl if (do_mkdirp) { ret = util_mkdir_p(fifo_path, CONSOLE_FIFO_DIRECTORY_MODE); if (ret < 0) { - COMMAND_ERROR("Unable to create console fifo directory %s: %s.", fifo_path, strerror(errno)); + CMD_SYSERROR("Unable to create console fifo directory %s.", fifo_path); goto out; } } @@ -215,7 +215,7 @@ int console_fifo_create(const char *fifo_path) ret = mknod(fifo_path, S_IFIFO | S_IRUSR | S_IWUSR, (dev_t)0); if (ret < 0 && errno != EEXIST) { - ERROR("Failed to mknod monitor fifo %s: %s.", fifo_path, strerror(errno)); + SYSERROR("Failed to mknod monitor fifo %s.", fifo_path); return -1; } @@ -265,7 +265,7 @@ int console_fifo_open(const char *fifo_path, int *fdout, int flags) fd = util_open(fifo_path, flags, (mode_t)0); if (fd < 0) { - ERROR("Failed to open fifo %s to send message: %s.", fifo_path, strerror(errno)); + SYSERROR("Failed to open fifo %s to send message.", fifo_path); return -1; } @@ -281,7 +281,7 @@ int console_fifo_open_withlock(const char *fifo_path, int *fdout, int flags) fd = util_open(fifo_path, flags, 0); if (fd < 0) { - WARN("Failed to open fifo %s to send message: %s.", fifo_path, strerror(errno)); + SYSWARN("Failed to open fifo %s to send message.", fifo_path); return -1; } @@ -411,12 +411,12 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin if (tty) { ret = epoll_loop_add_handler(&descr, ts.stdin_reader, console_cb_tty_stdin_with_escape, &ts); if (ret) { - INFO("Add handler for stdinfd faied. with error %s", strerror(errno)); + SYSINFO("Add handler for stdinfd faied."); } } else { ret = epoll_loop_add_handler(&descr, ts.stdin_reader, console_cb_stdio_copy, &ts); if (ret) { - INFO("Add handler for stdinfd faied. with error %s", strerror(errno)); + SYSINFO("Add handler for stdinfd faied."); } } } diff --git a/src/utils/cutils/network_namespace.c b/src/utils/cutils/network_namespace.c index 212f0bd7..0e225d9b 100644 --- a/src/utils/cutils/network_namespace.c +++ b/src/utils/cutils/network_namespace.c @@ -175,7 +175,7 @@ int remove_network_namespace(const char *netns_path) } if (umount_network_namespace(netns_path) != 0) { - ERROR("Failed to umount directory %s:%s", netns_path, strerror(errno)); + SYSERROR("Failed to umount directory %s", netns_path); return -1; } diff --git a/src/utils/cutils/path.c b/src/utils/cutils/path.c index d586e981..51d73445 100644 --- a/src/utils/cutils/path.c +++ b/src/utils/cutils/path.c @@ -698,7 +698,7 @@ static char *find_realpath(const char *path) ret = (int)readlink(iter_path, target, PATH_MAX - 1); if (ret < 0) { - ERROR("Failed to read link of %s: %s", iter_path, strerror(errno)); + SYSERROR("Failed to read link of %s.", iter_path); goto out; } // is not absolutely path @@ -745,7 +745,7 @@ int util_realpath_in_scope(const char *rootfs, const char *path, char **real_pat int nret = snprintf(full_path, sizeof(full_path), "%s%s", rootfs, path); if (nret < 0 || (size_t)nret >= sizeof(full_path)) { - ERROR("sprintf error: %s", strerror(errno)); + SYSERROR("sprintf failed"); ret = -1; goto out; } diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c index ecd530bc..d946694c 100644 --- a/src/utils/cutils/utils.c +++ b/src/utils/cutils/utils.c @@ -480,7 +480,7 @@ proc_t *util_stat2proc(const char *s, size_t len) num = sscanf(s, "%d (%15c", &p->pid, p->cmd); #endif if (num != 2) { - ERROR("Call sscanf error: %s", errno ? strerror(errno) : ""); + SYSERROR("Call sscanf error"); free(p); return NULL; } @@ -495,7 +495,7 @@ proc_t *util_stat2proc(const char *s, size_t len) &p->maj_flt, &p->cmaj_flt, &p->utime, &p->stime, &p->cutime, &p->cstime, &p->priority, &p->nice, &p->timeout, &p->it_real_value, &p->start_time); if (num != 20) { // max arg to read - ERROR("Call sscanf error: %s", errno ? strerror(errno) : ""); + SYSERROR("Call sscanf error"); free(p); return NULL; } @@ -1159,7 +1159,7 @@ static int set_echo_back(bool echo_back) struct termios old, new; if (tcgetattr(STDIN_FILENO, &old)) { - ERROR("get tc attribute failed: %s\n", strerror(errno)); + SYSERROR("get tc attribute failed"); return -1; } @@ -1172,7 +1172,7 @@ static int set_echo_back(bool echo_back) } if (tcsetattr(STDIN_FILENO, TCSANOW, &new)) { - ERROR("set tc attribute failed: %s\n", strerror(errno)); + SYSERROR("set tc attribute failed"); return -1; } @@ -1498,7 +1498,7 @@ int util_normalized_host_os_arch(char **host_os, char **host_arch, char **host_v } if (uname(&uts) < 0) { - ERROR("Failed to read host arch and os: %s", strerror(errno)); + SYSERROR("Failed to read host arch and os"); return -1; } @@ -1655,7 +1655,7 @@ int util_create_shm_path(const char *spath, const int64_t shm_size) nret = mount("shm", spath, "tmpfs", MS_NOEXEC | MS_NODEV | MS_NOSUID, shmproperty); if (nret < 0) { - ERROR("Mount %s failed: %s", spath, strerror(errno)); + SYSERROR("Mount %s failed", spath); return -1; } diff --git a/src/utils/cutils/utils_aes.c b/src/utils/cutils/utils_aes.c index 055a9538..2eecf2d6 100644 --- a/src/utils/cutils/utils_aes.c +++ b/src/utils/cutils/utils_aes.c @@ -72,13 +72,13 @@ int util_aes_key(const char *key_file, bool create, unsigned char *aeskey) } else { fd = open(key_file, O_RDONLY); if (fd < 0) { - ERROR("open key file %s failed: %s", key_file, strerror(errno)); + SYSERROR("open key file %s failed", key_file); ret = -1; goto out; } if (util_read_nointr(fd, aeskey, AES_256_CFB_KEY_LEN) != AES_256_CFB_KEY_LEN) { - ERROR("read key file %s failed: %s", key_file, strerror(errno)); + SYSERROR("read key file %s failed", key_file); ret = -1; goto out; } @@ -163,14 +163,14 @@ int util_aes_encode(unsigned char *aeskey, unsigned char *bytes, size_t len, uns evp_ret = EVP_EncryptInit(ctx, cipher, aeskey, iv); #endif if (evp_ret != 1) { - ERROR("init evp decrypt failed, result %d: %s", evp_ret, strerror(errno)); + SYSERROR("init evp decrypt failed, result %d", evp_ret); ret = -1; goto out; } evp_ret = EVP_EncryptUpdate(ctx, (*out) + AES_256_CFB_IV_LEN, &tmp_out_len, bytes, len); if (evp_ret != 1) { - ERROR("evp encrypt update failed, result %d: %s", evp_ret, strerror(errno)); + SYSERROR("evp encrypt update failed, result %d", evp_ret); ret = -1; goto out; } @@ -182,7 +182,7 @@ int util_aes_encode(unsigned char *aeskey, unsigned char *bytes, size_t len, uns evp_ret = EVP_EncryptFinal(ctx, (*out) + AES_256_CFB_IV_LEN + tmp_out_len, &tmp_out_len); #endif if (evp_ret != 1) { - ERROR("evp encrypt final failed, result %d: %s", evp_ret, strerror(errno)); + SYSERROR("evp encrypt final failed, result %d", evp_ret); ret = -1; goto out; } @@ -256,7 +256,7 @@ int util_aes_decode(unsigned char *aeskey, unsigned char *bytes, size_t len, uns evp_ret = EVP_DecryptInit(ctx, cipher, aeskey, iv); #endif if (evp_ret != 1) { - ERROR("init evp decrypt failed, result %d: %s", evp_ret, strerror(errno)); + SYSERROR("init evp decrypt failed, result %d", evp_ret); ret = -1; goto out; } @@ -264,7 +264,7 @@ int util_aes_decode(unsigned char *aeskey, unsigned char *bytes, size_t len, uns expected_size = len - AES_256_CFB_IV_LEN; evp_ret = EVP_DecryptUpdate(ctx, *out, &tmp_out_len, bytes + AES_256_CFB_IV_LEN, expected_size); if (evp_ret != 1) { - ERROR("evp decrypt update failed, result %d: %s", evp_ret, strerror(errno)); + SYSERROR("evp decrypt update failed, result %d", evp_ret); ret = -1; goto out; } @@ -276,7 +276,7 @@ int util_aes_decode(unsigned char *aeskey, unsigned char *bytes, size_t len, uns evp_ret = EVP_DecryptFinal(ctx, (*out) + tmp_out_len, &tmp_out_len); #endif if (evp_ret != 1) { - ERROR("evp decrypt final failed, result %d: %s", evp_ret, strerror(errno)); + SYSERROR("evp decrypt final failed, result %d", evp_ret); ret = -1; goto out; } diff --git a/src/utils/cutils/utils_base64.c b/src/utils/cutils/utils_base64.c index 3871140e..78e5ae0d 100644 --- a/src/utils/cutils/utils_base64.c +++ b/src/utils/cutils/utils_base64.c @@ -47,7 +47,7 @@ int util_base64_encode(unsigned char *bytes, size_t len, char **out) } if (EVP_EncodeBlock((uint8_t *)(*out), (const uint8_t *)bytes, len) == 0) { - ERROR("Encode base64 failed: %s", strerror(errno)); + SYSERROR("Encode base64 failed"); free(encoded); return -1; } @@ -78,7 +78,7 @@ int util_base64_decode(const char *input, size_t len, unsigned char **out, size_ } if (EVP_DecodeBase64((uint8_t *)decoded, &decoded_size, decoded_size, (const uint8_t *)input, len) == 0) { - ERROR("Decode base64 failed: %s", strerror(errno)); + SYSERROR("Decode base64 failed"); free(decoded); return -1; } diff --git a/src/utils/cutils/utils_file.c b/src/utils/cutils/utils_file.c index 8480dd94..bc22ee95 100644 --- a/src/utils/cutils/utils_file.c +++ b/src/utils/cutils/utils_file.c @@ -231,7 +231,7 @@ int util_mkdir_p_userns_remap(const char *dir, mode_t mode, const char *userns_r if (*cur_dir) { ret = mkdir(cur_dir, mode); if (ret != 0 && (errno != EEXIST || !util_dir_exists(cur_dir))) { - ERROR("failed to create directory '%s': %s", cur_dir, strerror(errno)); + SYSERROR("failed to create directory '%s'", cur_dir); goto err_out; } if (ret == 0 && userns_remap != NULL && chown(cur_dir, host_uid, host_gid) != 0) { @@ -318,14 +318,14 @@ bool util_force_remove_file(const char *fname, int *saved_errno) if (saved_errno != NULL && *saved_errno == 0) { *saved_errno = errno; } - WARN("Failed to delete %s: %s", fname, strerror(errno)); + SYSWARN("Failed to delete %s", fname); if (mark_file_mutable(fname) != 0) { WARN("Failed to mark file mutable"); } if (unlink(fname) != 0) { - ERROR("Failed to delete \"%s\": %s", fname, strerror(errno)); + SYSERROR("Failed to delete \"%s\"", fname); return false; } @@ -711,7 +711,7 @@ int util_gzip_compressed(const char *filename, bool *gzip) f = fopen(filename, "rb"); if (f == NULL) { - ERROR("Failed to open file %s: %s", filename, strerror(errno)); + SYSERROR("Failed to open file %s", filename); return -1; } @@ -887,7 +887,7 @@ char *util_read_text_file(const char *path) readlen = fread(buf, 1, (size_t)len, filp); if (((readlen < (size_t)len) && (!feof(filp))) || (readlen > (size_t)len)) { - ERROR("Failed to read file %s, error: %s\n", path, strerror(errno)); + SYSERROR("Failed to read file %s.", path); UTIL_FREE_AND_SET_NULL(buf); goto err_out; } @@ -913,7 +913,7 @@ int64_t util_file_size(const char *filename) } if (stat(filename, &st)) { - WARN("stat file %s failed: %s", filename, strerror(errno)); + SYSWARN("stat file %s failed", filename); return -1; } @@ -932,7 +932,7 @@ int util_scan_subdirs(const char *directory, subdir_callback_t cb, void *context dir = opendir(directory); if (dir == NULL) { - ERROR("Failed to open directory: %s error:%s", directory, strerror(errno)); + SYSERROR("Failed to open directory: %s", directory); return -1; } @@ -967,7 +967,7 @@ int util_list_all_subdir(const char *directory, char ***out) dir = opendir(directory); if (dir == NULL) { - ERROR("Failed to open directory: %s error:%s", directory, strerror(errno)); + SYSERROR("Failed to open directory: %s", directory); return -1; } direntp = readdir(dir); @@ -1115,14 +1115,14 @@ int util_write_file(const char *fname, const char *content, size_t content_len, } dst_fd = util_open(fname, O_WRONLY | O_CREAT | O_TRUNC, mode); if (dst_fd < 0) { - ERROR("Creat file: %s, failed: %s", fname, strerror(errno)); + SYSERROR("Creat file: %s, failed", fname); ret = -1; goto free_out; } len = util_write_nointr(dst_fd, content, content_len); if (len < 0 || ((size_t)len) != content_len) { ret = -1; - ERROR("Write file failed: %s", strerror(errno)); + SYSERROR("Write file failed"); goto free_out; } free_out: @@ -1141,7 +1141,7 @@ char *verify_file_and_get_real_path(const char *file) return NULL; } if (realpath(file, resolved_path) == NULL) { - ERROR("Failed to get realpath: %s , %s", resolved_path, strerror(errno)); + SYSERROR("Failed to get realpath: %s.", resolved_path); return NULL; } @@ -1171,33 +1171,33 @@ int util_copy_file(const char *src_file, const char *dst_file, mode_t mode) } nret = realpath(src_file, real_src_file); if (nret == NULL) { - ERROR("real path: %s, return: %s", src_file, strerror(errno)); + SYSERROR("real path: %s failed.", src_file); ret = -1; return ret; } src_fd = util_open(real_src_file, O_RDONLY, CONFIG_FILE_MODE); if (src_fd < 0) { - ERROR("Open src file: %s, failed: %s", real_src_file, strerror(errno)); + SYSERROR("Open src file: %s, failed", real_src_file); ret = -1; goto free_out; } dst_fd = util_open(dst_file, O_WRONLY | O_CREAT | O_TRUNC, mode); if (dst_fd < 0) { - ERROR("Creat file: %s, failed: %s", dst_file, strerror(errno)); + SYSERROR("Creat file: %s, failed", dst_file); ret = -1; goto free_out; } while (true) { ssize_t len = util_read_nointr(src_fd, buf, BUFSIZE); if (len < 0) { - ERROR("Read src file failed: %s", strerror(errno)); + SYSERROR("Read src file failed"); ret = -1; goto free_out; } else if (len == 0) { break; } if (util_write_nointr(dst_fd, buf, (size_t)len) != len) { - ERROR("Write file failed: %s", strerror(errno)); + SYSERROR("Write file failed"); ret = -1; goto free_out; } @@ -1489,7 +1489,7 @@ static int do_atomic_write_file(const char *fname, const char *content, size_t c dst_fd = util_open(fname, O_WRONLY | O_CREAT | O_TRUNC, mode); if (dst_fd < 0) { - ERROR("Creat file: %s, failed: %s", fname, strerror(errno)); + SYSERROR("Creat file: %s, failed", fname); ret = -1; goto free_out; } @@ -1497,7 +1497,7 @@ static int do_atomic_write_file(const char *fname, const char *content, size_t c len = util_write_nointr(dst_fd, content, content_len); if (len < 0 || ((size_t)len) != content_len) { ret = -1; - ERROR("Write file failed: %s", strerror(errno)); + SYSERROR("Write file failed"); goto free_out; } @@ -1673,7 +1673,7 @@ int util_proc_file_line_by_line(FILE *fp, read_line_callback_t cb, void *context // end of file if (errno != 0) { ret = -1; - ERROR("read line failed: %s", strerror(errno)); + SYSERROR("read line failed"); } goto out; } @@ -1761,7 +1761,7 @@ static int copy_own(char *copy_dst, struct stat *src_stat) struct stat dst_stat = { 0 }; if (lstat(copy_dst, &dst_stat) != 0) { - ERROR("lstat %s failed: %s", copy_dst, strerror(errno)); + SYSERROR("lstat %s failed", copy_dst); return -1; } @@ -1770,7 +1770,7 @@ static int copy_own(char *copy_dst, struct stat *src_stat) return 0; } - ERROR("lchown %s failed: %s", copy_dst, strerror(errno)); + SYSERROR("lchown %s failed", copy_dst); return ret; } @@ -1782,7 +1782,7 @@ static int copy_mode(char *copy_dst, struct stat *src_stat) } if (chmod(copy_dst, src_stat->st_mode) != 0) { - ERROR("chmod %s failed: %s", copy_dst, strerror(errno)); + SYSERROR("chmod %s failed", copy_dst); return -1; } @@ -1795,7 +1795,7 @@ static int copy_time(char *copy_dst, struct stat *src_stat) // copy_dst is absolute path, so first argment is ignored. if (utimensat(0, copy_dst, tm, AT_SYMLINK_NOFOLLOW) != 0) { - ERROR("failed to set time of %s: %s", copy_dst, strerror(errno)); + SYSERROR("failed to set time of %s", copy_dst); return -1; } @@ -1806,10 +1806,10 @@ static int set_one_xattr(char *copy_dst, char *key, char *value, ssize_t size) { if (lsetxattr(copy_dst, key, value, size, 0) != 0) { if (errno == ENOTSUP) { - DEBUG("ignore copy xattr %s of %s: %s", key, copy_dst, strerror(errno)); + SYSDEBUG("ignore copy xattr %s of %s", key, copy_dst); return 0; } - ERROR("failed to set xattr %s of %s: %s", key, copy_dst, strerror(errno)); + SYSERROR("failed to set xattr %s of %s", key, copy_dst); return -1; } @@ -1831,10 +1831,10 @@ static int do_copy_xattrs(char *copy_dst, char *copy_src, char *xattrs, ssize_t size = lgetxattr(copy_src, key, NULL, 0); if (size < 0) { if (errno == ENOTSUP) { - DEBUG("ignore copy xattr %s of %s: %s", key, copy_src, strerror(errno)); + SYSDEBUG("ignore copy xattr %s of %s", key, copy_src); continue; } - ERROR("failed to get xattr %s of %s: %s", key, copy_src, strerror(errno)); + SYSERROR("failed to get xattr %s of %s", key, copy_src); ret = -1; goto out; } @@ -1855,10 +1855,10 @@ static int do_copy_xattrs(char *copy_dst, char *copy_src, char *xattrs, ssize_t if (lgetxattr(copy_src, key, value, size) < 0) { if (errno == ENOTSUP) { - DEBUG("ignore copy xattr %s of %s: %s", key, copy_src, strerror(errno)); + SYSDEBUG("ignore copy xattr %s of %s", key, copy_src); continue; } - ERROR("failed to get xattr %s of %s: %s", key, copy_src, strerror(errno)); + SYSERROR("failed to get xattr %s of %s", key, copy_src); ret = -1; goto out; } @@ -1884,10 +1884,10 @@ static int copy_xattrs(char *copy_dst, char *copy_src) xattrs_len = llistxattr(copy_src, NULL, 0); if (xattrs_len < 0) { if (errno == ENOTSUP) { - DEBUG("ignore copy xattrs of %s: %s", copy_src, strerror(errno)); + SYSDEBUG("ignore copy xattrs of %s", copy_src); return 0; } - ERROR("failed to get xattrs length of %s: %s", copy_src, strerror(errno)); + SYSERROR("failed to get xattrs length of %s", copy_src); return -1; } @@ -1904,10 +1904,10 @@ static int copy_xattrs(char *copy_dst, char *copy_src) if (llistxattr(copy_src, xattrs, xattrs_len) < 0) { if (errno == ENOTSUP) { - DEBUG("ignore copy xattrs of %s: %s", copy_src, strerror(errno)); + SYSDEBUG("ignore copy xattrs of %s", copy_src); goto out; } - ERROR("failed to list xattrs of %s: %s", copy_src, strerror(errno)); + SYSERROR("failed to list xattrs of %s", copy_src); ret = -1; goto out; } @@ -1953,7 +1953,7 @@ static int copy_folder(char *copy_dst, char *copy_src) struct stat dst_stat = { 0 }; if (lstat(copy_src, &src_stat) != 0) { - ERROR("stat %s failed: %s", copy_src, strerror(errno)); + SYSERROR("stat %s failed", copy_src); return -1; } if (!S_ISDIR(src_stat.st_mode)) { @@ -1963,7 +1963,7 @@ static int copy_folder(char *copy_dst, char *copy_src) if (lstat(copy_dst, &dst_stat) != 0) { if (mkdir(copy_dst, src_stat.st_mode) != 0) { - ERROR("failed to mkdir %s: %s", copy_dst, strerror(errno)); + SYSERROR("failed to mkdir %s", copy_dst); return -1; } } else if (!S_ISDIR(dst_stat.st_mode)) { @@ -1971,7 +1971,7 @@ static int copy_folder(char *copy_dst, char *copy_src) return -1; } else { if (chmod(copy_dst, src_stat.st_mode) != 0) { - ERROR("failed to chmod %s: %s", copy_dst, strerror(errno)); + SYSERROR("failed to chmod %s.", copy_dst); return -1; } } @@ -1988,7 +1988,7 @@ static int copy_regular(char *copy_dst, char *copy_src, struct stat *src_stat, m target = map_search(inodes, (void *)(&(src_stat->st_ino))); if (target != NULL) { if (link(target, copy_dst) != 0) { - ERROR("failed to link %s to %s: %s", target, copy_dst, strerror(errno)); + SYSERROR("failed to link %s to %s", target, copy_dst); return -1; } return 0; @@ -2008,12 +2008,12 @@ static int copy_symbolic(char *copy_dst, char *copy_src) char link[PATH_MAX] = { 0 }; if (readlink(copy_src, link, sizeof(link)) < 0) { - ERROR("readlink of %s failed: %s", copy_src, strerror(errno)); + SYSERROR("readlink of %s failed", copy_src); return -1; } if (symlink(link, copy_dst) != 0) { - ERROR("create symbolic %s failed: %s", copy_dst, strerror(errno)); + SYSERROR("create symbolic %s failed", copy_dst); return -1; } @@ -2023,7 +2023,7 @@ static int copy_symbolic(char *copy_dst, char *copy_src) static int copy_device(char *copy_dst, char *copy_src, struct stat *src_stat) { if (mknod(copy_dst, src_stat->st_mode, src_stat->st_dev) != 0) { - ERROR("mknod %s failed: %s", copy_dst, strerror(errno)); + SYSERROR("mknod %s failed", copy_dst); return -1; } return 0; diff --git a/src/utils/cutils/utils_fs.c b/src/utils/cutils/utils_fs.c index ae71f3ba..63f6d2aa 100644 --- a/src/utils/cutils/utils_fs.c +++ b/src/utils/cutils/utils_fs.c @@ -449,7 +449,7 @@ static int do_real_mount(const char *src, const char *dst, const char *mtype, un if (!is_remount(src, mntflags) || (mntdata != NULL && strcmp(mntdata, "") != 0)) { ret = mount(src, dst, mtype, oflags, mntdata); if (ret < 0) { - ERROR("Failed to mount from %s to %s:%s", src, dst, strerror(errno)); + SYSERROR("Failed to mount from %s to %s", src, dst); goto out; } } @@ -458,7 +458,7 @@ static int do_real_mount(const char *src, const char *dst, const char *mtype, un // Change the propagation type. ret = mount("", dst, "", mntflags & PROPAGATION_FLAGS, ""); if (ret < 0) { - ERROR("Failed to change the propagation type of dst %s:%s", dst, strerror(errno)); + SYSERROR("Failed to change the propagation type of dst %s.", dst); goto out; } } @@ -467,7 +467,7 @@ static int do_real_mount(const char *src, const char *dst, const char *mtype, un // Remount the bind to apply read only. ret = mount("", dst, "", oflags | MS_REMOUNT, ""); if (ret < 0) { - ERROR("Failed to remount the bind to apply read only of dst %s:%s", dst, strerror(errno)); + SYSERROR("Failed to remount the bind to apply read only of dst %s.", dst); goto out; } } @@ -576,7 +576,7 @@ static int util_mount_from_handler(const char *src, const char *dst, const char ret = mount(src, dst, mtype, mntflags, mntdata); if (ret < 0) { - ERROR("Failed to mount from %s to %s:%s", src, dst, strerror(errno)); + SYSERROR("Failed to mount from %s to %s.", src, dst); goto out; } out: @@ -596,7 +596,7 @@ int util_mount_from(const char *base, const char *src, const char *dst, const ch pid = fork(); if (pid == (pid_t) -1) { - ERROR("Failed to fork: %s", strerror(errno)); + SYSERROR("Failed to fork"); goto cleanup; } @@ -652,7 +652,7 @@ bool util_check_readonly_fs(const char *path) continue; } - ERROR("Stat fs failed: %s", strerror(errno)); + SYSERROR("Stat fs failed"); return false; } diff --git a/src/utils/cutils/utils_port.c b/src/utils/cutils/utils_port.c index 583a3509..fbe143ae 100644 --- a/src/utils/cutils/utils_port.c +++ b/src/utils/cutils/utils_port.c @@ -984,12 +984,12 @@ static int do_close(int sock) if (close(sock) == 0) { return 0; } - WARN("close socket failed: %s, wait to retry: %zu\n", strerror(errno), i); + SYSWARN("close socket failed, wait to retry: %zu\n", i); // wait 100us to retry usleep(10000); } - ERROR("close socket failed: %s", strerror(errno)); + SYSERROR("close socket failed"); return -1; } @@ -1006,12 +1006,12 @@ bool util_check_port_free(int port) sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { - ERROR("get socket failed: %s", strerror(errno)); + SYSERROR("get socket failed"); return false; } if (bind(sock, (struct sockaddr *)&s_addr, sizeof(struct sockaddr_in)) < 0) { - ERROR("bind port failed: %s\n", strerror(errno)); + SYSERROR("bind port failed"); ret = false; } @@ -1036,19 +1036,19 @@ int util_get_random_port() sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { - ERROR("get socket failed: %s", strerror(errno)); + SYSERROR("get socket failed"); return -1; } if (bind(sock, (struct sockaddr *)&s_addr, sizeof(struct sockaddr_in)) < 0) { - ERROR("bind port failed: %s\n", strerror(errno)); + SYSERROR("bind port failed"); ret = -1; goto out; } s_len = sizeof(struct sockaddr_in); if (getsockname(sock, (struct sockaddr *)&s_addr, &s_len) == -1) { - ERROR("getsockname failed: %s\n", strerror(errno)); + SYSERROR("getsockname failed"); ret = -1; goto out; } diff --git a/src/utils/cutils/utils_verify.c b/src/utils/cutils/utils_verify.c index 67313d70..2f10f278 100644 --- a/src/utils/cutils/utils_verify.c +++ b/src/utils/cutils/utils_verify.c @@ -474,7 +474,7 @@ bool util_valid_file(const char *path, uint32_t fmod) nret = stat(path, &s); if (nret < 0) { - ERROR("stat failed, error: %s", strerror(errno)); + SYSERROR("stat failed"); return false; } diff --git a/src/utils/http/http.c b/src/utils/http/http.c index 5e46766d..8b74f773 100644 --- a/src/utils/http/http.c +++ b/src/utils/http/http.c @@ -333,7 +333,7 @@ static int ensure_path_file(char **rpath, void *output, bool resume, FILE **page if (resume) { mode = "a"; if (stat(*rpath, &st) < 0) { - ERROR("stat %s failed: %s", *rpath, strerror(errno)); + SYSERROR("stat %s failed", *rpath); return -1; } *fsize = (size_t)st.st_size; diff --git a/src/utils/sha256/sha256.c b/src/utils/sha256/sha256.c index d8e044b4..54cc2862 100644 --- a/src/utils/sha256/sha256.c +++ b/src/utils/sha256/sha256.c @@ -124,7 +124,7 @@ char *sha256_digest_file(const char *filename, bool isgzip) stream = (void *)fopen(filename, "r"); } if (stream == NULL) { - ERROR("open file %s failed: %s", filename, strerror(errno)); + SYSERROR("open file %s failed", filename); return NULL; } @@ -259,13 +259,13 @@ static char *cal_file_digest(const char *filename) fp = util_fopen(filename, "r"); if (fp == NULL) { - ERROR("failed to open file %s: %s", filename, strerror(errno)); + SYSERROR("failed to open file %s.", filename); return NULL; } digest = sha256_digest_file(filename, false); if (digest == NULL) { - ERROR("calc digest for file %s failed: %s", filename, strerror(errno)); + SYSERROR("calc digest for file %s failed", filename); goto err_out; } @@ -299,7 +299,7 @@ static char *cal_gzip_digest(const char *filename) digest = sha256_digest_file(filename, true); if (digest == NULL) { - ERROR("calc digest for file %s failed: %s", filename, strerror(errno)); + SYSERROR("calc digest for file %s failed", filename); goto err_out; } diff --git a/src/utils/tar/isulad_tar.c b/src/utils/tar/isulad_tar.c index 24269c70..7218cca8 100644 --- a/src/utils/tar/isulad_tar.c +++ b/src/utils/tar/isulad_tar.c @@ -113,7 +113,7 @@ static int resolve_host_source_path(const char *path, bool follow_link, char **r if (follow_link) { if (realpath(path, real_path) == NULL) { - ERROR("Can not get real path of %s: %s", real_path, strerror(errno)); + SYSERROR("Can not get real path of %s.", real_path); format_errorf(err, "Can not get real path of %s: %s", real_path, strerror(errno)); return -1; } @@ -130,7 +130,7 @@ static int resolve_host_source_path(const char *path, bool follow_link, char **r goto cleanup; } if (realpath(dirpath, real_path) == NULL) { - ERROR("Can not get real path of %s: %s", dirpath, strerror(errno)); + SYSERROR("Can not get real path of %s.", dirpath); format_errorf(err, "Can not get real path of %s: %s", dirpath, strerror(errno)); goto cleanup; } @@ -191,7 +191,7 @@ struct archive_copy_info *copy_info_source_path(const char *path, bool follow_li nret = lstat(resolved_path, &st); if (nret < 0) { - ERROR("lstat %s: %s", resolved_path, strerror(errno)); + SYSERROR("lstat %s failed", resolved_path); format_errorf(err, "lstat %s: %s", resolved_path, strerror(errno)); goto cleanup; } @@ -225,7 +225,7 @@ static int copy_info_destination_path_ret(struct archive_copy_info *info, struct ret = (int)readlink(iter_path, target, PATH_MAX); if (ret < 0) { - ERROR("Failed to read link of %s: %s", iter_path, strerror(errno)); + SYSERROR("Failed to read link of %s", iter_path); format_errorf(err, "Failed to read link of %s: %s", iter_path, strerror(errno)); goto cleanup; } @@ -258,7 +258,7 @@ static int copy_info_destination_path_ret(struct archive_copy_info *info, struct if (ret != 0) { char *dst_parent = NULL; if (errno != ENOENT) { - ERROR("Can not stat %s: %s", iter_path, strerror(errno)); + SYSERROR("Can not stat %s", iter_path); format_errorf(err, "Can not stat %s: %s", iter_path, strerror(errno)); goto cleanup; } @@ -428,7 +428,7 @@ static int tar_resource_rebase(const char *path, const char *rebase, const char char *srcbase = NULL; if (lstat(path, &st) < 0) { - ERROR("lstat %s: %s", path, strerror(errno)); + SYSERROR("lstat %s failed", path); format_errorf(err, "lstat %s: %s", path, strerror(errno)); return -1; } diff --git a/src/utils/tar/util_archive.c b/src/utils/tar/util_archive.c index d2fc5488..f34572ae 100644 --- a/src/utils/tar/util_archive.c +++ b/src/utils/tar/util_archive.c @@ -343,7 +343,7 @@ static int copy_data(struct archive *ar, struct archive *aw) } r = archive_write_data_block(aw, buff, size, offset); if (r < ARCHIVE_OK) { - ERROR("tar extraction error: %s, %s", archive_error_string(aw), strerror(archive_errno(aw))); + ERROR("tar extraction error: %s", archive_error_string(aw)); return r; } } @@ -672,7 +672,7 @@ int archive_unpack_handler(const struct io_read_wrapper *content, const struct a ret = archive_read_open(a, mydata, NULL, read_content, NULL); if (ret != 0) { ERROR("Failed to open archive: %s", archive_error_string(a)); - fprintf(stderr, "Failed to open archive: %s", strerror(errno)); + fprintf(stderr, "Failed to open archive: %s", archive_error_string(a)); ret = -1; goto out; } @@ -688,9 +688,8 @@ int archive_unpack_handler(const struct io_read_wrapper *content, const struct a } if (ret != ARCHIVE_OK) { - ERROR("Warning reading tar header: %s, %s", archive_error_string(a), strerror(archive_errno(a))); - (void)fprintf(stderr, "Warning reading tar header: %s, %s", archive_error_string(a), - strerror(archive_errno(a))); + ERROR("Warning reading tar header: %s", archive_error_string(a)); + (void)fprintf(stderr, "Warning reading tar header: %s", archive_error_string(a)); ret = -1; goto out; } @@ -724,26 +723,23 @@ int archive_unpack_handler(const struct io_read_wrapper *content, const struct a ret = archive_write_header(ext, entry); if (ret != ARCHIVE_OK) { - ERROR("Fail to handle tar header: %s, %s", archive_error_string(ext), strerror(archive_errno(ext))); - (void)fprintf(stderr, "Fail to handle tar header: %s, %s", archive_error_string(ext), - strerror(archive_errno(ext))); + ERROR("Fail to handle tar header: %s", archive_error_string(ext)); + (void)fprintf(stderr, "Fail to handle tar header: %s", archive_error_string(ext)); ret = -1; goto out; } else if (archive_entry_size(entry) > 0) { ret = copy_data(a, ext); if (ret != ARCHIVE_OK) { - ERROR("Failed to do copy tar data: %s, %s", archive_error_string(ext), strerror(archive_errno(ext))); - (void)fprintf(stderr, "Failed to do copy tar data: %s, %s", archive_error_string(ext), - strerror(archive_errno(ext))); + ERROR("Failed to do copy tar data: %s", archive_error_string(ext)); + (void)fprintf(stderr, "Failed to do copy tar data: %s", archive_error_string(ext)); ret = -1; goto out; } } ret = archive_write_finish_entry(ext); if (ret != ARCHIVE_OK) { - ERROR("Failed to freeing archive entry: %s, %s", archive_error_string(ext), strerror(archive_errno(ext))); - (void)fprintf(stderr, "Failed to freeing archive entry: %s, %s", archive_error_string(ext), - strerror(archive_errno(ext))); + ERROR("Failed to freeing archive entry: %s", archive_error_string(ext)); + (void)fprintf(stderr, "Failed to freeing archive entry: %s", archive_error_string(ext)); ret = -1; goto out; } @@ -824,7 +820,7 @@ int archive_unpack(const struct io_read_wrapper *content, const char *dstdir, co pid = fork(); if (pid == (pid_t) -1) { - ERROR("Failed to fork: %s", strerror(errno)); + SYSERROR("Failed to fork"); goto cleanup; } @@ -844,7 +840,7 @@ int archive_unpack(const struct io_read_wrapper *content, const char *dstdir, co // child process, dup2 pipe_for_read[1] to stderr, if (dup2(pipe_stderr[1], 2) < 0) { - ERROR("Dup fd error: %s", strerror(errno)); + SYSERROR("Dup fd error"); ret = -1; goto child_out; } @@ -876,7 +872,7 @@ child_out: ret = util_wait_for_pid(pid); if (ret != 0) { - ERROR("Wait archive_untar_handler failed with error:%s", strerror(errno)); + SYSERROR("Wait archive_untar_handler failed"); fcntl(pipe_stderr[0], F_SETFL, O_NONBLOCK); if (util_read_nointr(pipe_stderr[0], errbuf, BUFSIZ) < 0) { ERROR("read error message from child failed"); @@ -918,22 +914,21 @@ bool valid_archive_format(const char *file) ret = archive_read_support_filter_all(read_archive); if (ret != ARCHIVE_OK) { - ERROR("Failed to set archive read support filter all, result is %d, errmsg: %s, %s", ret, - archive_error_string(read_archive), strerror(archive_errno(read_archive))); + ERROR("Failed to set archive read support filter all, result is %d, errmsg: %s", ret, + archive_error_string(read_archive)); goto out; } ret = archive_read_support_format_all(read_archive); if (ret != ARCHIVE_OK) { - ERROR("Failed to set archive read support format all, result is %d, errmsg: %s, %s", ret, - archive_error_string(read_archive), strerror(archive_errno(read_archive))); + ERROR("Failed to set archive read support format all, result is %d, errmsg: %s", ret, + archive_error_string(read_archive)); goto out; } ret = archive_read_open_filename(read_archive, file, ARCHIVE_READ_BUFFER_SIZE); if (ret != ARCHIVE_OK) { - ERROR("Failed to open archive %s: %s, %s", file, archive_error_string(read_archive), - strerror(archive_errno(read_archive))); + ERROR("Failed to open archive %s: %s", file, archive_error_string(read_archive)); goto out; } @@ -944,15 +939,13 @@ bool valid_archive_format(const char *file) goto out; } if (ret != ARCHIVE_OK) { - ERROR("Failed to read next header for file %s: %s, %s", file, archive_error_string(read_archive), - strerror(archive_errno(read_archive))); + ERROR("Failed to read next header for file %s: %s", file, archive_error_string(read_archive)); goto out; } out: if (archive_read_free(read_archive) != ARCHIVE_OK) { - ERROR("Failed to free archive %s: %s, %s", file, archive_error_string(read_archive), - strerror(archive_errno(read_archive))); + ERROR("Failed to free archive %s: %s", file, archive_error_string(read_archive)); } read_archive = NULL; @@ -979,19 +972,15 @@ static int copy_data_between_archives(struct archive *ar, struct archive *aw) goto out; } if (size < 0) { - ERROR("tar archive read result %d, error: %s, %s", ret, archive_error_string(ar), - strerror(archive_errno(ar))); - (void)fprintf(stderr, "tar archive read result %d, error: %s, %s", ret, archive_error_string(ar), - strerror(archive_errno(ar))); + ERROR("tar archive read result %d, error: %s", ret, archive_error_string(ar)); + (void)fprintf(stderr, "tar archive read result %d, error: %s", ret, archive_error_string(ar)); ret = ARCHIVE_FAILED; goto out; } ret = archive_write_data(aw, buff, size); if (ret < ARCHIVE_OK) { - ERROR("tar archive write result %d, error: %s, %s", ret, archive_error_string(aw), - strerror(archive_errno(aw))); - (void)fprintf(stderr, "tar archive write result %d, error: %s, %s", ret, archive_error_string(aw), - strerror(archive_errno(aw))); + ERROR("tar archive write result %d, error: %s", ret, archive_error_string(aw)); + (void)fprintf(stderr, "tar archive write result %d, error: %s", ret, archive_error_string(aw)); goto out; } } @@ -1064,8 +1053,8 @@ int tar_handler(struct archive *r, struct archive *w, const char *src_base, cons } if (ret != ARCHIVE_OK) { - ERROR("read from disk failed: %s, %s", archive_error_string(r), strerror(archive_errno(r))); - (void)fprintf(stderr, "read from disk failed: %s, %s", archive_error_string(r), strerror(archive_errno(r))); + ERROR("read from disk failed: %s", archive_error_string(r)); + (void)fprintf(stderr, "read from disk failed: %s", archive_error_string(r)); break; } @@ -1083,37 +1072,34 @@ int tar_handler(struct archive *r, struct archive *w, const char *src_base, cons } ret = archive_write_header(w, entry); if (ret != ARCHIVE_OK) { - ERROR("Fail to write tar header: %s, %s\nlink:%s target:%s", archive_error_string(w), - strerror(archive_errno(w)), archive_entry_pathname(entry), archive_entry_hardlink(entry)); - (void)fprintf(stderr, "Fail to write tar header: %s, %s\nlink:%s target:%s\n", archive_error_string(w), - strerror(archive_errno(w)), archive_entry_pathname(entry), archive_entry_hardlink(entry)); + ERROR("Fail to write tar header: %s.\nlink:%s target:%s", archive_error_string(w), + archive_entry_pathname(entry), archive_entry_hardlink(entry)); + (void)fprintf(stderr, "Fail to write tar header: %s.\nlink:%s target:%s\n", archive_error_string(w), + archive_entry_pathname(entry), archive_entry_hardlink(entry)); break; } if (archive_entry_size(entry) > 0) { ret = copy_data_between_archives(r, w); if (ret != ARCHIVE_OK) { - ERROR("Failed to do copy data: %s, %s", archive_error_string(w), strerror(archive_errno(w))); - (void)fprintf(stderr, "Failed to do copy data: %s, %s\n", archive_error_string(w), - strerror(archive_errno(w))); + ERROR("Failed to do copy data: %s", archive_error_string(w)); + (void)fprintf(stderr, "Failed to do copy data: %s\n", archive_error_string(w)); break; } } ret = archive_write_finish_entry(w); if (ret != ARCHIVE_OK) { - ERROR("Failed to freeing archive entry: %s, %s", archive_error_string(w), strerror(archive_errno(w))); - (void)fprintf(stderr, "Failed to freeing archive entry: %s, %s\n", archive_error_string(w), - strerror(archive_errno(w))); + ERROR("Failed to freeing archive entry: %s", archive_error_string(w)); + (void)fprintf(stderr, "Failed to freeing archive entry: %s\n", archive_error_string(w)); break; } if (archive_entry_filetype(entry) == AE_IFDIR) { ret = archive_read_disk_descend(r); if (ret != ARCHIVE_OK) { - ERROR("read disk descend failed: %s, %s", archive_error_string(w), strerror(archive_errno(w))); - (void)fprintf(stderr, "read disk descend failed: %s, %s\n", archive_error_string(w), - strerror(archive_errno(w))); + ERROR("read disk descend failed: %s", archive_error_string(w)); + (void)fprintf(stderr, "read disk descend failed: %s\n", archive_error_string(w)); break; } } @@ -1169,9 +1155,8 @@ static int tar_all(const struct io_write_wrapper *writer, const char *tar_dir, c archive_read_disk_set_behavior(r, ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS); ret = archive_read_disk_open(r, tar_dir); if (ret != ARCHIVE_OK) { - ERROR("open archive read failed: %s, %s", archive_error_string(r), strerror(archive_errno(r))); - (void)fprintf(stderr, "open archive read failed: %s, %s\n", archive_error_string(r), - strerror(archive_errno(r))); + ERROR("open archive read failed: %s", archive_error_string(r)); + (void)fprintf(stderr, "open archive read failed: %s\n", archive_error_string(r)); goto out; } @@ -1186,9 +1171,8 @@ static int tar_all(const struct io_write_wrapper *writer, const char *tar_dir, c archive_write_set_options(w, "xattrheader=SCHILY"); ret = archive_write_open(w, (void *)writer, NULL, stream_write_data, NULL); if (ret != ARCHIVE_OK) { - ERROR("open archive write failed: %s, %s", archive_error_string(w), strerror(archive_errno(w))); - (void)fprintf(stderr, "open archive write failed: %s, %s\n", archive_error_string(w), - strerror(archive_errno(w))); + ERROR("open archive write failed: %s", archive_error_string(w)); + (void)fprintf(stderr, "open archive write failed: %s\n", archive_error_string(w)); goto out; } @@ -1261,14 +1245,14 @@ int archive_chroot_tar(const char *path, const char *file, const char *root_dir, // child process, dup2 pipe_for_read[1] to stderr, if (dup2(pipe_for_read[1], 2) < 0) { - ERROR("Dup fd error: %s", strerror(errno)); + SYSERROR("Dup fd failed"); ret = -1; goto child_out; } fd = open(file, TAR_DEFAULT_FLAG, TAR_DEFAULT_MODE); if (fd < 0) { - ERROR("Failed to open file %s for export: %s", file, strerror(errno)); + SYSERROR("Failed to open file %s for export", file); fprintf(stderr, "Failed to open file %s for export: %s\n", file, strerror(errno)); ret = -1; goto child_out; @@ -1477,17 +1461,17 @@ int archive_chroot_untar_stream(const struct io_read_wrapper *context, const cha } if (pipe(pipe_stderr) != 0) { - ERROR("Failed to create pipe: %s", strerror(errno)); + SYSERROR("Failed to create pipe"); goto cleanup; } if (pipe(pipe_stream) != 0) { - ERROR("Failed to create pipe: %s", strerror(errno)); + SYSERROR("Failed to create pipe"); goto cleanup; } pid = fork(); if (pid == (pid_t) -1) { - ERROR("Failed to fork: %s", strerror(errno)); + SYSERROR("Failed to fork"); goto cleanup; } @@ -1506,7 +1490,7 @@ int archive_chroot_untar_stream(const struct io_read_wrapper *context, const cha // child process, dup2 pipe_stderr[1] to stderr, if (dup2(pipe_stderr[1], 2) < 0) { - ERROR("Dup fd error: %s", strerror(errno)); + SYSERROR("Dup fd error"); ret = -1; goto child_out; } @@ -1562,7 +1546,7 @@ child_out: while (read_len > 0) { ssize_t writed_len = archive_context_write(ctx, buf, (size_t)read_len); if (writed_len < 0) { - DEBUG("Tar may exited: %s", strerror(errno)); + SYSDEBUG("Tar may exited"); break; } read_len = context->read(context->context, buf, buf_len); @@ -1613,17 +1597,17 @@ int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, cons } if (pipe(pipe_stderr) != 0) { - ERROR("Failed to create pipe: %s", strerror(errno)); + SYSERROR("Failed to create pipe"); goto free_out; } if (pipe(pipe_stream) != 0) { - ERROR("Failed to create pipe: %s", strerror(errno)); + SYSERROR("Failed to create pipe"); goto free_out; } pid = fork(); if (pid == (pid_t) -1) { - ERROR("Failed to fork: %s", strerror(errno)); + SYSERROR("Failed to fork"); goto free_out; } @@ -1645,7 +1629,7 @@ int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, cons // child process, dup2 pipe_stderr[1] to stderr, if (dup2(pipe_stderr[1], 2) < 0) { - ERROR("Dup fd error: %s", strerror(errno)); + SYSERROR("Dup fd error"); ret = -1; goto child_out; } diff --git a/src/utils/tar/util_gzip.c b/src/utils/tar/util_gzip.c index bf649300..0c8c8372 100644 --- a/src/utils/tar/util_gzip.c +++ b/src/utils/tar/util_gzip.c @@ -42,13 +42,13 @@ int util_gzip_z(const char *srcfile, const char *dstfile, const mode_t mode) srcfd = util_open(srcfile, O_RDONLY, SECURE_CONFIG_FILE_MODE); if (srcfd < 0) { - ERROR("Open src file: %s, failed: %s", srcfile, strerror(errno)); + SYSERROR("Open src file: %s, failed", srcfile); return -1; } stream = gzopen(dstfile, "w"); if (stream == NULL) { - ERROR("gzopen %s error: %s", dstfile, strerror(errno)); + SYSERROR("gzopen %s failed", dstfile); close(srcfd); return -1; } @@ -64,7 +64,7 @@ int util_gzip_z(const char *srcfile, const char *dstfile, const mode_t mode) int n; size = util_read_nointr(srcfd, buffer, BLKSIZE); if (size < 0) { - ERROR("read file %s failed: %s", srcfile, strerror(errno)); + SYSERROR("read file %s failed", srcfile); ret = -1; break; } else if (size == 0) { @@ -92,7 +92,7 @@ out: free(buffer); if (ret != 0) { if (util_path_remove(dstfile) != 0) { - ERROR("Remove file %s failed: %s", dstfile, strerror(errno)); + SYSERROR("Remove file %s failed", dstfile); } } @@ -115,7 +115,7 @@ int util_gzip_d(const char *srcfile, const FILE *dstfp) stream = gzopen(srcfile, "r"); if (stream == NULL) { - ERROR("gzopen %s failed: %s", srcfile, strerror(errno)); + SYSERROR("gzopen %s failed", srcfile); return -1; } @@ -142,7 +142,7 @@ int util_gzip_d(const char *srcfile, const FILE *dstfp) size = fwrite(buffer, 1, n, (FILE *)dstfp); if (size != n) { ret = -1; - ERROR("Write file failed: %s", strerror(errno)); + SYSERROR("Write file failed"); break; } } -- 2.40.1