代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/iSulad 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From bf50cef67ac2288bed7013c675df8d35f370dc32 Mon Sep 17 00:00:00 2001
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
Date: Sat, 27 Aug 2022 10:40:02 +0800
Subject: [PATCH 02/11] cleancode about rest register container
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
---
src/daemon/common/selinux_label.c | 2 +-
.../connect/rest/rest_containers_service.c | 93 ++++++++++++-------
2 files changed, 62 insertions(+), 33 deletions(-)
diff --git a/src/daemon/common/selinux_label.c b/src/daemon/common/selinux_label.c
index 52422970..145e4b6e 100644
--- a/src/daemon/common/selinux_label.c
+++ b/src/daemon/common/selinux_label.c
@@ -481,7 +481,7 @@ static int uniq_mcs(unsigned int range, char *mcs, size_t len)
c2 = tmp;
}
- nret = snprintf(mcs, len, "s0:c%d,c%d", c1, c2);
+ nret = snprintf(mcs, len, "s0:c%u,c%u", c1, c2);
if (nret < 0 || nret >= len) {
ERROR("Failed to compose mcs");
return -1;
diff --git a/src/daemon/entry/connect/rest/rest_containers_service.c b/src/daemon/entry/connect/rest/rest_containers_service.c
index 53241bef..397660e2 100644
--- a/src/daemon/entry/connect/rest/rest_containers_service.c
+++ b/src/daemon/entry/connect/rest/rest_containers_service.c
@@ -1733,8 +1733,7 @@ out:
free_container_stats_response(cresponse);
}
-/* rest register containers handler */
-int rest_register_containers_handler(evhtp_t *htp)
+static int rest_register_containers_manage_handler(evhtp_t *htp)
{
if (evhtp_set_cb(htp, ContainerServiceCreate, rest_create_cb, NULL) == NULL) {
ERROR("Failed to register create callback");
@@ -1748,10 +1747,6 @@ int rest_register_containers_handler(evhtp_t *htp)
ERROR("Failed to register restart callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceVersion, rest_version_cb, NULL) == NULL) {
- ERROR("Failed to register version callback");
- return -1;
- }
if (evhtp_set_cb(htp, ContainerServiceUpdate, rest_update_cb, NULL) == NULL) {
ERROR("Failed to register update callback");
return -1;
@@ -1760,62 +1755,96 @@ int rest_register_containers_handler(evhtp_t *htp)
ERROR("Failed to register kill callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceInspect, rest_container_inspect_cb, NULL) == NULL) {
- ERROR("Failed to register inspect callback");
+ if (evhtp_set_cb(htp, ContainerServiceRemove, rest_remove_cb, NULL) == NULL) {
+ ERROR("Failed to register remove callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceExec, rest_exec_cb, NULL) == NULL) {
- ERROR("Failed to register exec callback");
+ if (evhtp_set_cb(htp, ContainerServiceStart, rest_start_cb, NULL) == NULL) {
+ ERROR("Failed to register start callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceAttach, rest_attach_cb, NULL) == NULL) {
- ERROR("Failed to register attach callback");
+ if (evhtp_set_cb(htp, ContainerServicePause, rest_pause_cb, NULL) == NULL) {
+ ERROR("Failed to register pause callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceRemove, rest_remove_cb, NULL) == NULL) {
- ERROR("Failed to register remove callback");
+ if (evhtp_set_cb(htp, ContainerServiceResume, rest_resume_cb, NULL) == NULL) {
+ ERROR("Failed to register resume callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceStart, rest_start_cb, NULL) == NULL) {
- ERROR("Failed to register start callback");
+ if (evhtp_set_cb(htp, ContainerServiceWait, rest_wait_cb, NULL) == NULL) {
+ ERROR("Failed to register wait callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceList, rest_list_cb, NULL) == NULL) {
- ERROR("Failed to register list callback");
+ if (evhtp_set_cb(htp, ContainerServiceExport, rest_export_cb, NULL) == NULL) {
+ ERROR("Failed to register export callback");
+ return -1;
+ }
+ if (evhtp_set_cb(htp, ContainerServiceRename, rest_rename_cb, NULL) == NULL) {
+ ERROR("Failed to register rename callback");
+ return -1;
+ }
+ if (evhtp_set_cb(htp, ContainerServiceResize, rest_resize_cb, NULL) == NULL) {
+ ERROR("Failed to register resize callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceWait, rest_wait_cb, NULL) == NULL) {
- ERROR("Failed to register wait callback");
+ return 0;
+}
+
+static int rest_register_containers_info_handler(evhtp_t *htp)
+{
+ if (evhtp_set_cb(htp, ContainerServiceVersion, rest_version_cb, NULL) == NULL) {
+ ERROR("Failed to register version callback");
+ return -1;
+ }
+ if (evhtp_set_cb(htp, ContainerServiceInspect, rest_container_inspect_cb, NULL) == NULL) {
+ ERROR("Failed to register inspect callback");
+ return -1;
+ }
+ if (evhtp_set_cb(htp, ContainerServiceList, rest_list_cb, NULL) == NULL) {
+ ERROR("Failed to register list callback");
return -1;
}
if (evhtp_set_cb(htp, ContainerServiceInfo, rest_info_cb, NULL) == NULL) {
ERROR("Failed to register info callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceExport, rest_export_cb, NULL) == NULL) {
- ERROR("Failed to register export callback");
+ if (evhtp_set_cb(htp, ContainerServiceStats, rest_stats_cb, NULL) == NULL) {
+ ERROR("Failed to register stats callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServicePause, rest_pause_cb, NULL) == NULL) {
- ERROR("Failed to register pause callback");
+
+ return 0;
+}
+
+static int rest_register_containers_stream_handler(evhtp_t *htp)
+{
+ if (evhtp_set_cb(htp, ContainerServiceExec, rest_exec_cb, NULL) == NULL) {
+ ERROR("Failed to register exec callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceResume, rest_resume_cb, NULL) == NULL) {
- ERROR("Failed to register resume callback");
+ if (evhtp_set_cb(htp, ContainerServiceAttach, rest_attach_cb, NULL) == NULL) {
+ ERROR("Failed to register attach callback");
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceRename, rest_rename_cb, NULL) == NULL) {
- ERROR("Failed to register rename callback");
+
+ return 0;
+}
+
+/* rest register containers handler */
+int rest_register_containers_handler(evhtp_t *htp)
+{
+ if (rest_register_containers_manage_handler(htp) != 0) {
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceResize, rest_resize_cb, NULL) == NULL) {
- ERROR("Failed to register resize callback");
+
+ if (rest_register_containers_info_handler(htp) != 0) {
return -1;
}
- if (evhtp_set_cb(htp, ContainerServiceStats, rest_stats_cb, NULL) == NULL) {
- ERROR("Failed to register stats callback");
+
+ if (rest_register_containers_stream_handler(htp) != 0) {
return -1;
}
+
return 0;
}
--
2.25.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。