1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
From 8e442712354a9d4f766d1f90b018fd1246cb9ef2 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Wed, 4 Sep 2024 16:26:59 +1400
Subject: [PATCH 123/149] code improve for codecheck
Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
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
|