1 Star 0 Fork 43

zhongtao/src-iSulad

forked from src-openEuler/iSulad 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0123-code-improve-for-codecheck.patch 10.43 KB
一键复制 编辑 原始数据 按行查看 历史
From 8e442712354a9d4f766d1f90b018fd1246cb9ef2 Mon Sep 17 00:00:00 2001
From: zhongtao <[email protected]>
Date: Wed, 4 Sep 2024 16:26:59 +1400
Subject: [PATCH 123/149] code improve for codecheck
Signed-off-by: zhongtao <[email protected]>
---
src/daemon/common/sysinfo.h | 8 ++++----
src/daemon/entry/cri/network_plugin.cc | 2 +-
src/daemon/mailbox/message_queue.h | 8 ++++----
src/daemon/mailbox/message_subscriber.h | 8 ++++++++
src/daemon/modules/runtime/shim/shim_rt_monitor.cc | 2 ++
src/daemon/nri/nri_adaption.h | 1 -
src/daemon/sandbox/sandbox_manager.cc | 5 ++---
src/utils/cutils/blocking_queue.h | 2 +-
src/utils/cutils/utils_aes.h | 2 +-
src/utils/cutils/utils_cap.h | 7 +++----
src/utils/cutils/utils_fs.h | 2 +-
src/utils/cutils/utils_network.c | 2 ++
src/utils/cutils/utils_string.h | 3 +--
src/utils/tar/util_archive.h | 5 ++---
src/utils/tar/util_gzip.h | 2 +-
15 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/src/daemon/common/sysinfo.h b/src/daemon/common/sysinfo.h
index 6142487b..e6bb7f95 100644
--- a/src/daemon/common/sysinfo.h
+++ b/src/daemon/common/sysinfo.h
@@ -15,16 +15,16 @@
#ifndef DAEMON_COMMON_SYSINFO_H
#define DAEMON_COMMON_SYSINFO_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include <stdbool.h>
#include <stdint.h>
#include <isula_libutils/auto_cleanup.h>
#include "cgroup.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct {
// Number of processors currently online (i.e., available).
int ncpus;
diff --git a/src/daemon/entry/cri/network_plugin.cc b/src/daemon/entry/cri/network_plugin.cc
index f8f9c7e6..439d0224 100644
--- a/src/daemon/entry/cri/network_plugin.cc
+++ b/src/daemon/entry/cri/network_plugin.cc
@@ -198,7 +198,7 @@ void InitNetworkPlugin(std::vector<std::shared_ptr<NetworkPlugin>> *plugins, std
if (networkPluginName.empty()) {
DEBUG("network plugin name empty");
- *result = std::shared_ptr<NetworkPlugin>(new (std::nothrow) NoopNetworkPlugin);
+ *result = std::make_shared<NoopNetworkPlugin>();
if (*result == nullptr) {
ERROR("Out of memory");
return;
diff --git a/src/daemon/mailbox/message_queue.h b/src/daemon/mailbox/message_queue.h
index 7905840f..c9bbc9e2 100644
--- a/src/daemon/mailbox/message_queue.h
+++ b/src/daemon/mailbox/message_queue.h
@@ -16,10 +16,6 @@
#ifndef DAEMON_MESSAGE_MESSAGE_QUEUE_H
#define DAEMON_MESSAGE_MESSAGE_QUEUE_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include <pthread.h>
#include "blocking_queue.h"
@@ -27,6 +23,10 @@ extern "C" {
#include "map.h"
#include "message_subscriber.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct message_queue {
blocking_queue *messages;
diff --git a/src/daemon/mailbox/message_subscriber.h b/src/daemon/mailbox/message_subscriber.h
index de4574d9..2987b60d 100644
--- a/src/daemon/mailbox/message_subscriber.h
+++ b/src/daemon/mailbox/message_subscriber.h
@@ -19,6 +19,10 @@
#include "blocking_queue.h"
#include "mailbox_message.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct {
blocking_queue *queue;
} message_subscriber;
@@ -38,4 +42,8 @@ define_auto_cleanup_callback(message_subscriber_destroy, message_subscriber);
// define auto free macro for blocking queue
#define __isula_auto_subscriber auto_cleanup_tag(message_subscriber_destroy)
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/src/daemon/modules/runtime/shim/shim_rt_monitor.cc b/src/daemon/modules/runtime/shim/shim_rt_monitor.cc
index 2547a206..97f5cd68 100644
--- a/src/daemon/modules/runtime/shim/shim_rt_monitor.cc
+++ b/src/daemon/modules/runtime/shim/shim_rt_monitor.cc
@@ -30,6 +30,8 @@
#include "utils.h"
#include "error.h"
+// The shim v2 header file needs to be modified to
+// use extern "C" to wrap external functions.
extern "C" {
#include <shim_v2.h>
}
diff --git a/src/daemon/nri/nri_adaption.h b/src/daemon/nri/nri_adaption.h
index 27a6d93e..6bd41941 100644
--- a/src/daemon/nri/nri_adaption.h
+++ b/src/daemon/nri/nri_adaption.h
@@ -16,7 +16,6 @@
#ifndef DAEMON_NRI_PLUGIN_NRI_ADAPTION_H
#define DAEMON_NRI_PLUGIN_NRI_ADAPTION_H
-// #include "read_write_lock.h"
#include <isula_libutils/nri_update_containers_request.h>
#include <isula_libutils/nri_update_containers_response.h>
diff --git a/src/daemon/sandbox/sandbox_manager.cc b/src/daemon/sandbox/sandbox_manager.cc
index cee444f4..4159993f 100644
--- a/src/daemon/sandbox/sandbox_manager.cc
+++ b/src/daemon/sandbox/sandbox_manager.cc
@@ -109,8 +109,7 @@ auto SandboxManager::CreateSandbox(const std::string &name, RuntimeInfo &info, s
return nullptr;
}
- sandbox = std::shared_ptr<Sandbox>(new Sandbox(id, m_rootdir, m_statedir, name, info, netMode, netNsPath,
- sandboxConfig, image));
+ sandbox = std::make_shared<Sandbox>(id, m_rootdir, m_statedir, name, info, netMode, netNsPath, sandboxConfig, image);
if (sandbox == nullptr) {
ERROR("Failed to malloc for sandbox: %s", name.c_str());
error.Errorf("Failed to malloc for sandbox: %s", name.c_str());
@@ -452,7 +451,7 @@ auto SandboxManager::LoadSandbox(std::string &id) -> std::shared_ptr<Sandbox>
return nullptr;
}
- sandbox = std::shared_ptr<Sandbox>(new Sandbox(id, m_rootdir, m_statedir));
+ sandbox = std::make_shared<Sandbox>(id, m_rootdir, m_statedir);
if (sandbox == nullptr) {
ERROR("Failed to malloc for sandboxes: %s", id.c_str());
return nullptr;
diff --git a/src/utils/cutils/blocking_queue.h b/src/utils/cutils/blocking_queue.h
index 257779c3..e6931501 100644
--- a/src/utils/cutils/blocking_queue.h
+++ b/src/utils/cutils/blocking_queue.h
@@ -26,7 +26,7 @@
extern "C" {
#endif
-#define BLOCKING_QUEUE_NO_TIMEOUT -1
+#define BLOCKING_QUEUE_NO_TIMEOUT (-1)
typedef struct blocking_node {
void *data;
diff --git a/src/utils/cutils/utils_aes.h b/src/utils/cutils/utils_aes.h
index bd2c2065..8ff6dad8 100644
--- a/src/utils/cutils/utils_aes.h
+++ b/src/utils/cutils/utils_aes.h
@@ -26,7 +26,7 @@ extern "C" {
#define AES_256_CFB_KEY_LEN 32
#define AES_256_CFB_IV_LEN 16
-int util_aes_key(const char *key_path, bool create, unsigned char *aeskey);
+int util_aes_key(const char *key_file, bool create, unsigned char *aeskey);
// note: Input bytes is "IV+data", "bytes+AES_256_CFB_IV_LEN" is the real data to be encoded.
// The output length is the input "len" and add the '\0' after end of the length.
diff --git a/src/utils/cutils/utils_cap.h b/src/utils/cutils/utils_cap.h
index de63d070..c7e78ac2 100644
--- a/src/utils/cutils/utils_cap.h
+++ b/src/utils/cutils/utils_cap.h
@@ -16,14 +16,13 @@
#ifndef UTILS_CUTILS_UTILS_CAP_H
#define UTILS_CUTILS_UTILS_CAP_H
+#include <stdbool.h>
+#include <stddef.h>
+
#ifdef __cplusplus
extern "C" {
#endif
-#include <stdbool.h>
-#include <stddef.h>
-#include <linux/capability.h>
-
bool util_valid_cap(const char *cap);
/**
diff --git a/src/utils/cutils/utils_fs.h b/src/utils/cutils/utils_fs.h
index c44fed8c..438af416 100644
--- a/src/utils/cutils/utils_fs.h
+++ b/src/utils/cutils/utils_fs.h
@@ -34,7 +34,7 @@ bool util_detect_mounted(const char *path);
int util_ensure_mounted_as(const char *dst, const char *mntopts);
int util_mount_from(const char *base, const char *src, const char *dst, const char *mtype, const char *mntopts);
typedef int (*mount_info_call_back_t)(const char *, const char *);
-bool util_deal_with_mount_info(mount_info_call_back_t cb, const char *);
+bool util_deal_with_mount_info(mount_info_call_back_t cb, const char *pattern);
bool util_check_readonly_fs(const char *path);
#ifdef __cplusplus
}
diff --git a/src/utils/cutils/utils_network.c b/src/utils/cutils/utils_network.c
index bb6a2f87..be33ec87 100644
--- a/src/utils/cutils/utils_network.c
+++ b/src/utils/cutils/utils_network.c
@@ -801,6 +801,8 @@ static bool is_invalid_char(char c)
return true;
case ' ':
return true;
+ default:
+ return false;
}
return false;
}
diff --git a/src/utils/cutils/utils_string.h b/src/utils/cutils/utils_string.h
index 0de2266c..d37343d5 100644
--- a/src/utils/cutils/utils_string.h
+++ b/src/utils/cutils/utils_string.h
@@ -17,7 +17,6 @@
#define UTILS_CUTILS_UTILS_STRING_H
#include <stdbool.h>
#include <stddef.h>
-#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus
@@ -48,7 +47,7 @@ char **util_string_split(const char *src_str, char _sep);
// note that every delimiter bytes is considered to be a single delimiter
char **util_string_split_multi(const char *src_str, char delim);
-char **util_string_split_n(const char *src_str, char delim, size_t n);
+char **util_string_split_n(const char *src, char sep, size_t n);
const char *util_str_skip_str(const char *str, const char *skip);
diff --git a/src/utils/tar/util_archive.h b/src/utils/tar/util_archive.h
index 8f0ab2a4..98597d53 100644
--- a/src/utils/tar/util_archive.h
+++ b/src/utils/tar/util_archive.h
@@ -53,9 +53,8 @@ int archive_chroot_tar(const char *path, const char *file, const char *root_dir,
int archive_chroot_tar_stream(const char *chroot_dir, const char *tar_path, const char *src_base,
const char *dst_base, const char *root_dir, struct io_read_wrapper *content);
-int archive_chroot_untar_stream(const struct io_read_wrapper *content, const char *chroot_dir,
- const char *untar_dir, const char *src_base, const char *dst_base,
- const char *root_dir, char **errmsg);
+int archive_chroot_untar_stream(const struct io_read_wrapper *context, const char *chroot_dir, const char *untar_dir,
+ const char *src_base, const char *dst_base, const char *root_dir, char **errmsg);
int archive_copy_oci_tar_split_and_ret_size(int src_fd, const char *dist_file, int64_t *ret_size);
diff --git a/src/utils/tar/util_gzip.h b/src/utils/tar/util_gzip.h
index 7d881e92..7797c5f9 100644
--- a/src/utils/tar/util_gzip.h
+++ b/src/utils/tar/util_gzip.h
@@ -26,7 +26,7 @@ extern "C" {
int util_gzip_z(const char *srcfile, const char *dstfile, const mode_t mode);
// Decompress
-int util_gzip_d(const char *srcfile, const FILE *destfp);
+int util_gzip_d(const char *srcfile, const FILE *dstfp);
/*
* compress file.
--
2.25.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/taotao-sauce/src-iSulad.git
[email protected]:taotao-sauce/src-iSulad.git
taotao-sauce
src-iSulad
src-iSulad
master

搜索帮助