From 058adb5b47593694199a3270ee8799b2950b7373 Mon Sep 17 00:00:00 2001 From: lifeng68 Date: Tue, 30 Jun 2020 11:42:30 +0800 Subject: [PATCH] refact: add api head files to api directory Signed-off-by: lifeng68 --- src/cmd/isulad/main.c | 10 +-- src/daemon/entry/cri/cri_image_service.cc | 4 +- src/daemon/executor/container_cb/execution.c | 10 +-- .../executor/container_cb/execution_create.c | 10 +-- .../executor/container_cb/execution_extend.c | 10 +-- .../container_cb/execution_information.c | 17 +++-- .../executor/container_cb/execution_stream.c | 6 +- src/daemon/executor/container_cb/io_handler.c | 6 +- src/daemon/executor/image_cb/image_cb.c | 4 +- src/daemon/modules/api/container_api.h | 2 - .../{events_sender => api}/event_type.h | 0 .../events_collector_api.h} | 0 .../events_sender_api.h} | 0 .../log_gather.h => api/log_gather_api.h} | 0 .../{plugin/plugin.h => api/plugin_api.h} | 27 ++++---- .../{runtime/runtime.h => api/runtime_api.h} | 0 .../service_container_api.h} | 6 +- .../service_image_api.h} | 0 .../modules/{spec/specs.h => api/specs_api.h} | 14 ++-- .../container/container_events_handler.c | 4 +- .../container/container_gc/containers_gc.c | 4 +- .../container/health_check/health_check.c | 25 +++---- .../restart_manager/restartmanager.c | 3 +- .../modules/container/restore/restore.c | 4 +- .../modules/container/supervisor/supervisor.c | 4 +- src/daemon/modules/events/collector.c | 2 +- src/daemon/modules/events/monitord.c | 4 +- .../modules/events_sender/event_sender.c | 24 +++---- src/daemon/modules/log/log_gather.c | 5 +- src/daemon/modules/plugin/plugin.c | 4 +- src/daemon/modules/plugin/pspec.c | 17 ++--- src/daemon/modules/runtime/engines/engine.h | 2 +- .../modules/runtime/engines/lcr/lcr_rt_ops.c | 2 +- .../modules/runtime/engines/lcr/lcr_rt_ops.h | 2 +- .../modules/runtime/isula/isula_rt_ops.c | 6 +- .../modules/runtime/isula/isula_rt_ops.h | 2 +- src/daemon/modules/runtime/runtime.c | 2 +- .../modules/service/service_container.c | 10 +-- src/daemon/modules/service/service_image.c | 4 +- src/daemon/modules/spec/specs.c | 8 +-- src/daemon/modules/spec/specs_security.c | 67 +++++++++---------- src/daemon/modules/spec/verify.c | 2 +- .../image/oci/oci_config_merge/CMakeLists.txt | 1 + test/image/oci/storage/layers/CMakeLists.txt | 1 + test/mocks/collector_mock.h | 4 +- test/mocks/container_operator_mock.h | 2 +- test/mocks/runtime_mock.h | 2 +- test/mocks/specs_mock.h | 6 +- test/runtime/isula/CMakeLists.txt | 1 + test/runtime/lcr/CMakeLists.txt | 1 + .../execute/execution_extend/CMakeLists.txt | 1 + test/specs/specs/CMakeLists.txt | 1 + test/specs/specs/specs_ut.cpp | 22 +++--- test/specs/specs_extend/CMakeLists.txt | 1 + test/specs/specs_extend/specs_extend_ut.cpp | 30 ++++----- 55 files changed, 196 insertions(+), 210 deletions(-) rename src/daemon/modules/{events_sender => api}/event_type.h (100%) rename src/daemon/modules/{events/collector.h => api/events_collector_api.h} (100%) rename src/daemon/modules/{events_sender/event_sender.h => api/events_sender_api.h} (100%) rename src/daemon/modules/{log/log_gather.h => api/log_gather_api.h} (100%) rename src/daemon/modules/{plugin/plugin.h => api/plugin_api.h} (80%) rename src/daemon/modules/{runtime/runtime.h => api/runtime_api.h} (100%) rename src/daemon/modules/{service/service_container.h => api/service_container_api.h} (93%) rename src/daemon/modules/{service/service_image.h => api/service_image_api.h} (100%) rename src/daemon/modules/{spec/specs.h => api/specs_api.h} (81%) diff --git a/src/cmd/isulad/main.c b/src/cmd/isulad/main.c index f578b2b..08bca0e 100644 --- a/src/cmd/isulad/main.c +++ b/src/cmd/isulad/main.c @@ -39,7 +39,7 @@ #endif #include "constants.h" -#include "collector.h" +#include "events_collector_api.h" #include "isulad_commands.h" #include "isula_libutils/log.h" #include "utils.h" @@ -49,13 +49,13 @@ #include "verify.h" #include "service_common.h" #include "callback.h" -#include "log_gather.h" +#include "log_gather_api.h" #include "container_api.h" -#include "service_container.h" -#include "plugin.h" +#include "service_container_api.h" +#include "plugin_api.h" #include "selinux_label.h" #include "http.h" -#include "runtime.h" +#include "runtime_api.h" #ifdef GRPC_CONNECTOR #include "clibcni/api.h" diff --git a/src/daemon/entry/cri/cri_image_service.cc b/src/daemon/entry/cri/cri_image_service.cc index 3e67bdc..e09b073 100644 --- a/src/daemon/entry/cri/cri_image_service.cc +++ b/src/daemon/entry/cri/cri_image_service.cc @@ -26,8 +26,8 @@ #include "isula_libutils/log.h" #include "utils.h" #include "cri_helpers.h" -#include "event_sender.h" -#include "service_image.h" +#include "events_sender_api.h" +#include "service_image_api.h" static void conv_image_to_grpc(const imagetool_image *element, std::unique_ptr &image) { diff --git a/src/daemon/executor/container_cb/execution.c b/src/daemon/executor/container_cb/execution.c index 7641c73..f812f2e 100644 --- a/src/daemon/executor/container_cb/execution.c +++ b/src/daemon/executor/container_cb/execution.c @@ -43,15 +43,15 @@ #include "execution_stream.h" #include "execution_create.h" #include "io_handler.h" -#include "plugin.h" +#include "plugin_api.h" #include "execution_network.h" -#include "runtime.h" +#include "runtime_api.h" #include "specs_extend.h" #include "utils.h" #include "error.h" -#include "event_sender.h" -#include "specs.h" -#include "service_container.h" +#include "events_sender_api.h" +#include "specs_api.h" +#include "service_container_api.h" static int filter_by_label(const container_t *cont, const container_get_id_request *request) { diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c index cfde3ea..8959645 100644 --- a/src/daemon/executor/container_cb/execution_create.c +++ b/src/daemon/executor/container_cb/execution_create.c @@ -32,20 +32,20 @@ #include "io_wrapper.h" #include "isulad_config.h" #include "config.h" -#include "specs.h" +#include "specs_api.h" #include "verify.h" #include "container_api.h" #include "execution_network.h" -#include "runtime.h" -#include "plugin.h" +#include "runtime_api.h" +#include "plugin_api.h" #include "image_api.h" #include "utils.h" #include "error.h" #include "constants.h" #include "namespace.h" -#include "event_sender.h" +#include "events_sender_api.h" #include "sysinfo.h" -#include "service_container.h" +#include "service_container_api.h" static int runtime_check(const char *name, bool *runtime_res) { diff --git a/src/daemon/executor/container_cb/execution_extend.c b/src/daemon/executor/container_cb/execution_extend.c index d29c282..3c219de 100644 --- a/src/daemon/executor/container_cb/execution_extend.c +++ b/src/daemon/executor/container_cb/execution_extend.c @@ -27,8 +27,8 @@ #include #include "isula_libutils/log.h" -#include "event_sender.h" -#include "collector.h" +#include "events_sender_api.h" +#include "events_collector_api.h" #include "io_wrapper.h" #include "isulad_config.h" #include "config.h" @@ -36,10 +36,10 @@ #include "verify.h" #include "isula_libutils/container_inspect.h" #include "container_api.h" -#include "service_container.h" +#include "service_container_api.h" #include "sysinfo.h" -#include "specs.h" -#include "runtime.h" +#include "specs_api.h" +#include "runtime_api.h" #include "filters.h" #include "utils.h" diff --git a/src/daemon/executor/container_cb/execution_information.c b/src/daemon/executor/container_cb/execution_information.c index 9b7be1a..0d87631 100644 --- a/src/daemon/executor/container_cb/execution_information.c +++ b/src/daemon/executor/container_cb/execution_information.c @@ -37,11 +37,11 @@ #include "execution_information.h" #include "sysinfo.h" -#include "runtime.h" +#include "runtime_api.h" #include "list.h" #include "utils.h" #include "error.h" -#include "event_sender.h" +#include "events_sender_api.h" static int container_version_cb(const container_version_request *request, container_version_response **response) { @@ -928,11 +928,14 @@ static int dup_health_check_config(const container_config *src, container_inspec dest->health_check->test[i] = util_strdup_s(src->healthcheck->test[i]); dest->health_check->test_len++; } - dest->health_check->interval = timeout_with_default(src->healthcheck->interval, DEFAULT_PROBE_INTERVAL); - dest->health_check->start_period = timeout_with_default(src->healthcheck->start_period, DEFAULT_START_PERIOD); - dest->health_check->timeout = timeout_with_default(src->healthcheck->timeout, DEFAULT_PROBE_TIMEOUT); - dest->health_check->retries = src->healthcheck->retries != 0 ? src->healthcheck->retries : - DEFAULT_PROBE_RETRIES; + dest->health_check->interval = (src->healthcheck->interval == 0) ? DEFAULT_PROBE_INTERVAL : + src->healthcheck->interval; + dest->health_check->start_period = (src->healthcheck->start_period == 0) ? DEFAULT_START_PERIOD : + src->healthcheck->start_period; + dest->health_check->timeout = (src->healthcheck->timeout == 0) ? DEFAULT_PROBE_TIMEOUT : + src->healthcheck->timeout; + dest->health_check->retries = (src->healthcheck->retries != 0) ? src->healthcheck->retries : + DEFAULT_PROBE_RETRIES; dest->health_check->exit_on_unhealthy = src->healthcheck->exit_on_unhealthy; } diff --git a/src/daemon/executor/container_cb/execution_stream.c b/src/daemon/executor/container_cb/execution_stream.c index 0750bce..a30dea2 100644 --- a/src/daemon/executor/container_cb/execution_stream.c +++ b/src/daemon/executor/container_cb/execution_stream.c @@ -41,9 +41,9 @@ #include "error.h" #include "isula_libutils/logger_json_file.h" #include "constants.h" -#include "runtime.h" -#include "event_sender.h" -#include "service_container.h" +#include "runtime_api.h" +#include "events_sender_api.h" +#include "service_container_api.h" #include "io_handler.h" struct container_log_config { diff --git a/src/daemon/executor/container_cb/io_handler.c b/src/daemon/executor/container_cb/io_handler.c index cd4529e..ecb0027 100644 --- a/src/daemon/executor/container_cb/io_handler.c +++ b/src/daemon/executor/container_cb/io_handler.c @@ -41,9 +41,9 @@ #include "error.h" #include "isula_libutils/logger_json_file.h" #include "constants.h" -#include "runtime.h" -#include "event_sender.h" -#include "service_container.h" +#include "runtime_api.h" +#include "events_sender_api.h" +#include "service_container_api.h" static char *create_single_fifo(const char *statepath, const char *subpath, const char *stdflag) { diff --git a/src/daemon/executor/image_cb/image_cb.c b/src/daemon/executor/image_cb/image_cb.c index 91aaded..47a9781 100644 --- a/src/daemon/executor/image_cb/image_cb.c +++ b/src/daemon/executor/image_cb/image_cb.c @@ -33,8 +33,8 @@ #include "isulad_config.h" #include "mediatype.h" #include "filters.h" -#include "event_sender.h" -#include "service_image.h" +#include "events_sender_api.h" +#include "service_image_api.h" #ifdef ENABLE_OCI_IMAGE #include "oci_common_operators.h" #endif diff --git a/src/daemon/modules/api/container_api.h b/src/daemon/modules/api/container_api.h index 73fd85b..1995d39 100644 --- a/src/daemon/modules/api/container_api.h +++ b/src/daemon/modules/api/container_api.h @@ -225,8 +225,6 @@ int dup_health_check_status(defs_health **dst, const defs_health *src); void update_health_monitor(const char *container_id); -int64_t timeout_with_default(int64_t configured_value, int64_t default_value); - extern int supervisor_add_exit_monitor(int fd, const container_pid_t *pid_info, const char *name, const char *runtime); extern char *exit_fifo_create(const char *cont_state_path); diff --git a/src/daemon/modules/events_sender/event_type.h b/src/daemon/modules/api/event_type.h similarity index 100% rename from src/daemon/modules/events_sender/event_type.h rename to src/daemon/modules/api/event_type.h diff --git a/src/daemon/modules/events/collector.h b/src/daemon/modules/api/events_collector_api.h similarity index 100% rename from src/daemon/modules/events/collector.h rename to src/daemon/modules/api/events_collector_api.h diff --git a/src/daemon/modules/events_sender/event_sender.h b/src/daemon/modules/api/events_sender_api.h similarity index 100% rename from src/daemon/modules/events_sender/event_sender.h rename to src/daemon/modules/api/events_sender_api.h diff --git a/src/daemon/modules/log/log_gather.h b/src/daemon/modules/api/log_gather_api.h similarity index 100% rename from src/daemon/modules/log/log_gather.h rename to src/daemon/modules/api/log_gather_api.h diff --git a/src/daemon/modules/plugin/plugin.h b/src/daemon/modules/api/plugin_api.h similarity index 80% rename from src/daemon/modules/plugin/plugin.h rename to src/daemon/modules/api/plugin_api.h index 478fb86..26edcfc 100644 --- a/src/daemon/modules/plugin/plugin.h +++ b/src/daemon/modules/api/plugin_api.h @@ -19,8 +19,8 @@ #include #include "map.h" -#include "specs.h" /* oci_runtime_spec */ -#include "container_unix.h" /* container_t */ +#include "specs_api.h" /* oci_runtime_spec */ +#include "container_api.h" /* container_t */ /* * returned int should means: @@ -32,14 +32,14 @@ * comment. */ -#define PLUGIN_INIT_SKIP 0 -#define PLUGIN_INIT_WITH_CONTAINER_RUNNING 1 -#define PLUGIN_INIT_WITH_CONTAINER_ALL 2 +#define PLUGIN_INIT_SKIP 0 +#define PLUGIN_INIT_WITH_CONTAINER_RUNNING 1 +#define PLUGIN_INIT_WITH_CONTAINER_ALL 2 -#define PLUGIN_EVENT_CONTAINER_PRE_CREATE 1UL -#define PLUGIN_EVENT_CONTAINER_PRE_START (1UL << 1) -#define PLUGIN_EVENT_CONTAINER_POST_STOP (1UL << 2) -#define PLUGIN_EVENT_CONTAINER_POST_REMOVE (1UL << 3) +#define PLUGIN_EVENT_CONTAINER_PRE_CREATE 1UL +#define PLUGIN_EVENT_CONTAINER_PRE_START (1UL << 1) +#define PLUGIN_EVENT_CONTAINER_POST_STOP (1UL << 2) +#define PLUGIN_EVENT_CONTAINER_POST_REMOVE (1UL << 3) typedef struct plugin_manifest { uint64_t init_type; @@ -65,8 +65,8 @@ typedef struct plugin { * more plugint_put() shall be called. */ plugin_t *plugin_new(const char *name, const char *addr); -void plugin_get(plugin_t *plugin); /* ref++ */ -void plugin_put(plugin_t *plugin); /* ref-- */ +void plugin_get(plugin_t *plugin); /* ref++ */ +void plugin_put(plugin_t *plugin); /* ref-- */ int plugin_set_activated(plugin_t *plugin, bool activated, const char *errmsg); int plugin_set_manifest(plugin_t *plugin, const plugin_manifest_t *manifest); @@ -74,8 +74,8 @@ bool plugin_is_watching(plugin_t *plugin, uint64_t pe); typedef struct plugin_manager { pthread_rwlock_t pm_rwlock; - map_t *np; /* name:plugin */ - map_t *eps; /* watch_event:plugins */ + map_t *np; /* name:plugin */ + map_t *eps; /* watch_event:plugins */ } plugin_manager_t; /* @@ -112,4 +112,3 @@ int plugin_event_container_post_remove(const container_t *cont); int plugin_event_container_post_remove2(const char *cid, const oci_runtime_spec *oci); #endif /* _PLUGIN_H_ */ - diff --git a/src/daemon/modules/runtime/runtime.h b/src/daemon/modules/api/runtime_api.h similarity index 100% rename from src/daemon/modules/runtime/runtime.h rename to src/daemon/modules/api/runtime_api.h diff --git a/src/daemon/modules/service/service_container.h b/src/daemon/modules/api/service_container_api.h similarity index 93% rename from src/daemon/modules/service/service_container.h rename to src/daemon/modules/api/service_container_api.h index 31fed91..c7dabcf 100644 --- a/src/daemon/modules/service/service_container.h +++ b/src/daemon/modules/api/service_container_api.h @@ -14,9 +14,7 @@ ******************************************************************************/ #ifndef __ISULAD_SERVICE_CONTAINER_OPERATOR_H #define __ISULAD_SERVICE_CONTAINER_OPERATOR_H -#include -#include -#include "container_unix.h" +#include "container_api.h" #ifdef __cplusplus extern "C" { @@ -40,8 +38,6 @@ int set_container_to_removal(const container_t *cont); int delete_container(container_t *cont, bool force); -int container_module_init(char **msg); - #ifdef __cplusplus } #endif diff --git a/src/daemon/modules/service/service_image.h b/src/daemon/modules/api/service_image_api.h similarity index 100% rename from src/daemon/modules/service/service_image.h rename to src/daemon/modules/api/service_image_api.h diff --git a/src/daemon/modules/spec/specs.h b/src/daemon/modules/api/specs_api.h similarity index 81% rename from src/daemon/modules/spec/specs.h rename to src/daemon/modules/api/specs_api.h index 613ca9e..2b403f7 100644 --- a/src/daemon/modules/spec/specs.h +++ b/src/daemon/modules/api/specs_api.h @@ -26,20 +26,17 @@ extern "C" { #endif -int merge_all_specs(host_config *host_spec, - const char *real_rootfs, - container_config_v2_common_config *v2_spec, oci_runtime_spec *oci_spec); -int merge_oci_cgroups_path(const char *id, oci_runtime_spec *oci_spec, - const host_config *host_spec); +int merge_all_specs(host_config *host_spec, const char *real_rootfs, container_config_v2_common_config *v2_spec, + oci_runtime_spec *oci_spec); +int merge_oci_cgroups_path(const char *id, oci_runtime_spec *oci_spec, const host_config *host_spec); int merge_global_config(oci_runtime_spec *oci_spec); oci_runtime_spec *load_oci_config(const char *rootpath, const char *name); oci_runtime_spec *default_spec(bool system_container); int merge_conf_cgroup(oci_runtime_spec *oci_spec, const host_config *host_spec); int save_oci_config(const char *id, const char *rootpath, const oci_runtime_spec *oci_spec); -int parse_security_opt(const host_config *host_spec, bool *no_new_privileges, - char ***label_opts, size_t *label_opts_len, - char **seccomp_profile); +int parse_security_opt(const host_config *host_spec, bool *no_new_privileges, char ***label_opts, + size_t *label_opts_len, char **seccomp_profile); int merge_share_namespace(oci_runtime_spec *oci_spec, const host_config *host_spec); #ifdef __cplusplus @@ -47,4 +44,3 @@ int merge_share_namespace(oci_runtime_spec *oci_spec, const host_config *host_sp #endif #endif - diff --git a/src/daemon/modules/container/container_events_handler.c b/src/daemon/modules/container/container_events_handler.c index 7eee405..e23e8c2 100644 --- a/src/daemon/modules/container/container_events_handler.c +++ b/src/daemon/modules/container/container_events_handler.c @@ -27,8 +27,8 @@ #include "container_events_handler.h" #include "utils.h" #include "container_api.h" -#include "service_container.h" -#include "plugin.h" +#include "service_container_api.h" +#include "plugin_api.h" #include "restartmanager.h" #include "health_check.h" diff --git a/src/daemon/modules/container/container_gc/containers_gc.c b/src/daemon/modules/container/container_gc/containers_gc.c index e6670ba..78b0110 100644 --- a/src/daemon/modules/container/container_gc/containers_gc.c +++ b/src/daemon/modules/container/container_gc/containers_gc.c @@ -23,9 +23,9 @@ #include "isula_libutils/container_garbage_config.h" #include "isula_libutils/log.h" #include "utils.h" -#include "service_container.h" +#include "service_container_api.h" #include "container_api.h" -#include "runtime.h" +#include "runtime_api.h" #include "restartmanager.h" static containers_gc_t g_gc_containers; diff --git a/src/daemon/modules/container/health_check/health_check.c b/src/daemon/modules/container/health_check/health_check.c index ae97ded..231dce1 100644 --- a/src/daemon/modules/container/health_check/health_check.c +++ b/src/daemon/modules/container/health_check/health_check.c @@ -26,10 +26,10 @@ #include "utils.h" #include "health_check.h" #include "callback.h" -#include "service_container.h" +#include "service_container_api.h" #include "isula_libutils/container_exec_request.h" #include "isula_libutils/container_exec_response.h" -#include "log_gather.h" +#include "log_gather_api.h" #include "container_state.h" /* container state lock */ @@ -147,15 +147,6 @@ void stop_health_checks(const char *container_id) container_unref(cont); } -// If configuredValue is zero, use defaultValue instead. -int64_t timeout_with_default(int64_t configured_value, int64_t default_value) -{ - if (configured_value == 0) { - return default_value; - } - return configured_value; -} - /* health check manager free */ void health_check_manager_free(health_check_manager_t *health_check) { @@ -357,8 +348,9 @@ static int handle_unhealthy_case(container_t *cont, const defs_health_log_elemen health_status = get_health_status(cont->state); if (strcmp(health_status, HEALTH_STARTING) == 0) { - int64_t start_period = - timeout_with_default(cont->common_config->config->healthcheck->start_period, DEFAULT_START_PERIOD); + int64_t start_period = (cont->common_config->config->healthcheck->start_period == 0) ? + DEFAULT_START_PERIOD : + cont->common_config->config->healthcheck->start_period; int64_t first, last; if (to_unix_nanos_from_str(cont->state->state->started_at, &first)) { ERROR("Parse container started time failed: %s", cont->state->state->started_at); @@ -557,7 +549,8 @@ void *health_check_run(void *arg) container_req->attach_stdin = false; container_req->attach_stdout = true; container_req->attach_stderr = true; - container_req->timeout = timeout_with_default(config->healthcheck->timeout, DEFAULT_PROBE_TIMEOUT) / Time_Second; + container_req->timeout = + ((config->healthcheck->timeout == 0) ? DEFAULT_PROBE_TIMEOUT : config->healthcheck->timeout) / Time_Second; container_req->container_id = util_strdup_s(cont->common_config->id); container_req->argv = cmd_slice; container_req->argv_len = util_array_len((const char **)cmd_slice); @@ -704,7 +697,9 @@ static void *health_check_monitor(void *arg) ERROR("Failed to monitor start time stamp"); goto out; } - probe_interval = timeout_with_default(cont->common_config->config->healthcheck->interval, DEFAULT_PROBE_INTERVAL); + probe_interval = (cont->common_config->config->healthcheck->interval == 0) ? + DEFAULT_PROBE_INTERVAL : + cont->common_config->config->healthcheck->interval; set_monitor_idle_status(cont->health_check); while (true) { switch (get_health_check_monitor_state(cont->health_check)) { diff --git a/src/daemon/modules/container/restart_manager/restartmanager.c b/src/daemon/modules/container/restart_manager/restartmanager.c index 202f078..e517f5b 100644 --- a/src/daemon/modules/container/restart_manager/restartmanager.c +++ b/src/daemon/modules/container/restart_manager/restartmanager.c @@ -26,7 +26,8 @@ #include "isula_libutils/log.h" #include "isulad_config.h" #include "utils.h" -#include "service_container.h" +#include "service_container_api.h" +#include "container_unix.h" #define backoffMultipulier 2U // unit nanos diff --git a/src/daemon/modules/container/restore/restore.c b/src/daemon/modules/container/restore/restore.c index 382ddcd..2d680d2 100644 --- a/src/daemon/modules/container/restore/restore.c +++ b/src/daemon/modules/container/restore/restore.c @@ -28,8 +28,8 @@ #include "container_unix.h" #include "error.h" #include "image_api.h" -#include "runtime.h" -#include "service_container.h" +#include "runtime_api.h" +#include "service_container_api.h" #include "restartmanager.h" #include "health_check.h" diff --git a/src/daemon/modules/container/supervisor/supervisor.c b/src/daemon/modules/container/supervisor/supervisor.c index 2156f5d..84d91fc 100644 --- a/src/daemon/modules/container/supervisor/supervisor.c +++ b/src/daemon/modules/container/supervisor/supervisor.c @@ -22,9 +22,9 @@ #include "supervisor.h" #include "mainloop.h" #include "libisulad.h" -#include "event_sender.h" +#include "events_sender_api.h" #include "containers_gc.h" -#include "service_container.h" +#include "service_container_api.h" pthread_mutex_t g_supervisor_lock = PTHREAD_MUTEX_INITIALIZER; struct epoll_descr g_supervisor_descr; diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c index 3bf6472..b5b1cfd 100644 --- a/src/daemon/modules/events/collector.c +++ b/src/daemon/modules/events/collector.c @@ -27,7 +27,7 @@ #include "error.h" #include "isula_libutils/log.h" -#include "collector.h" +#include "events_collector_api.h" #include "monitord.h" #include "isulad_config.h" #include "libisulad.h" diff --git a/src/daemon/modules/events/monitord.c b/src/daemon/modules/events/monitord.c index 9da096d..a52316c 100644 --- a/src/daemon/modules/events/monitord.c +++ b/src/daemon/modules/events/monitord.c @@ -27,9 +27,9 @@ #include "monitord.h" #include "mainloop.h" #include "isulad_config.h" -#include "collector.h" +#include "events_collector_api.h" #include "utils.h" -#include "event_sender.h" +#include "events_sender_api.h" struct monitord_handler { struct epoll_descr *pdescr; diff --git a/src/daemon/modules/events_sender/event_sender.c b/src/daemon/modules/events_sender/event_sender.c index d359601..36d0587 100644 --- a/src/daemon/modules/events_sender/event_sender.c +++ b/src/daemon/modules/events_sender/event_sender.c @@ -13,7 +13,7 @@ * Description: provide container collector definition ******************************************************************************/ #define _GNU_SOURCE -#include "event_sender.h" +#include "events_sender_api.h" #include #include #include @@ -78,13 +78,12 @@ int isulad_monitor_send_container_event(const char *name, runtime_state_t state, { int ret = 0; struct monitord_msg msg = { .type = MONITORD_MSG_STATE, - .event_type = CONTAINER_EVENT, - .value = state, - .pid = -1, - .exit_code = -1, - .args = { 0x00 }, - .extra_annations = { 0x00 } - }; + .event_type = CONTAINER_EVENT, + .value = state, + .pid = -1, + .exit_code = -1, + .args = { 0x00 }, + .extra_annations = { 0x00 } }; if (name == NULL) { CRIT("Invalid input arguments"); @@ -124,11 +123,10 @@ int isulad_monitor_send_image_event(const char *name, image_state_t state) int ret = 0; struct monitord_msg msg = { .type = MONITORD_MSG_STATE, - .event_type = IMAGE_EVENT, - .value = state, - .args = { 0x00 }, - .extra_annations = { 0x00 } - }; + .event_type = IMAGE_EVENT, + .value = state, + .args = { 0x00 }, + .extra_annations = { 0x00 } }; if (name == NULL) { CRIT("Invalid input arguments"); diff --git a/src/daemon/modules/log/log_gather.c b/src/daemon/modules/log/log_gather.c index 327ce6d..2727341 100644 --- a/src/daemon/modules/log/log_gather.c +++ b/src/daemon/modules/log/log_gather.c @@ -13,7 +13,7 @@ * Description: provide log gather functions ******************************************************************************/ #define _GNU_SOURCE -#include "log_gather.h" +#include "log_gather_api.h" #include #include @@ -28,7 +28,7 @@ #include "utils.h" #include "isulad_tar.h" -typedef int(*log_save_t)(const void *buf, size_t count); +typedef int (*log_save_t)(const void *buf, size_t count); static log_save_t g_save_log_op = NULL; static int g_fifo_fd = -1; @@ -407,4 +407,3 @@ err_out: pexit: return NULL; } - diff --git a/src/daemon/modules/plugin/plugin.c b/src/daemon/modules/plugin/plugin.c index eb2d4a8..104a128 100644 --- a/src/daemon/modules/plugin/plugin.c +++ b/src/daemon/modules/plugin/plugin.c @@ -22,13 +22,13 @@ #include #include "isula_libutils/log.h" -#include "plugin.h" +#include "plugin_api.h" #include "pspec.h" #include "utils.h" #include "parser.h" #include "buffer.h" #include "isulad_config.h" -#include "specs.h" +#include "specs_api.h" #include "specs_extend.h" #include "rest_common.h" #include "container_api.h" diff --git a/src/daemon/modules/plugin/pspec.c b/src/daemon/modules/plugin/pspec.c index 45e889a..de6a102 100644 --- a/src/daemon/modules/plugin/pspec.c +++ b/src/daemon/modules/plugin/pspec.c @@ -17,7 +17,7 @@ #include "isula_libutils/log.h" #include "isula_libutils/oci_runtime_spec.h" #include "isula_libutils/oci_runtime_pspec.h" -#include "plugin.h" +#include "plugin_api.h" #include "pspec.h" /* @@ -26,12 +26,12 @@ */ #define PTR_UPDATE(old, new, field, ffree) \ do { \ - if ((new)->field == NULL) { \ + if ((new)->field == NULL) { \ break; \ } \ - ffree((old)->field); \ - (old)->field = (new)->field; \ - (new)->field = NULL; \ + ffree((old)->field); \ + (old)->field = (new)->field; \ + (new)->field = NULL; \ } while (0) /* @@ -87,8 +87,7 @@ static oci_runtime_pspec *raw_get_pspec(oci_runtime_spec *oci) PPR_UPDATE(pspec, oci->process, env, env_len, free); PPR_UPDATE(pspec, oci->linux, devices, devices_len, free_defs_device); - PPR_UPDATE(pspec->resources, oci->linux->resources, devices, devices_len, - free_defs_device_cgroup); + PPR_UPDATE(pspec->resources, oci->linux->resources, devices, devices_len, free_defs_device_cgroup); return pspec; } @@ -113,8 +112,7 @@ static void raw_set_pspec(oci_runtime_spec *oci, oci_runtime_pspec *pspec) PPR_UPDATE(oci->process, pspec, env, env_len, free); PPR_UPDATE(oci->linux, pspec, devices, devices_len, free_defs_device); - PPR_UPDATE(oci->linux->resources, pspec->resources, devices, devices_len, - free_defs_device_cgroup); + PPR_UPDATE(oci->linux->resources, pspec->resources, devices, devices_len, free_defs_device_cgroup); } char *get_pspec(oci_runtime_spec *oci) @@ -254,4 +252,3 @@ revert_free_old: return dst; } - diff --git a/src/daemon/modules/runtime/engines/engine.h b/src/daemon/modules/runtime/engines/engine.h index 67f7531..13070d9 100644 --- a/src/daemon/modules/runtime/engines/engine.h +++ b/src/daemon/modules/runtime/engines/engine.h @@ -19,7 +19,7 @@ #include #include -#include "runtime.h" +#include "runtime_api.h" #ifdef __cplusplus extern "C" { diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c index e5691aa..6d348e6 100644 --- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c +++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c @@ -23,7 +23,7 @@ #include "error.h" #include "isulad_config.h" #include "libisulad.h" -#include "runtime.h" +#include "runtime_api.h" bool rt_lcr_detect(const char *runtime) { diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h index e73add4..cd65ef3 100644 --- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h +++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.h @@ -16,7 +16,7 @@ #ifndef __RUNTIME_LCR_OPS_INTERFACE_H_ #define __RUNTIME_LCR_OPS_INTERFACE_H_ -#include "runtime.h" +#include "runtime_api.h" #ifdef __cplusplus extern "C" { diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c index e207637..c4273cf 100644 --- a/src/daemon/modules/runtime/isula/isula_rt_ops.c +++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c @@ -22,7 +22,7 @@ #include "isula_rt_ops.h" #include "isula_libutils/log.h" #include "error.h" -#include "runtime.h" +#include "runtime_api.h" #include "constants.h" #include "isula_libutils/shim_client_process_state.h" #include "isula_libutils/shim_client_runtime_stats.h" @@ -673,7 +673,7 @@ static int shim_create(bool fg, const char *id, const char *workdir, const char _exit(EXIT_SUCCESS); } -realexec: + realexec: /* real shim process. */ close(exec_fd[0]); if (setsid() < 0) { @@ -685,7 +685,7 @@ realexec: (void)dprintf(exec_fd[1], "close inherited fds failed"); } - execvp(SHIM_BINARY, (char * const *)params); + execvp(SHIM_BINARY, (char *const *)params); (void)dprintf(exec_fd[1], "exec failed: %s", strerror(errno)); } diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.h b/src/daemon/modules/runtime/isula/isula_rt_ops.h index 78cb035..a4739cf 100644 --- a/src/daemon/modules/runtime/isula/isula_rt_ops.h +++ b/src/daemon/modules/runtime/isula/isula_rt_ops.h @@ -16,7 +16,7 @@ #ifndef ISULA_RT_OPS_H #define ISULA_RT_OPS_H /* ISULA_RT_OPS_H */ -#include "runtime.h" +#include "runtime_api.h" #ifdef __cplusplus extern "C" { diff --git a/src/daemon/modules/runtime/runtime.c b/src/daemon/modules/runtime/runtime.c index 54baa03..0ebafa3 100644 --- a/src/daemon/modules/runtime/runtime.c +++ b/src/daemon/modules/runtime/runtime.c @@ -21,7 +21,7 @@ #include #include -#include "runtime.h" +#include "runtime_api.h" #include "engine.h" #include "isulad_config.h" #include "isula_libutils/log.h" diff --git a/src/daemon/modules/service/service_container.c b/src/daemon/modules/service/service_container.c index c8bd9bd..3d458af 100644 --- a/src/daemon/modules/service/service_container.c +++ b/src/daemon/modules/service/service_container.c @@ -13,7 +13,7 @@ * Description: provide container supervisor functions ******************************************************************************/ #define _GNU_SOURCE -#include "service_container.h" +#include "service_container_api.h" #include #include #include @@ -23,15 +23,15 @@ #include "utils.h" #include "mainloop.h" #include "libisulad.h" -#include "event_sender.h" +#include "events_sender_api.h" #include "image_api.h" -#include "specs.h" +#include "specs_api.h" #include "isulad_config.h" #include "verify.h" -#include "plugin.h" +#include "plugin_api.h" #include "container_api.h" #include "namespace.h" -#include "runtime.h" +#include "runtime_api.h" int set_container_to_removal(const container_t *cont) { diff --git a/src/daemon/modules/service/service_image.c b/src/daemon/modules/service/service_image.c index f13554b..15e1803 100644 --- a/src/daemon/modules/service/service_image.c +++ b/src/daemon/modules/service/service_image.c @@ -13,7 +13,7 @@ * Description: provide container supervisor functions ******************************************************************************/ #define _GNU_SOURCE -#include "service_image.h" +#include "service_image_api.h" #include #include #include @@ -23,7 +23,7 @@ #include "image_api.h" #include "utils.h" #include "container_api.h" -#include "event_sender.h" +#include "events_sender_api.h" static bool check_image_in_used(const char *image_ref) { diff --git a/src/daemon/modules/spec/specs.c b/src/daemon/modules/spec/specs.c index da603a3..d0d96ab 100644 --- a/src/daemon/modules/spec/specs.c +++ b/src/daemon/modules/spec/specs.c @@ -30,7 +30,7 @@ #include "error.h" #include "isula_libutils/log.h" -#include "specs.h" +#include "specs_api.h" #include "isula_libutils/oci_runtime_spec.h" #include "isula_libutils/oci_runtime_hooks.h" #include "isula_libutils/docker_seccomp.h" @@ -688,16 +688,16 @@ static int merge_hugetlbs(oci_runtime_spec *oci_spec, host_config_hugetlbs_eleme for (i = 0; i < hugetlbs_len; i++) { oci_spec->linux->resources->hugepage_limits[oci_spec->linux->resources->hugepage_limits_len] = - util_common_calloc_s(sizeof(defs_resources_hugepage_limits_element)); + util_common_calloc_s(sizeof(defs_resources_hugepage_limits_element)); if (oci_spec->linux->resources->hugepage_limits[oci_spec->linux->resources->hugepage_limits_len] == NULL) { ERROR("Failed to malloc memory for hugepage limits"); ret = -1; goto out; } oci_spec->linux->resources->hugepage_limits[oci_spec->linux->resources->hugepage_limits_len]->limit = - hugetlbs[i]->limit; + hugetlbs[i]->limit; oci_spec->linux->resources->hugepage_limits[oci_spec->linux->resources->hugepage_limits_len]->page_size = - util_strdup_s(hugetlbs[i]->page_size); + util_strdup_s(hugetlbs[i]->page_size); oci_spec->linux->resources->hugepage_limits_len++; } out: diff --git a/src/daemon/modules/spec/specs_security.c b/src/daemon/modules/spec/specs_security.c index f71353d..6542c62 100644 --- a/src/daemon/modules/spec/specs_security.c +++ b/src/daemon/modules/spec/specs_security.c @@ -44,18 +44,17 @@ #include "libisulad.h" #include "specs_extend.h" #include "selinux_label.h" -#include "specs.h" +#include "specs_api.h" #include "constants.h" #define MAX_CAP_LEN 32 -static const char * const g_system_caps[] = { "SYS_BOOT", "SETPCAP", "NET_RAW", "NET_BIND_SERVICE", +static const char *const g_system_caps[] = { "SYS_BOOT", "SETPCAP", "NET_RAW", "NET_BIND_SERVICE", #ifdef CAP_AUDIT_WRITE - "AUDIT_WRITE", + "AUDIT_WRITE", #endif - "DAC_OVERRIDE", "SETFCAP", "SETGID", "SETUID", "MKNOD", "CHOWN", - "FOWNER", "FSETID", "KILL", "SYS_CHROOT" - }; + "DAC_OVERRIDE", "SETFCAP", "SETGID", "SETUID", "MKNOD", "CHOWN", + "FOWNER", "FSETID", "KILL", "SYS_CHROOT" }; static int append_capability(char ***dstcaps, size_t *dstcaps_len, const char *cap) { @@ -311,25 +310,24 @@ static char *seccomp_trans_arch_for_docker(const char *arch) { size_t i = 0; char *arch_map[][2] = { { "SCMP_ARCH_X86", "x86" }, - { "SCMP_ARCH_X86_64", "amd64" }, - { "SCMP_ARCH_X32", "x32" }, - { "SCMP_ARCH_ARM", "arm" }, - { "SCMP_ARCH_AARCH64", "arm64" }, - { "SCMP_ARCH_MIPS", "mips" }, - { "SCMP_ARCH_MIPS64", "mips64" }, - { "SCMP_ARCH_MIPS64N32", "mips64n32" }, - { "SCMP_ARCH_MIPSEL", "mipsel" }, - { "SCMP_ARCH_MIPSEL64", "mipsel64" }, - { "SCMP_ARCH_MIPSEL64N32", "mipsel64n32" }, - { "SCMP_ARCH_PPC", "ppc" }, - { "SCMP_ARCH_PPC64", "ppc64" }, - { "SCMP_ARCH_PPC64LE", "ppc64le" }, - { "SCMP_ARCH_S390", "s390" }, - { "SCMP_ARCH_S390X", "s390x" }, - { "SCMP_ARCH_PARISC", "parisc" }, - { "SCMP_ARCH_PARISC64", "parisc64" }, - { "SCMP_ARCH_ALL", "all" } - }; + { "SCMP_ARCH_X86_64", "amd64" }, + { "SCMP_ARCH_X32", "x32" }, + { "SCMP_ARCH_ARM", "arm" }, + { "SCMP_ARCH_AARCH64", "arm64" }, + { "SCMP_ARCH_MIPS", "mips" }, + { "SCMP_ARCH_MIPS64", "mips64" }, + { "SCMP_ARCH_MIPS64N32", "mips64n32" }, + { "SCMP_ARCH_MIPSEL", "mipsel" }, + { "SCMP_ARCH_MIPSEL64", "mipsel64" }, + { "SCMP_ARCH_MIPSEL64N32", "mipsel64n32" }, + { "SCMP_ARCH_PPC", "ppc" }, + { "SCMP_ARCH_PPC64", "ppc64" }, + { "SCMP_ARCH_PPC64LE", "ppc64le" }, + { "SCMP_ARCH_S390", "s390" }, + { "SCMP_ARCH_S390X", "s390x" }, + { "SCMP_ARCH_PARISC", "parisc" }, + { "SCMP_ARCH_PARISC64", "parisc64" }, + { "SCMP_ARCH_ALL", "all" } }; for (i = 0; i < sizeof(arch_map) / sizeof(arch_map[0]); i++) { if (strcmp(arch, arch_map[i][0]) == 0) { return util_strdup_s(arch_map[i][1]); @@ -493,10 +491,10 @@ static int dup_architectures_to_oci_spec(const docker_seccomp *docker_seccomp_sp } for (i = 0; i < docker_seccomp_spec->arch_map_len; i++) { oci_seccomp_spec->architectures[oci_seccomp_spec->architectures_len++] = - util_strdup_s(docker_seccomp_spec->arch_map[i]->architecture); + util_strdup_s(docker_seccomp_spec->arch_map[i]->architecture); for (j = 0; j < docker_seccomp_spec->arch_map[i]->sub_architectures_len; j++) { oci_seccomp_spec->architectures[oci_seccomp_spec->architectures_len++] = - util_strdup_s(docker_seccomp_spec->arch_map[i]->sub_architectures[j]); + util_strdup_s(docker_seccomp_spec->arch_map[i]->sub_architectures[j]); } } } @@ -574,7 +572,7 @@ static int dup_syscall_to_oci_spec(const docker_seccomp *docker_seccomp_spec, } oci_seccomp_spec->syscalls[k]->names = - util_common_calloc_s(docker_seccomp_spec->syscalls[i]->names_len * sizeof(char *)); + util_common_calloc_s(docker_seccomp_spec->syscalls[i]->names_len * sizeof(char *)); if (oci_seccomp_spec->syscalls[k]->names == NULL) { return -1; } @@ -961,8 +959,7 @@ int adapt_settings_for_system_container(oci_runtime_spec *oci_spec, const host_c { int ret = 0; char *unblocked_systemcall_for_system_container[] = { "mount", "umount2", "reboot", "name_to_handle_at", - "unshare" - }; + "unshare" }; char **adds = NULL; size_t adds_len = 0; bool no_new_privileges = false; @@ -1005,11 +1002,11 @@ int adapt_settings_for_system_container(oci_runtime_spec *oci_spec, const host_c } ret = append_systemcall_to_seccomp( - oci_spec->linux->seccomp, - make_seccomp_syscalls_element((const char **)unblocked_systemcall_for_system_container, - sizeof(unblocked_systemcall_for_system_container) / - sizeof(unblocked_systemcall_for_system_container[0]), - "SCMP_ACT_ALLOW", 0, NULL)); + oci_spec->linux->seccomp, + make_seccomp_syscalls_element((const char **)unblocked_systemcall_for_system_container, + sizeof(unblocked_systemcall_for_system_container) / + sizeof(unblocked_systemcall_for_system_container[0]), + "SCMP_ACT_ALLOW", 0, NULL)); if (ret != 0) { ERROR("Failed to append systemcall to seccomp file"); ret = -1; diff --git a/src/daemon/modules/spec/verify.c b/src/daemon/modules/spec/verify.c index e6f9901..e18a6b9 100644 --- a/src/daemon/modules/spec/verify.c +++ b/src/daemon/modules/spec/verify.c @@ -30,7 +30,7 @@ #include "libisulad.h" #include "isula_libutils/log.h" #include "sysinfo.h" -#include "specs.h" +#include "specs_api.h" #include "verify.h" #include "isulad_config.h" #include "selinux_label.h" diff --git a/test/image/oci/oci_config_merge/CMakeLists.txt b/test/image/oci/oci_config_merge/CMakeLists.txt index 6c08cfa..ed00991 100644 --- a/test/image/oci/oci_config_merge/CMakeLists.txt +++ b/test/image/oci/oci_config_merge/CMakeLists.txt @@ -38,6 +38,7 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/common ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/api ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/runtime/engines ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/spec/ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/container/ diff --git a/test/image/oci/storage/layers/CMakeLists.txt b/test/image/oci/storage/layers/CMakeLists.txt index ff4666e..c91f2b5 100644 --- a/test/image/oci/storage/layers/CMakeLists.txt +++ b/test/image/oci/storage/layers/CMakeLists.txt @@ -40,6 +40,7 @@ target_include_directories(${DRIVER_EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/sha256 ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/console ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/api ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver diff --git a/test/mocks/collector_mock.h b/test/mocks/collector_mock.h index d3f8d27..11a39bd 100644 --- a/test/mocks/collector_mock.h +++ b/test/mocks/collector_mock.h @@ -17,7 +17,7 @@ #define COLLECTOR_MOCK_H_ #include -#include "collector.h" +#include "events_collector_api.h" class MockCollector { public: @@ -29,6 +29,6 @@ public: const char *args, const char *extra_annations)); }; -void MockCollector_SetMock(MockCollector* mock); +void MockCollector_SetMock(MockCollector *mock); #endif diff --git a/test/mocks/container_operator_mock.h b/test/mocks/container_operator_mock.h index d8f3d11..ff62670 100644 --- a/test/mocks/container_operator_mock.h +++ b/test/mocks/container_operator_mock.h @@ -17,7 +17,7 @@ #define CONTAINERS_OPERATOR_MOCK_H_ #include -#include "service_container.h" +#include "service_container_api.h" class MockContainersOperator { public: diff --git a/test/mocks/runtime_mock.h b/test/mocks/runtime_mock.h index 5810595..9e4732b 100644 --- a/test/mocks/runtime_mock.h +++ b/test/mocks/runtime_mock.h @@ -17,7 +17,7 @@ #define RUNTIME_MOCK_H_ #include -#include "runtime.h" +#include "runtime_api.h" class MockRuntime { public: diff --git a/test/mocks/specs_mock.h b/test/mocks/specs_mock.h index 30e2866..68dc31c 100644 --- a/test/mocks/specs_mock.h +++ b/test/mocks/specs_mock.h @@ -17,15 +17,15 @@ #define SPECS_MOCK_H_ #include -#include "specs.h" +#include "specs_api.h" class MockSpecs { public: - MOCK_METHOD2(LoadOciConfig, oci_runtime_spec * (const char *rootpath, const char *name)); + MOCK_METHOD2(LoadOciConfig, oci_runtime_spec *(const char *rootpath, const char *name)); MOCK_METHOD2(MergeConfCgroup, int(oci_runtime_spec *oci_spec, const host_config *host_spec)); MOCK_METHOD3(SaveOciConfig, int(const char *id, const char *rootpath, const oci_runtime_spec *oci_spec)); }; -void MockSpecs_SetMock(MockSpecs* mock); +void MockSpecs_SetMock(MockSpecs *mock); #endif diff --git a/test/runtime/isula/CMakeLists.txt b/test/runtime/isula/CMakeLists.txt index e9b27ca..ee1de29 100644 --- a/test/runtime/isula/CMakeLists.txt +++ b/test/runtime/isula/CMakeLists.txt @@ -34,6 +34,7 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map + ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/api ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/services/execution/manager ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/events ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/runtime diff --git a/test/runtime/lcr/CMakeLists.txt b/test/runtime/lcr/CMakeLists.txt index cf4b9b6..2ff170a 100644 --- a/test/runtime/lcr/CMakeLists.txt +++ b/test/runtime/lcr/CMakeLists.txt @@ -35,6 +35,7 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon + ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/api ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container/restart_manager ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container/health_check diff --git a/test/services/execution/execute/execution_extend/CMakeLists.txt b/test/services/execution/execute/execution_extend/CMakeLists.txt index 0a28d96..e8debb5 100644 --- a/test/services/execution/execute/execution_extend/CMakeLists.txt +++ b/test/services/execution/execute/execution_extend/CMakeLists.txt @@ -57,6 +57,7 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/console ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils + ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/api ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/image ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/service ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/modules/container diff --git a/test/specs/specs/CMakeLists.txt b/test/specs/specs/CMakeLists.txt index 1b18c54..ca45f8a 100644 --- a/test/specs/specs/CMakeLists.txt +++ b/test/specs/specs/CMakeLists.txt @@ -42,6 +42,7 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd/isulad ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon + ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/api ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/runtime ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container/restart_manager diff --git a/test/specs/specs/specs_ut.cpp b/test/specs/specs/specs_ut.cpp index 39b13ff..307830f 100644 --- a/test/specs/specs/specs_ut.cpp +++ b/test/specs/specs/specs_ut.cpp @@ -18,7 +18,7 @@ #include #include "mock.h" #include "isula_libutils/oci_runtime_spec.h" -#include "specs.h" +#include "specs_api.h" #include "isula_libutils/host_config.h" #include "isula_libutils/container_config.h" #include "oci_ut_common.h" @@ -69,7 +69,7 @@ TEST(merge_conf_cgroup_ut, test_merge_conf_cgroup_2) oci_runtime_spec *oci_spec = NULL; // Parameter host_spec is NULL - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); ASSERT_NE(merge_conf_cgroup(oci_spec, NULL), 0); free_oci_runtime_spec(oci_spec); @@ -113,7 +113,7 @@ TEST(merge_conf_cgroup_ut, test_merge_conf_cgroup) free(host_config_file); host_config_file = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); ASSERT_EQ(merge_conf_cgroup(oci_spec, host_spec), 0); @@ -245,10 +245,10 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_2) oci_runtime_spec *oci_spec = nullptr; host_config *host_spec = nullptr; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - host_spec = (host_config *) util_common_calloc_s(sizeof(host_config)); + host_spec = (host_config *)util_common_calloc_s(sizeof(host_config)); ASSERT_TRUE(host_spec != NULL); EXPECT_CALL(m_isulad_conf, GetCgroupParent()).WillRepeatedly(Invoke(invoke_conf_get_isulad_cgroup_parent_null)); @@ -268,10 +268,10 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_3) oci_runtime_spec *oci_spec = nullptr; host_config *host_spec = nullptr; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - host_spec = (host_config *) util_common_calloc_s(sizeof(host_config)); + host_spec = (host_config *)util_common_calloc_s(sizeof(host_config)); ASSERT_TRUE(host_spec != NULL); host_spec->cgroup_parent = util_strdup_s("/test"); @@ -293,10 +293,10 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_4) oci_runtime_spec *oci_spec = nullptr; host_config *host_spec = nullptr; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - host_spec = (host_config *) util_common_calloc_s(sizeof(host_config)); + host_spec = (host_config *)util_common_calloc_s(sizeof(host_config)); ASSERT_TRUE(host_spec != NULL); EXPECT_CALL(m_isulad_conf, GetCgroupParent()).WillRepeatedly(Invoke(invoke_conf_get_isulad_cgroup_parent)); @@ -316,10 +316,10 @@ TEST_F(SpecsUnitTest, test_merge_oci_cgroups_path_5) oci_runtime_spec *oci_spec = nullptr; host_config *host_spec = nullptr; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - host_spec = (host_config *) util_common_calloc_s(sizeof(host_config)); + host_spec = (host_config *)util_common_calloc_s(sizeof(host_config)); ASSERT_TRUE(host_spec != NULL); host_spec->cgroup_parent = util_strdup_s("/test"); diff --git a/test/specs/specs_extend/CMakeLists.txt b/test/specs/specs_extend/CMakeLists.txt index 0451bfc..1820b42 100644 --- a/test/specs/specs_extend/CMakeLists.txt +++ b/test/specs/specs_extend/CMakeLists.txt @@ -42,6 +42,7 @@ target_include_directories(${EXE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd/isulad ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon + ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/api ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container/restart_manager ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/modules/container/health_check diff --git a/test/specs/specs_extend/specs_extend_ut.cpp b/test/specs/specs_extend/specs_extend_ut.cpp index 4b77605..65017a6 100644 --- a/test/specs/specs_extend/specs_extend_ut.cpp +++ b/test/specs/specs_extend/specs_extend_ut.cpp @@ -18,7 +18,7 @@ #include #include "mock.h" #include "isula_libutils/oci_runtime_spec.h" -#include "specs.h" +#include "specs_api.h" #include "isula_libutils/host_config.h" #include "isula_libutils/container_config.h" #include "oci_ut_common.h" @@ -47,7 +47,7 @@ using namespace std; TEST(make_sure_oci_spec_linux_ut, test_make_sure_oci_spec_linux) { oci_runtime_spec *oci_spec = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); ASSERT_EQ(make_sure_oci_spec_linux(oci_spec), 0); ASSERT_TRUE(oci_spec->linux != NULL); @@ -58,7 +58,7 @@ TEST(make_sure_oci_spec_linux_ut, test_make_sure_oci_spec_linux) TEST(make_sure_oci_spec_process_ut, test_make_sure_oci_spec_process) { oci_runtime_spec *oci_spec = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); ASSERT_EQ(make_sure_oci_spec_process(oci_spec), 0); ASSERT_TRUE(oci_spec->process != NULL); @@ -69,7 +69,7 @@ TEST(make_sure_oci_spec_process_ut, test_make_sure_oci_spec_process) TEST(make_sure_oci_spec_linux_resources_ut, test_make_sure_oci_spec_linux_resources) { oci_runtime_spec *oci_spec = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); ASSERT_EQ(make_sure_oci_spec_linux_resources(oci_spec), 0); ASSERT_TRUE(oci_spec->linux != NULL); @@ -81,7 +81,7 @@ TEST(make_sure_oci_spec_linux_resources_ut, test_make_sure_oci_spec_linux_resour TEST(make_sure_oci_spec_linux_resources_blkio_ut, test_make_sure_oci_spec_linux_resources_blkio) { oci_runtime_spec *oci_spec = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); ASSERT_EQ(make_sure_oci_spec_linux_resources_blkio(oci_spec), 0); ASSERT_TRUE(oci_spec->linux != NULL); @@ -100,9 +100,9 @@ TEST(merge_hooks_ut, test_merge_hooks_ut_2) { oci_runtime_spec *oci_spec = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); + oci_spec->hooks = (oci_runtime_spec_hooks *)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); ASSERT_NE(merge_hooks(oci_spec->hooks, NULL), 0); free_oci_runtime_spec(oci_spec); oci_spec = NULL; @@ -144,9 +144,9 @@ TEST(merge_hooks_ut, test_merge_hooks_ut_4) free(hooks_config_file); hooks_config_file = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); + oci_spec->hooks = (oci_runtime_spec_hooks *)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0); @@ -172,9 +172,9 @@ TEST(merge_hooks_ut, test_merge_hooks_ut_prestart) free(hooks_config_file); hooks_config_file = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); + oci_spec->hooks = (oci_runtime_spec_hooks *)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0); ASSERT_EQ(oci_spec->hooks->prestart_len, 1); @@ -210,9 +210,9 @@ TEST(merge_hooks_ut, test_merge_hooks_ut_poststart) free(hooks_config_file); hooks_config_file = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); + oci_spec->hooks = (oci_runtime_spec_hooks *)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0); ASSERT_EQ(oci_spec->hooks->poststart_len, 2); @@ -257,9 +257,9 @@ TEST(merge_hooks_ut, test_merge_hooks_ut_poststop) free(hooks_config_file); hooks_config_file = NULL; - oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec)); + oci_spec = (oci_runtime_spec *)util_common_calloc_s(sizeof(oci_runtime_spec)); ASSERT_TRUE(oci_spec != NULL); - oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); + oci_spec->hooks = (oci_runtime_spec_hooks *)util_common_calloc_s(sizeof(oci_runtime_spec_hooks)); ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0); ASSERT_EQ(oci_spec->hooks->poststop_len, 2); -- GitLab