1 Star 0 Fork 42

songyanting/iSulad

forked from src-openEuler/iSulad 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0024-fix-compile-error-when-building-embedded-image.patch 28.76 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
From ce905c49d29446ea9f60d5a9466b7b68e019a03a Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 30 Dec 2021 09:55:40 +0800
Subject: [PATCH] fix compile error when building embedded image
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
cmake/checker.cmake | 14 ++--
src/CMakeLists.txt | 28 ++++++--
src/cmd/isula/extend/stats.c | 9 +--
src/cmd/isula/main.c | 4 ++
src/cmd/isula/stream/CMakeLists.txt | 11 ++-
src/cmd/isulad/isulad_commands.c | 3 +-
src/cmd/isulad/main.c | 4 ++
.../executor/container_cb/execution_stream.c | 8 ++-
src/daemon/executor/container_cb/list.c | 2 +-
src/daemon/modules/image/CMakeLists.txt | 40 +++++++++--
src/daemon/modules/image/embedded/db/db_all.c | 2 +-
src/daemon/modules/image/embedded/lim.c | 10 +--
src/daemon/modules/log/log_gather.c | 5 +-
src/daemon/modules/plugin/plugin.c | 9 +--
src/daemon/modules/spec/verify.c | 9 +--
src/utils/cutils/utils.c | 2 +-
src/utils/cutils/utils_base64.c | 2 +-
src/utils/tar/CMakeLists.txt | 7 ++
src/utils/tar/isulad_tar.c | 68 ------------------
src/utils/tar/isulad_tar.h | 7 --
src/utils/tar/util_gzip.c | 69 +++++++++++++++++++
src/utils/tar/util_gzip.h | 7 ++
22 files changed, 200 insertions(+), 120 deletions(-)
diff --git a/cmake/checker.cmake b/cmake/checker.cmake
index 7f3ef888..17a324f6 100644
--- a/cmake/checker.cmake
+++ b/cmake/checker.cmake
@@ -56,6 +56,7 @@ find_library(LIBYAJL_LIBRARY yajl
HINTS ${PC_LIBYAJL_LIBDIR} ${PC_LIBYAJL_LIBRARY_DIRS})
_CHECK(LIBYAJL_LIBRARY "LIBYAJL_LIBRARY-NOTFOUND" "libyajl.so")
+if (ENABLE_OCI_IMAGE)
# check libarchive
pkg_check_modules(PC_LIBARCHIVE REQUIRED "libarchive>=3.4")
find_path(LIBARCHIVE_INCLUDE_DIR archive.h
@@ -65,17 +66,18 @@ find_library(LIBARCHIVE_LIBRARY archive
HINTS ${PC_LIBARCHIVE_LIBDIR} ${PC_LIBARCHIVE_LIBRARY_DIRS})
_CHECK(LIBARCHIVE_LIBRARY "LIBARCHIVE_LIBRARY-NOTFOUND" "libarchive.so")
-# check libcrypto
-pkg_check_modules(PC_CRYPTO REQUIRED "libcrypto")
-find_library(CRYPTO_LIBRARY crypto
- HINTS ${PC_CRYPTO_LIBDIR} ${PC_LIBCRYPTO_LIBRARY_DIRS})
-_CHECK(CRYPTO_LIBRARY "CRYPTO_LIBRARY-NOTFOUND" "libcrypto.so")
-
# check websocket
find_path(WEBSOCKET_INCLUDE_DIR libwebsockets.h)
_CHECK(WEBSOCKET_INCLUDE_DIR "WEBSOCKET_INCLUDE_DIR-NOTFOUND" libwebsockets.h)
find_library(WEBSOCKET_LIBRARY websockets)
_CHECK(WEBSOCKET_LIBRARY "WEBSOCKET_LIBRARY-NOTFOUND" "libwebsockets.so")
+endif()
+
+# check libcrypto
+pkg_check_modules(PC_CRYPTO REQUIRED "libcrypto")
+find_library(CRYPTO_LIBRARY crypto
+ HINTS ${PC_CRYPTO_LIBDIR} ${PC_LIBCRYPTO_LIBRARY_DIRS})
+_CHECK(CRYPTO_LIBRARY "CRYPTO_LIBRARY-NOTFOUND" "libcrypto.so")
find_path(HTTP_PARSER_INCLUDE_DIR http_parser.h)
_CHECK(HTTP_PARSER_INCLUDE_DIR "HTTP_PARSER_INCLUDE_DIR-NOTFOUND" "http_parser.h")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 034190a3..1401784b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -73,14 +73,19 @@ set_target_properties(libisula PROPERTIES PREFIX "")
target_link_libraries(libisula
${LIBYAJL_LIBRARY}
- ${SELINUX_LIBRARY}
${ISULA_LIBUTILS_LIBRARY}
- ${LIBARCHIVE_LIBRARY}
${LIBTAR_LIBRARY}
- ${WEBSOCKET_LIBRARY}
${CRYPTO_LIBRARY}
)
+if (ENABLE_OCI_IMAGE)
+ target_link_libraries(libisula ${LIBARCHIVE_LIBRARY} ${WEBSOCKET_LIBRARY})
+endif()
+
+if (ENABLE_SELINUX)
+ target_link_libraries(libisula ${SELINUX_LIBRARY})
+endif()
+
if (ENABLE_SHIM_V2)
target_link_libraries(libisula ${LIBSHIM_V2_LIBRARY})
endif()
@@ -110,7 +115,12 @@ add_executable(isulad-shim
${SHARED_SRCS}
)
target_include_directories(isulad-shim PUBLIC ${ISULAD_SHIM_INCS} ${SHARED_INCS})
-target_link_libraries(isulad-shim ${LIBYAJL_LIBRARY} ${ISULA_LIBUTILS_LIBRARY} ${LIBARCHIVE_LIBRARY} ${LIBTAR_LIBRARY} ${ZLIB_LIBRARY} ${CRYPTO_LIBRARY} -lpthread)
+
+target_link_libraries(isulad-shim ${LIBYAJL_LIBRARY} ${ISULA_LIBUTILS_LIBRARY} ${LIBTAR_LIBRARY} ${ZLIB_LIBRARY} ${CRYPTO_LIBRARY} -lpthread)
+
+if (ENABLE_OCI_IMAGE)
+ target_link_libraries(isulad-shim ${LIBARCHIVE_LIBRARY})
+endif()
# ------ build isula-shim finish -------
@@ -132,7 +142,15 @@ target_include_directories(isulad PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/utils/http
)
-target_link_libraries(isulad ${LIBYAJL_LIBRARY} ${SYSTEMD_LIBRARY} ${SELINUX_LIBRARY} ${LIBARCHIVE_LIBRARY} ${LIBTAR_LIBRARY} ${WEBSOCKET_LIBRARY} ${CRYPTO_LIBRARY})
+target_link_libraries(isulad ${LIBYAJL_LIBRARY} ${SYSTEMD_LIBRARY} ${LIBTAR_LIBRARY} ${CRYPTO_LIBRARY})
+
+if (ENABLE_OCI_IMAGE)
+ target_link_libraries(isulad ${LIBARCHIVE_LIBRARY} ${WEBSOCKET_LIBRARY})
+endif()
+
+if (ENABLE_SELINUX)
+ target_link_libraries(isulad ${SELINUX_LIBRARY})
+endif()
target_link_libraries(isulad -ldl ${ZLIB_LIBRARY} ${ISULA_LIBUTILS_LIBRARY} -lpthread libhttpclient)
diff --git a/src/cmd/isula/extend/stats.c b/src/cmd/isula/extend/stats.c
index 35458f14..21ea34b9 100644
--- a/src/cmd/isula/extend/stats.c
+++ b/src/cmd/isula/extend/stats.c
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <unistd.h>
#include <string.h>
+#include <inttypes.h>
#include "client_arguments.h"
#include "utils.h"
@@ -171,10 +172,10 @@ static void stats_print_original_data(const struct isula_container_info *stats)
short_id[SHORTIDLEN] = '\0';
}
- printf("%-16s %-10llu %-10s %-20lu %-20lu %-15u %-15lu %-15lu %-15lu %-15lu %-15lu %-15lu %-40s", short_id,
- (unsigned long long)stats->pids_current, stats->status, stats->cpu_use_nanos, stats->cpu_system_use,
- stats->online_cpus, stats->blkio_read, stats->blkio_write, stats->mem_used, stats->mem_limit,
- stats->kmem_used, stats->cache, stats->name);
+ printf("%-16s %-10" PRIu64 " %-10s %-20" PRIu64 " %-20" PRIu64 " %-15u %-15" PRIu64 " %-15" PRIu64 " %-15" PRIu64
+ " %-15" PRIu64 " %-15" PRIu64 " %-15" PRIu64 " %-40s", short_id, stats->pids_current, stats->status,
+ stats->cpu_use_nanos, stats->cpu_system_use, stats->online_cpus, stats->blkio_read, stats->blkio_write,
+ stats->mem_used, stats->mem_limit, stats->kmem_used, stats->cache, stats->name);
free(short_id);
}
diff --git a/src/cmd/isula/main.c b/src/cmd/isula/main.c
index a69df5d5..4e7cf1ca 100644
--- a/src/cmd/isula/main.c
+++ b/src/cmd/isula/main.c
@@ -203,6 +203,7 @@ struct command g_commands[] = {
{ NULL, false, NULL, NULL, NULL, NULL } // End of the list
};
+#ifdef ENABLE_OCI_IMAGE
static int set_locale()
{
int ret = 0;
@@ -217,12 +218,15 @@ static int set_locale()
out:
return ret;
}
+#endif
int main(int argc, char **argv)
{
+#ifdef ENABLE_OCI_IMAGE
if (set_locale() != 0) {
exit(ECOMMON);
}
+#endif
if (connect_client_ops_init()) {
return ECOMMON;
diff --git a/src/cmd/isula/stream/CMakeLists.txt b/src/cmd/isula/stream/CMakeLists.txt
index 332435bc..eeb7e4dd 100644
--- a/src/cmd/isula/stream/CMakeLists.txt
+++ b/src/cmd/isula/stream/CMakeLists.txt
@@ -1,7 +1,14 @@
# get current directory sources files
-aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} isula_stream_srcs)
+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_isula_stream_srcs)
+
+# use a separate micro defination for libarchive
+if (DISABLE_OCI)
+ list(REMOVE_ITEM local_isula_stream_srcs
+ ${CMAKE_CURRENT_SOURCE_DIR}/cp.c
+ )
+endif()
set(ISULA_STREAM_SRCS
- ${isula_stream_srcs}
+ ${local_isula_stream_srcs}
PARENT_SCOPE
)
diff --git a/src/cmd/isulad/isulad_commands.c b/src/cmd/isulad/isulad_commands.c
index c2826c83..b37c7208 100644
--- a/src/cmd/isulad/isulad_commands.c
+++ b/src/cmd/isulad/isulad_commands.c
@@ -19,6 +19,7 @@
#include <limits.h>
#include <isula_libutils/host_config.h>
#include <strings.h>
+#include <inttypes.h>
#include "config.h"
#include "isula_libutils/log.h"
@@ -250,7 +251,7 @@ static int check_args_log_conf(const struct service_arguments *args)
/* validate max-size */
if ((args->json_confs->log_driver && strcasecmp("file", args->json_confs->log_driver) == 0) &&
(args->max_size < (4 * 1024))) {
- ERROR("Max-size \"%ld\" must large than 4KB.", args->max_size);
+ ERROR("Max-size \"%" PRId64 "\" must large than 4KB.", args->max_size);
ret = -1;
goto out;
}
diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c
index c981bf1c..16a4f15b 100644
--- a/src/cmd/isulad/main.c
+++ b/src/cmd/isulad/main.c
@@ -1448,6 +1448,7 @@ out:
return ret;
}
+#ifdef ENABLE_OCI_IMAGE
static int set_locale()
{
int ret = 0;
@@ -1462,6 +1463,7 @@ static int set_locale()
out:
return ret;
}
+#endif
/*
* Takes socket path as argument
@@ -1478,9 +1480,11 @@ int main(int argc, char **argv)
exit(ECOMMON);
}
+#ifdef ENABLE_OCI_IMAGE
if (set_locale() != 0) {
exit(ECOMMON);
}
+#endif
http_global_init();
diff --git a/src/daemon/executor/container_cb/execution_stream.c b/src/daemon/executor/container_cb/execution_stream.c
index 4b6cdb10..0921eb19 100644
--- a/src/daemon/executor/container_cb/execution_stream.c
+++ b/src/daemon/executor/container_cb/execution_stream.c
@@ -40,6 +40,7 @@
#include <string.h>
#include <sys/prctl.h>
#include <time.h>
+#include <inttypes.h>
#include "isula_libutils/log.h"
#include "io_wrapper.h"
@@ -343,6 +344,7 @@ pack_response:
return (cc == ISULAD_SUCCESS) ? 0 : -1;
}
+#ifdef ENABLE_OCI_IMAGE
static int copy_from_container_cb_check(const struct isulad_copy_from_container_request *request,
struct isulad_copy_from_container_response **response, container_t **cont)
{
@@ -963,6 +965,7 @@ pack_response:
free(dst_base);
return ret;
}
+#endif
static int container_logs_cb_check(const struct isulad_logs_request *request, struct isulad_logs_response *response)
{
@@ -1626,7 +1629,8 @@ static int container_logs_cb(const struct isulad_logs_request *request, stream_f
goto out;
}
- EVENT("Event: {Object: %s, Content: path: %s, rotate: %d, size: %ld }", id, log_config->path, log_config->rotate,
+ EVENT("Event: {Object: %s, Content: path: %s, rotate: %d, size: %" PRId64 " }", id, log_config->path,
+ log_config->rotate,
log_config->size);
nret = check_log_config(log_config);
@@ -1670,7 +1674,9 @@ void container_stream_callback_init(service_container_callback_t *cb)
{
cb->attach = container_attach_cb;
cb->exec = container_exec_cb;
+#ifdef ENABLE_OCI_IMAGE
cb->copy_from_container = copy_from_container_cb;
cb->copy_to_container = copy_to_container_cb;
+#endif
cb->logs = container_logs_cb;
}
diff --git a/src/daemon/executor/container_cb/list.c b/src/daemon/executor/container_cb/list.c
index d8f26328..67fef06e 100644
--- a/src/daemon/executor/container_cb/list.c
+++ b/src/daemon/executor/container_cb/list.c
@@ -620,7 +620,7 @@ static int pack_list_containers(char **idsarray, const struct list_context *ctx,
}
if (container_nums > (SIZE_MAX / sizeof(container_container *))) {
- ERROR("Get too many containers:%ld", container_nums);
+ ERROR("Get too many containers:%zu", container_nums);
ret = -1;
goto out;
}
diff --git a/src/daemon/modules/image/CMakeLists.txt b/src/daemon/modules/image/CMakeLists.txt
index 14ce571d..bfab0334 100644
--- a/src/daemon/modules/image/CMakeLists.txt
+++ b/src/daemon/modules/image/CMakeLists.txt
@@ -45,7 +45,7 @@ set(IMAGE_INCS
# set sources and headers for libisulad_img
set(LIB_ISULAD_IMG libisulad_img)
-add_library(${LIB_ISULAD_IMG} ${LIBTYPE}
+set(LIB_ISULAD_IMG_SRCS
${local_image_srcs}
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils.c
${CMAKE_SOURCE_DIR}/src/utils/cutils/utils_regex.c
@@ -66,15 +66,29 @@ add_library(${LIB_ISULAD_IMG} ${LIBTYPE}
${CMAKE_SOURCE_DIR}/src/utils/sha256/sha256.c
${CMAKE_SOURCE_DIR}/src/utils/buffer/buffer.c
${CMAKE_SOURCE_DIR}/src/daemon/common/err_msg.c
- ${CMAKE_SOURCE_DIR}/src/daemon/common/selinux_label.c
${CMAKE_SOURCE_DIR}/src/daemon/common/sysinfo.c
- ${CMAKE_SOURCE_DIR}/src/utils/tar/isulad_tar.c
- ${CMAKE_SOURCE_DIR}/src/utils/tar/util_archive.c
${CMAKE_SOURCE_DIR}/src/utils/tar/util_gzip.c
${CMAKE_SOURCE_DIR}/src/daemon/config/isulad_config.c
${CMAKE_SOURCE_DIR}/src/daemon/config/daemon_arguments.c
)
+if (ENALBE_SELINUX)
+ list(APPEND LIB_ISULAD_IMG_SRCS
+ ${CMAKE_SOURCE_DIR}/src/daemon/common/selinux_label.c
+ )
+endif()
+
+if (ENABLE_OCI_IMAGE)
+ list(APPEND LIB_ISULAD_IMG_SRCS
+ ${CMAKE_SOURCE_DIR}/src/utils/tar/isulad_tar.c
+ ${CMAKE_SOURCE_DIR}/src/utils/tar/util_archive.c
+ )
+endif()
+
+add_library(${LIB_ISULAD_IMG} ${LIBTYPE}
+ ${LIB_ISULAD_IMG_SRCS}
+ )
+
target_include_directories(${LIB_ISULAD_IMG} PUBLIC
${local_image_incs}
${CMAKE_SOURCE_DIR}/src/daemon/modules/api
@@ -97,9 +111,21 @@ target_link_libraries(${LIB_ISULAD_IMG}
${ISULA_LIBUTILS_LIBRARY}
${DEVMAPPER_LIBRARY}
${LIBTAR_LIBRARY}
- ${SELINUX_LIBRARY}
- ${LIBARCHIVE_LIBRARY}
- -lpthread -lcrypto -lz libhttpclient)
+ ${CRYPTO_LIBRARY}
+ ${ZLIB_LIBRARY}
+ -lpthread libhttpclient)
+
+if (ENABLE_OCI_IMAGE)
+ target_link_libraries(${LIB_ISULAD_IMG}
+ ${LIBARCHIVE_LIBRARY}
+ )
+endif()
+
+if (ENALBE_SELINUX)
+ target_link_libraries(${LIB_ISULAD_IMG}
+ ${SELINUX_LIBRARY}
+ )
+endif()
target_compile_definitions(${LIB_ISULAD_IMG} PRIVATE LIB_ISULAD_IMG_SO)
diff --git a/src/daemon/modules/image/embedded/db/db_all.c b/src/daemon/modules/image/embedded/db/db_all.c
index 9a611589..47e6e2e0 100644
--- a/src/daemon/modules/image/embedded/db/db_all.c
+++ b/src/daemon/modules/image/embedded/db/db_all.c
@@ -694,7 +694,7 @@ static int read_all_images_info(sqlite3_stmt *stmt, void **data)
goto cleanup;
}
if ((*imagesinfo)->imagesnum > (SIZE_MAX / sizeof(struct db_image *) - 1)) {
- ERROR("List of images is too long:%ld", (*imagesinfo)->imagesnum);
+ ERROR("List of images is too long:%zu", (*imagesinfo)->imagesnum);
goto cleanup;
}
oldsize = (*imagesinfo)->imagesnum * sizeof(struct db_image *);
diff --git a/src/daemon/modules/image/embedded/lim.c b/src/daemon/modules/image/embedded/lim.c
index a3834d3c..538cfff6 100644
--- a/src/daemon/modules/image/embedded/lim.c
+++ b/src/daemon/modules/image/embedded/lim.c
@@ -196,7 +196,7 @@ static bool validate_layer_path_in_host_real(size_t layer_index, char *path_in_h
}
if (!util_valid_file(real_path, fmod)) {
- ERROR("invalid path in host %s, real path is %s, layer %ld", path_in_host, real_path, layer_index);
+ ERROR("invalid path in host %s, real path is %s, layer %zu", path_in_host, real_path, layer_index);
if (fmod == (uint32_t)S_IFREG) {
isulad_try_set_error_message(
"Invalid content in manifest: layer(except first layer) is not a regular file");
@@ -218,13 +218,13 @@ static bool validate_layer_path_in_host(size_t layer_index, const char *location
if (layer_index == 0) {
/* layer 0 is absolute path of rootfs device or host / */
if (!valid_absolute_path(path_in_host)) {
- ERROR("path in host %s not a absolute path, layer %lu", path_in_host, layer_index);
+ ERROR("path in host %s not a absolute path, layer %zu", path_in_host, layer_index);
isulad_try_set_error_message("Invalid content in manifest: first layer path in host must be absolute path");
return false;
}
if ((int)fmod == S_IFDIR && strcmp(path_in_host, "/") != 0) {
- ERROR("expected / as root, got %s, layer %lu", path_in_host, layer_index);
+ ERROR("expected / as root, got %s, layer %zu", path_in_host, layer_index);
isulad_try_set_error_message("Invalid content in manifest: first layer path in host must be /");
return false;
}
@@ -235,7 +235,7 @@ static bool validate_layer_path_in_host(size_t layer_index, const char *location
char parent_location[PATH_MAX] = { 0 };
int sret = 0;
if (!valid_relative_path(path_in_host)) {
- ERROR("path in host %s not a relative path, layer %lu", path_in_host, layer_index);
+ ERROR("path in host %s not a relative path, layer %zu", path_in_host, layer_index);
isulad_try_set_error_message("Invalid content in manifest:"
" layer path in host(except first layer) must be relative path");
return false;
@@ -409,7 +409,7 @@ static bool validate_image_name(char *image_name)
static bool validate_image_layers_number(size_t layers_len)
{
if (layers_len > LAYER_NUM_MAX || layers_len < 1) {
- ERROR("invalid layers number %ld maxium is %d", layers_len, LAYER_NUM_MAX);
+ ERROR("invalid layers number %zu maxium is %d", layers_len, LAYER_NUM_MAX);
isulad_try_set_error_message("Invalid content in manifest: layer empty or max depth exceeded");
return false;
}
diff --git a/src/daemon/modules/log/log_gather.c b/src/daemon/modules/log/log_gather.c
index b9813917..51c112a3 100644
--- a/src/daemon/modules/log/log_gather.c
+++ b/src/daemon/modules/log/log_gather.c
@@ -26,11 +26,12 @@
#include <stdio.h>
#include <strings.h>
#include <sys/prctl.h>
+#include <inttypes.h>
#include "log_gather_api.h"
#include "isula_libutils/log.h"
#include "utils.h"
-#include "isulad_tar.h"
+#include "util_gzip.h"
#include "utils_file.h"
typedef int (*log_save_t)(const void *buf, size_t count);
@@ -223,7 +224,7 @@ static int check_log_file()
if (ret != 0) {
COMMAND_ERROR("Rotate log file %s failed.", g_log_file);
} else {
- INFO("Log file large than %lu, rotate it.", g_max_size);
+ INFO("Log file large than %" PRIu64", rotate it.", g_max_size);
}
} else {
ret = 0;
diff --git a/src/daemon/modules/plugin/plugin.c b/src/daemon/modules/plugin/plugin.c
index 25326567..9fe6dc8b 100644
--- a/src/daemon/modules/plugin/plugin.c
+++ b/src/daemon/modules/plugin/plugin.c
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
+#include <inttypes.h>
#include "isula_libutils/log.h"
#include "plugin_api.h"
@@ -519,7 +520,7 @@ static int pm_register_plugin(const char *name, const char *addr)
goto failed;
}
- INFO("add activated plugin %s 0x%lx", plugin->name, plugin->manifest->watch_event);
+ INFO("add activated plugin %s 0x%" PRIx64, plugin->name, plugin->manifest->watch_event);
return 0;
failed:
@@ -854,7 +855,7 @@ bool plugin_is_watching(plugin_t *plugin, uint64_t pe)
}
plugin_unlock(plugin);
- INFO("plugin %s watching=%s for event 0x%lx", plugin->name, (ok ? "true" : "false"), pe);
+ INFO("plugin %s watching=%s for event 0x%" PRIx64, plugin->name, (ok ? "true" : "false"), pe);
return ok;
}
@@ -885,7 +886,7 @@ static int unpack_activate_response(const struct parsed_http_message *message, v
goto out;
}
- INFO("get resp 0x%lx", resp->watch_event);
+ INFO("get resp 0x%" PRIx64, resp->watch_event);
manifest->init_type = resp->init_type;
manifest->watch_event = resp->watch_event;
@@ -1371,7 +1372,7 @@ static int plugin_event_handle_dispath_impl(const char *cid, const char *plugins
ret = plugin_event_post_remove_handle(plugin, cid);
break;
default:
- ERROR("plugin event %ld not support.", pe);
+ ERROR("plugin event %" PRIu64 " not support.", pe);
ret = -1;
break;
}
diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c
index 57501cde..245beb8b 100644
--- a/src/daemon/modules/spec/verify.c
+++ b/src/daemon/modules/spec/verify.c
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <string.h>
#include <linux/oom.h>
+#include <inttypes.h>
#include "constants.h"
#include "err_msg.h"
@@ -962,8 +963,8 @@ static bool check_hugetlbs_repeated(size_t newlen, const char *pagesize,
for (j = 0; j < newlen; j++) {
if (newtlb[j] != NULL && newtlb[j]->page_size != NULL && !strcmp(newtlb[j]->page_size, pagesize)) {
- WARN("hugetlb-limit setting of %s is repeated, former setting %lu will be replaced with %lu", pagesize,
- newtlb[j]->limit, hugetlb->limit);
+ WARN("hugetlb-limit setting of %s is repeated, former setting %" PRIu64 " will be replaced with %" PRIu64,
+ pagesize, newtlb[j]->limit, hugetlb->limit);
newtlb[j]->limit = hugetlb->limit;
repeated = true;
goto out;
@@ -1090,7 +1091,7 @@ static int verify_resources_device(defs_resources *resources)
for (i = 0; i < resources->devices_len; i++) {
if (!util_valid_device_mode(resources->devices[i]->access)) {
- ERROR("Invalid device mode \"%s\" for device \"%ld %ld\"", resources->devices[i]->access,
+ ERROR("Invalid device mode \"%s\" for device \"%" PRId64" %" PRId64 "\"", resources->devices[i]->access,
resources->devices[i]->major, resources->devices[i]->minor);
isulad_set_error_message("Invalid device mode \"%s\" for device \"%ld %ld\"", resources->devices[i]->access,
resources->devices[i]->major, resources->devices[i]->minor);
@@ -1678,7 +1679,7 @@ static int add_hugetbl_element(host_config_hugetlbs_element ***hugetlb, size_t *
for (j = 0; j < *len; j++) {
if (strcmp((*hugetlb)[j]->page_size, pagesize) == 0) {
WARN("Hostconfig: hugetlb-limit setting of %s is repeated, "
- "former setting %lu will be replaced with %lu",
+ "former setting %" PRIu64 " will be replaced with %" PRIu64,
pagesize, (*hugetlb)[j]->limit, element->limit);
(*hugetlb)[j]->limit = element->limit;
goto out;
diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c
index 511cde96..850b2329 100644
--- a/src/utils/cutils/utils.c
+++ b/src/utils/cutils/utils.c
@@ -1358,7 +1358,7 @@ int util_normalized_host_os_arch(char **host_os, char **host_arch, char **host_v
*host_arch = util_strdup_s("arm64");
} else if ((strcasecmp("armhf", uts.machine) == 0) || (strcasecmp("armel", uts.machine) == 0)) {
*host_arch = util_strdup_s("arm");
- } else if ((strcasecmp("mips64le", uts.machine) == 0) || (strcasecmp("mips64el", uts.machine) == 0)) {
+ } else if ((strcasecmp("mips64le", uts.machine) == 0) || (strcasecmp("mips64el", uts.machine) == 0)) {
*host_arch = util_strdup_s("mips64le");
} else {
*host_arch = util_strdup_s(uts.machine);
diff --git a/src/utils/cutils/utils_base64.c b/src/utils/cutils/utils_base64.c
index 2eb6b6bd..a2b0d7a4 100644
--- a/src/utils/cutils/utils_base64.c
+++ b/src/utils/cutils/utils_base64.c
@@ -115,7 +115,7 @@ size_t util_base64_decode_len(const char *input, size_t len)
size_t padding_count = 0;
if (input == NULL || len < 4 || len % 4 != 0) {
- ERROR("Invalid param for base64 decode length, length is %ld", len);
+ ERROR("Invalid param for base64 decode length, length is %zu", len);
return -1;
}
diff --git a/src/utils/tar/CMakeLists.txt b/src/utils/tar/CMakeLists.txt
index 0f3a56c1..97532ad1 100644
--- a/src/utils/tar/CMakeLists.txt
+++ b/src/utils/tar/CMakeLists.txt
@@ -1,6 +1,13 @@
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_tar_srcs)
+if (DISABLE_OCI)
+ list(REMOVE_ITEM local_tar_srcs
+ ${CMAKE_CURRENT_SOURCE_DIR}/util_archive.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/isulad_tar.c
+ )
+endif()
+
set(TAR_SRCS
${local_tar_srcs}
PARENT_SCOPE
diff --git a/src/utils/tar/isulad_tar.c b/src/utils/tar/isulad_tar.c
index 03277373..228e091a 100644
--- a/src/utils/tar/isulad_tar.c
+++ b/src/utils/tar/isulad_tar.c
@@ -19,8 +19,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/wait.h>
#include <limits.h>
#include <sys/stat.h>
#include <errno.h>
@@ -50,72 +48,6 @@ void free_archive_copy_info(struct archive_copy_info *info)
free(info);
}
-/*
- * compress file.
- * param filename: archive file to compres.
- * return: zero if compress success, non-zero if not.
- */
-int gzip(const char *filename, size_t len)
-{
- int pipefd[2] = { -1, -1 };
- int status = 0;
- pid_t pid = 0;
-
- if (filename == NULL) {
- return -1;
- }
- if (len == 0) {
- return -1;
- }
-
- if (pipe2(pipefd, O_CLOEXEC) != 0) {
- ERROR("Failed to create pipe\n");
- return -1;
- }
-
- pid = fork();
- if (pid == -1) {
- ERROR("Failed to fork()\n");
- close(pipefd[0]);
- close(pipefd[1]);
- return -1;
- }
-
- if (pid == 0) {
- // child process, dup2 pipefd[1] to stderr
- close(pipefd[0]);
- dup2(pipefd[1], 2);
-
- if (!util_valid_cmd_arg(filename)) {
- fprintf(stderr, "Invalid filename: %s\n", filename);
- exit(EXIT_FAILURE);
- }
-
- execlp("gzip", "gzip", "-f", filename, NULL);
-
- fprintf(stderr, "Failed to exec gzip");
- exit(EXIT_FAILURE);
- }
-
- ssize_t size_read = 0;
- char buffer[BUFSIZ] = { 0 };
-
- close(pipefd[1]);
-
- if (waitpid(pid, &status, 0) != pid) {
- close(pipefd[0]);
- return -1;
- }
-
- size_read = read(pipefd[0], buffer, BUFSIZ);
- close(pipefd[0]);
-
- if (size_read) {
- ERROR("Received error:\n%s", buffer);
- }
- return status;
-}
-
static int get_rebase_name(const char *path, const char *real_path, char **resolved_path, char **rebase_name)
{
int nret;
diff --git a/src/utils/tar/isulad_tar.h b/src/utils/tar/isulad_tar.h
index c773fe9b..31d2d24a 100644
--- a/src/utils/tar/isulad_tar.h
+++ b/src/utils/tar/isulad_tar.h
@@ -47,13 +47,6 @@ struct archive_tar_resource_rebase_opts {
char *include_file;
};
-/*
- * compress file.
- * param filename : archive file to compres.
- * return: zero if compress success, non-zero if not.
- */
-int gzip(const char *filename, size_t len);
-
struct archive_copy_info *copy_info_source_path(const char *path, bool follow_link, char **err);
char *prepare_archive_copy(const struct archive_copy_info *srcinfo, const struct archive_copy_info *dstinfo,
diff --git a/src/utils/tar/util_gzip.c b/src/utils/tar/util_gzip.c
index 8733bcbc..9b17e9d7 100644
--- a/src/utils/tar/util_gzip.c
+++ b/src/utils/tar/util_gzip.c
@@ -16,6 +16,8 @@
#include "util_gzip.h"
#include <zlib.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include "utils.h"
#include "isula_libutils/log.h"
@@ -151,3 +153,70 @@ out:
return ret;
}
+
+/*
+ * compress file.
+ * param filename: archive file to compres.
+ * return: zero if compress success, non-zero if not.
+ */
+int gzip(const char *filename, size_t len)
+{
+ int pipefd[2] = { -1, -1 };
+ int status = 0;
+ pid_t pid = 0;
+
+ if (filename == NULL) {
+ return -1;
+ }
+ if (len == 0) {
+ return -1;
+ }
+
+ if (pipe2(pipefd, O_CLOEXEC) != 0) {
+ ERROR("Failed to create pipe\n");
+ return -1;
+ }
+
+ pid = fork();
+ if (pid == -1) {
+ ERROR("Failed to fork()\n");
+ close(pipefd[0]);
+ close(pipefd[1]);
+ return -1;
+ }
+
+ if (pid == 0) {
+ // child process, dup2 pipefd[1] to stderr
+ close(pipefd[0]);
+ dup2(pipefd[1], 2);
+ dup2(pipefd[1], 2);
+
+ if (!util_valid_cmd_arg(filename)) {
+ fprintf(stderr, "Invalid filename: %s\n", filename);
+ exit(EXIT_FAILURE);
+ }
+
+ execlp("gzip", "gzip", "-f", filename, NULL);
+
+ fprintf(stderr, "Failed to exec gzip");
+ exit(EXIT_FAILURE);
+ }
+
+ ssize_t size_read = 0;
+ char buffer[BUFSIZ] = { 0 };
+
+ close(pipefd[1]);
+
+ if (waitpid(pid, &status, 0) != pid) {
+ close(pipefd[0]);
+ return -1;
+ }
+
+ size_read = read(pipefd[0], buffer, BUFSIZ);
+ close(pipefd[0]);
+
+ if (size_read) {
+ ERROR("Received error:\n%s", buffer);
+ }
+ return status;
+}
diff --git a/src/utils/tar/util_gzip.h b/src/utils/tar/util_gzip.h
index 637997bd..7d881e92 100644
--- a/src/utils/tar/util_gzip.h
+++ b/src/utils/tar/util_gzip.h
@@ -28,6 +28,13 @@ 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);
+/*
+ * compress file.
+ * param filename: archive file to compres.
+ * return: zero if compress success, non-zero if not.
+ */
+int gzip(const char *filename, size_t len);
+
#ifdef __cplusplus
}
#endif
--
2.25.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/songyanting1/iSulad.git
git@gitee.com:songyanting1/iSulad.git
songyanting1
iSulad
iSulad
master

搜索帮助

A270a887 8829481 3d7a4017 8829481