From 017a89c128844288b6a0bb9ffa2696089b9bf104 Mon Sep 17 00:00:00 2001 From: zhangxiaoyu Date: Mon, 25 Apr 2022 20:23:31 +0800 Subject: [PATCH] sync from upstream Signed-off-by: zhangxiaoyu --- 0001-cleancode-http-request.patch | 211 ++++++++++++++++ ...-refactor-mount-parse-in-spec-module.patch | 235 ++++++++++++++++++ ...sula-wait-even-if-it-s-not-oci-image.patch | 30 +++ iSulad.spec | 12 +- 4 files changed, 487 insertions(+), 1 deletion(-) create mode 100644 0001-cleancode-http-request.patch create mode 100644 0002-refactor-mount-parse-in-spec-module.patch create mode 100644 0003-support-isula-wait-even-if-it-s-not-oci-image.patch diff --git a/0001-cleancode-http-request.patch b/0001-cleancode-http-request.patch new file mode 100644 index 0000000..ee8cb2a --- /dev/null +++ b/0001-cleancode-http-request.patch @@ -0,0 +1,211 @@ +From c0900d0bb68cb29484f670a67412447df316ff6e Mon Sep 17 00:00:00 2001 +From: zhangxiaoyu +Date: Tue, 19 Apr 2022 18:33:16 +0800 +Subject: [PATCH 1/3] cleancode: http request + +Signed-off-by: zhangxiaoyu +--- + src/utils/http/http.c | 150 ++++++++++++++++++++++-------------------- + 1 file changed, 77 insertions(+), 73 deletions(-) + +diff --git a/src/utils/http/http.c b/src/utils/http/http.c +index 2ed7fbe8..0b53cf1e 100644 +--- a/src/utils/http/http.c ++++ b/src/utils/http/http.c +@@ -95,38 +95,53 @@ void http_global_cleanup(void) + curl_global_cleanup(); + } + ++static int http_get_header_common(const unsigned int flag, const char *key, const char *value, ++ struct curl_slist **chunk) ++{ ++ int nret = 0; ++ size_t len = 0; ++ char *header = NULL; ++ ++ if (flag == 0 || key == NULL || value == NULL) { ++ return 0; ++ } ++ ++ // format key: value ++ if (strlen(value) > (SIZE_MAX - strlen(key)) - 3) { ++ ERROR("Invalid authorization option"); ++ return -1; ++ } ++ ++ // key + ": " + value + '\0' ++ len = strlen(key) + strlen(value) + 3; ++ header = util_common_calloc_s(len); ++ if (header == NULL) { ++ ERROR("Out of memory"); ++ return -1; ++ } ++ ++ nret = snprintf(header, len, "%s: %s", key, value); ++ if (nret < 0 || (size_t)nret >= len) { ++ ERROR("Failed to print string"); ++ } else { ++ *chunk = curl_slist_append(*chunk, header); ++ } ++ ++ free(header); ++ return nret == 0 ? 0 : -1; ++} ++ + struct curl_slist *http_get_chunk_header(const struct http_get_options *options) + { + int ret = 0; +- int nret; +- size_t len = 0; ++ int i; + struct curl_slist *chunk = NULL; +- char *header = NULL; + char **custom_headers = NULL; +- int i = 0; + +- if (options->with_header_auth && options->authorization) { +- if (strlen(options->authorization) > (SIZE_MAX - strlen("Authorization: ")) - 1) { +- ERROR("Invalid authorization option"); +- ret = -1; +- goto out; +- } +- len = strlen(options->authorization) + strlen("Authorization: ") + 1; +- header = util_common_calloc_s(len); +- if (header == NULL) { +- ERROR("Out of memory"); +- ret = -1; +- goto out; +- } +- nret = snprintf(header, len, "Authorization: %s", options->authorization); +- if (nret < 0 || (size_t)nret >= len) { +- ERROR("Failed to print string"); +- ret = -1; +- goto out; +- } +- chunk = curl_slist_append(chunk, header); +- free(header); +- header = NULL; ++ ret = http_get_header_common(options->with_header_auth, "Authorization", options->authorization, ++ &chunk); ++ if (ret != 0) { ++ goto out; + } + + if (options->with_header_json) { +@@ -140,47 +155,47 @@ struct curl_slist *http_get_chunk_header(const struct http_get_options *options) + chunk = curl_slist_append(chunk, custom_headers[i]); + } + +- if (options->with_header_accept && options->accepts) { +- if (strlen(options->accepts) > (SIZE_MAX - strlen("Accept: ")) - 1) { +- ERROR("Invalid accepts option"); +- ret = -1; +- goto out; +- } +- len = strlen(options->accepts) + strlen("Accept: ") + 1; +- header = util_common_calloc_s(len); +- if (header == NULL) { +- ERROR("Out of memory"); +- ret = -1; +- goto out; +- } +- nret = snprintf(header, len, "Accept: %s", options->accepts); +- if (nret < 0 || (size_t)nret >= len) { +- ERROR("Failed to print string"); +- ret = -1; +- goto out; +- } +- chunk = curl_slist_append(chunk, header); +- free(header); +- header = NULL; ++ ret = http_get_header_common(options->with_header_accept, "Accept", options->accepts, ++ &chunk); ++ if (ret != 0) { ++ goto out; + } ++ + out: +- if (ret) { ++ if (ret != 0) { + curl_slist_free_all(chunk); + chunk = NULL; + } +- free(header); + + return chunk; + } + +-static int http_custom_options(CURL *curl_handle, const struct http_get_options *options) ++static void http_custom_ssl_options(CURL *curl_handle, const struct http_get_options *options) + { +- int ret = 0; ++ if (options->ssl_verify_peer) { ++ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L); ++ } else { ++ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); ++ } ++ if (options->ssl_verify_host) { ++ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2L); ++ } else { ++ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); ++ } + +- if (curl_handle == NULL || options == NULL) { +- return -1; ++ if (options->ca_file != NULL) { ++ curl_easy_setopt(curl_handle, CURLOPT_CAINFO, options->ca_file); ++ } ++ if (options->cert_file != NULL) { ++ curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, options->cert_file); ++ } ++ if (options->key_file != NULL) { ++ curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, options->key_file); + } ++} + ++static void http_custom_general_options(CURL *curl_handle, const struct http_get_options *options) ++{ + if (options->timeout) { + /* complete connection within 30 seconds */ + curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30L); +@@ -222,29 +237,18 @@ static int http_custom_options(CURL *curl_handle, const struct http_get_options + if (options->debug) { + curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); + } ++} + +- if (options->ssl_verify_peer) { +- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L); +- } else { +- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); +- } +- if (options->ssl_verify_host) { +- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2L); +- } else { +- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); ++static int http_custom_options(CURL *curl_handle, const struct http_get_options *options) ++{ ++ if (curl_handle == NULL || options == NULL) { ++ return -1; + } + +- if (options->ca_file != NULL) { +- curl_easy_setopt(curl_handle, CURLOPT_CAINFO, options->ca_file); +- } +- if (options->cert_file != NULL) { +- curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, options->cert_file); +- } +- if (options->key_file != NULL) { +- curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, options->key_file); +- } ++ http_custom_general_options(curl_handle, options); ++ http_custom_ssl_options(curl_handle, options); + +- return ret; ++ return 0; + } + + static void close_file(FILE *pagefile) +-- +2.25.1 + diff --git a/0002-refactor-mount-parse-in-spec-module.patch b/0002-refactor-mount-parse-in-spec-module.patch new file mode 100644 index 0000000..98de307 --- /dev/null +++ b/0002-refactor-mount-parse-in-spec-module.patch @@ -0,0 +1,235 @@ +From b58453982016f9a2f707b51ad54f12583aa21929 Mon Sep 17 00:00:00 2001 +From: wujing +Date: Wed, 20 Apr 2022 10:52:30 +0800 +Subject: [PATCH 2/3] refactor mount parse in spec module + +Signed-off-by: wujing +--- + src/daemon/modules/spec/specs_mount.c | 160 +++++++++++++++++--------- + 1 file changed, 106 insertions(+), 54 deletions(-) + +diff --git a/src/daemon/modules/spec/specs_mount.c b/src/daemon/modules/spec/specs_mount.c +index 5644b21e..c89f077f 100644 +--- a/src/daemon/modules/spec/specs_mount.c ++++ b/src/daemon/modules/spec/specs_mount.c +@@ -580,7 +580,7 @@ out: + static int append_tmpfs_option_size(defs_mount *m, size_t size) + { + int nret = 0; +- char kvbuf[MOUNT_PROPERTIES_SIZE] = {0}; ++ char kvbuf[MOUNT_PROPERTIES_SIZE] = { 0 }; + + if (size == 0) { + return 0; +@@ -604,7 +604,7 @@ static int append_tmpfs_option_size(defs_mount *m, size_t size) + static int append_tmpfs_option_mode(defs_mount *m, uint32_t mode) + { + int nret = 0; +- char kvbuf[MOUNT_PROPERTIES_SIZE] = {0}; ++ char kvbuf[MOUNT_PROPERTIES_SIZE] = { 0 }; + + if (mode == 0) { + return 0; +@@ -625,19 +625,8 @@ static int append_tmpfs_option_mode(defs_mount *m, uint32_t mode) + return 0; + } + +-static defs_mount *parse_mount(mount_spec *spec) ++static int parse_basic_mount_spec_fileds(const mount_spec *spec, defs_mount *m) + { +- int ret = 0; +- defs_mount *m = NULL; +- bool has_pro = false; +- bool has_sel = false; +- +- m = util_common_calloc_s(sizeof(defs_mount)); +- if (m == NULL) { +- ERROR("Out of memory"); +- return NULL; +- } +- + m->type = util_strdup_s(spec->type); + if (strcmp(m->type, MOUNT_TYPE_TMPFS) == 0) { + m->source = util_strdup_s("tmpfs"); +@@ -652,58 +641,122 @@ static defs_mount *parse_mount(mount_spec *spec) + if (spec->readonly) { + if (util_array_append(&m->options, "ro")) { + ERROR("append ro mode to array failed"); +- ret = -1; +- goto out; ++ return -1; + } + m->options_len++; + } + +- if (spec->bind_options != NULL) { +- if (spec->bind_options->propagation != NULL) { +- if (util_array_append(&m->options, spec->bind_options->propagation)) { +- ERROR("append propagation to array failed"); +- ret = -1; +- goto out; +- } +- m->options_len++; +- has_pro = true; +- } +- if (spec->bind_options->selinux_opts != NULL) { +- if (util_array_append(&m->options, spec->bind_options->selinux_opts)) { +- ERROR("append selinux opts to array failed"); +- ret = -1; +- goto out; +- } +- m->options_len++; +- has_sel = true; +- } ++ return 0; ++} ++ ++static int append_spec_bind_mount_options(const mount_spec *spec, defs_mount *m, bool *has_pro, bool *has_sel) ++{ ++ if (spec->bind_options == NULL) { ++ return 0; + } + +- if (spec->volume_options != NULL && spec->volume_options->no_copy) { +- if (util_array_append(&m->options, "nocopy")) { +- ERROR("append nocopy to array failed"); +- ret = -1; +- goto out; ++ if (spec->bind_options->propagation != NULL) { ++ if (util_array_append(&m->options, spec->bind_options->propagation)) { ++ ERROR("append propagation to array failed"); ++ return -1; + } + m->options_len++; ++ *has_pro = true; + } +- +- if (strcmp(m->type, MOUNT_TYPE_TMPFS) == 0 && spec->tmpfs_options != NULL) { +- if (append_tmpfs_option_size(m, (size_t) spec->tmpfs_options->size_bytes) != 0) { +- ERROR("append tmpfs option size failed"); +- ret = -1; +- goto out; ++ if (spec->bind_options->selinux_opts != NULL) { ++ if (util_array_append(&m->options, spec->bind_options->selinux_opts)) { ++ ERROR("append selinux opts to array failed"); ++ return -1; + } ++ m->options_len++; ++ *has_sel = true; ++ } + +- if (append_tmpfs_option_mode(m, spec->tmpfs_options->mode) != 0) { +- ERROR("append tmpfs option mode failed"); +- ret = -1; +- goto out; +- } ++ return 0; ++} ++ ++static int append_spec_volume_options(const mount_spec *spec, defs_mount *m) ++{ ++ if (spec->volume_options == NULL || !spec->volume_options->no_copy) { ++ return 0; ++ } ++ ++ if (util_array_append(&m->options, "nocopy")) { ++ ERROR("append nocopy to array failed"); ++ return -1; ++ } ++ m->options_len++; ++ ++ return 0; ++} ++ ++static int append_spec_tmpfs_options(const mount_spec *spec, defs_mount *m) ++{ ++ if (strcmp(m->type, MOUNT_TYPE_TMPFS) != 0 || spec->tmpfs_options == NULL) { ++ return 0; ++ } ++ ++ if (append_tmpfs_option_size(m, (size_t)spec->tmpfs_options->size_bytes) != 0) { ++ ERROR("append tmpfs option size failed"); ++ return -1; ++ } ++ ++ if (append_tmpfs_option_mode(m, spec->tmpfs_options->mode) != 0) { ++ ERROR("append tmpfs option mode failed"); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static int append_spec_mount_options(const mount_spec *spec, defs_mount *m, bool *has_pro, bool *has_sel) ++{ ++ if (append_spec_bind_mount_options(spec, m, has_pro, has_sel) != 0) { ++ ERROR("Failed to append bind options in v2_spec"); ++ return -1; ++ } ++ ++ if (append_spec_volume_options(spec, m) != 0) { ++ ERROR("Failed to append volume options in v2_spec"); ++ return -1; ++ } ++ ++ if (append_spec_tmpfs_options(spec, m) != 0) { ++ ERROR("Failed to append tmpfs options in v2_spec"); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static defs_mount *parse_mount(const mount_spec *spec) ++{ ++ int ret = 0; ++ defs_mount *m = NULL; ++ bool has_pro = false; ++ bool has_sel = false; ++ ++ m = util_common_calloc_s(sizeof(defs_mount)); ++ if (m == NULL) { ++ ERROR("Out of memory"); ++ return NULL; ++ } ++ ++ ret = parse_basic_mount_spec_fileds(spec, m); ++ if (ret != 0) { ++ ERROR("Failed to parse basic mount fileds in v2_spec"); ++ goto out; ++ } ++ ++ ret = append_spec_mount_options(spec, m, &has_pro, &has_sel); ++ if (ret != 0) { ++ ERROR("Failed to append spec mount options"); ++ goto out; + } + + ret = append_default_mount_options(m, true, has_pro, has_sel); + if (ret != 0) { ++ ERROR("Failed to append default mount options"); + goto out; + } + +@@ -2857,8 +2910,7 @@ static void add_mount(defs_mount **merged_mounts, size_t *merged_mounts_len, def + *merged_mounts_len += 1; + } + +-static int add_embedded_layers(container_config *container_spec, defs_mount **merged_mounts, +- size_t *merged_mounts_len) ++static int add_embedded_layers(container_config *container_spec, defs_mount **merged_mounts, size_t *merged_mounts_len) + { + int ret = 0; + size_t i = 0; +@@ -2976,7 +3028,7 @@ out: + + static char *get_valid_tmpfs_dst_path(char *tmpfs) + { +- char dstpath[PATH_MAX] = {0}; ++ char dstpath[PATH_MAX] = { 0 }; + + if (tmpfs == NULL) { + return NULL; +-- +2.25.1 + diff --git a/0003-support-isula-wait-even-if-it-s-not-oci-image.patch b/0003-support-isula-wait-even-if-it-s-not-oci-image.patch new file mode 100644 index 0000000..0117906 --- /dev/null +++ b/0003-support-isula-wait-even-if-it-s-not-oci-image.patch @@ -0,0 +1,30 @@ +From e0c13b23ddee161a6196ca2e0c970704e4bbef0e Mon Sep 17 00:00:00 2001 +From: WangFengTu +Date: Sun, 24 Apr 2022 14:18:26 +0800 +Subject: [PATCH 3/3] support isula wait even if it's not oci image + +Signed-off-by: WangFengTu +--- + src/cmd/isula/main.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/cmd/isula/main.c b/src/cmd/isula/main.c +index 0e5b845c..2deb862c 100644 +--- a/src/cmd/isula/main.c ++++ b/src/cmd/isula/main.c +@@ -134,11 +134,11 @@ struct command g_commands[] = { + "rmi", false, cmd_rmi_main, g_cmd_rmi_desc, NULL, &g_cmd_rmi_args + }, + #endif +-#ifdef ENABLE_OCI_IMAGE + { + // `wait` sub-command + "wait", false, cmd_wait_main, g_cmd_wait_desc, NULL, &g_cmd_wait_args + }, ++#ifdef ENABLE_OCI_IMAGE + { + // `logs` sub-command + "logs", false, cmd_logs_main, g_cmd_logs_desc, NULL, &g_cmd_logs_args +-- +2.25.1 + diff --git a/iSulad.spec b/iSulad.spec index 1f2cd12..5de7ab9 100644 --- a/iSulad.spec +++ b/iSulad.spec @@ -1,5 +1,5 @@ %global _version 2.0.13 -%global _release 1 +%global _release 2 %global is_systemd 1 %global enable_shimv2 1 %global is_embedded 1 @@ -13,6 +13,10 @@ URL: https://gitee.com/openeuler/iSulad Source: https://gitee.com/openeuler/iSulad/repository/archive/v%{version}.tar.gz BuildRoot: {_tmppath}/iSulad-%{version} +Patch0001: 0001-cleancode-http-request.patch +Patch0002: 0002-refactor-mount-parse-in-spec-module.patch +Patch0003: 0003-support-isula-wait-even-if-it-s-not-oci-image.patch + %ifarch x86_64 aarch64 Provides: libhttpclient.so()(64bit) Provides: libisula.so()(64bit) @@ -239,6 +243,12 @@ fi %endif %changelog +* Mon Apr 25 2022 zhangxiaoyu - 2.0.13-2 +- Type: bugfix +- ID: NA +- SUG: NA +- DESC: sync from upstream + * Mon Apr 18 2022 wangfengtu - 2.0.13-1 - Type: bugfix - ID: NA