1. add hostname env; 2. fix uwait use after free; Signed-off-by: haozi007 <liuhao27@huawei.com>
176 lines
7.0 KiB
Diff
176 lines
7.0 KiB
Diff
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
|
|
|