提交 f36dd647 编写于 作者: L lifeng68

refact: split events to events_sender

Signed-off-by: Nlifeng68 <lifeng68@huawei.com>
上级 1e621b03
......@@ -118,6 +118,14 @@ extern "C" {
#define MAX_HOSTS 10
#define EVENT_ARGS_MAX 255
#define EVENT_EXTRA_ANNOTATION_MAX 255
/* container id max length */
#define CONTAINER_ID_MAX_LEN 64
#define CONTAINER_EXEC_ID_MAX_LEN 64
typedef enum {
CONTAINER_STATUS_UNKNOWN = 0,
CONTAINER_STATUS_CREATED = 1,
......
......@@ -37,6 +37,7 @@
#include "utils_fs.h"
#include "utils_base64.h"
#include "utils_aes.h"
#include "constants.h"
#ifdef __cplusplus
extern "C" {
......@@ -95,11 +96,6 @@ extern "C" {
#define UINT_LEN 10
/* container id max length */
#define CONTAINER_ID_MAX_LEN 64
#define CONTAINER_EXEC_ID_MAX_LEN 64
#define LIST_SIZE_MAX 1000LL
#define LIST_DEVICE_SIZE_MAX 10000LL
#define LIST_ENV_SIZE_MAX 200000LL
......
......@@ -10,6 +10,7 @@ add_subdirectory(container)
add_subdirectory(connect)
add_subdirectory(log)
add_subdirectory(events)
add_subdirectory(events_sender)
set(local_daemon_srcs
${daemon_top_srcs}
......@@ -22,6 +23,7 @@ set(local_daemon_srcs
${SERVER_CONNECT_SRCS}
${LOG_GATHER_SRCS}
${EVENTS_SRCS}
${EVENTS_SENDER_SRCS}
)
set(local_daemon_incs
......@@ -35,6 +37,7 @@ set(local_daemon_incs
${SERVER_CONNECT_INCS}
${LOG_GATHER_INCS}
${EVENTS_INCS}
${EVENTS_SENDER_INCS}
)
if (GRPC_CONNECTOR)
......
......@@ -51,7 +51,7 @@
#include "specs_extend.h"
#include "utils.h"
#include "error.h"
#include "collector.h"
#include "event_sender.h"
#include "specs.h"
static int filter_by_label(const container_t *cont, const container_get_id_request *request)
......@@ -1250,7 +1250,7 @@ static int kill_with_signal(container_t *cont, uint32_t signal)
const char *id = cont->common_config->id;
bool need_unpause = is_paused(cont->state);
rt_resume_params_t params = { 0 };
char annotations[EXTRA_ANNOTATION_MAX] = { 0 };
char annotations[EVENT_EXTRA_ANNOTATION_MAX] = { 0 };
if (container_exit_on_next(cont)) {
ERROR("Failed to cancel restart manager");
......
......@@ -43,7 +43,7 @@
#include "error.h"
#include "constants.h"
#include "namespace.h"
#include "collector.h"
#include "event_sender.h"
#include "sysinfo.h"
static int runtime_check(const char *name, bool *runtime_res)
......
......@@ -27,6 +27,7 @@
#include <sys/sysinfo.h>
#include "isula_libutils/log.h"
#include "event_sender.h"
#include "collector.h"
#include "console.h"
#include "isulad_config.h"
......
......@@ -42,7 +42,7 @@
#include "list.h"
#include "utils.h"
#include "error.h"
#include "collector.h"
#include "event_sender.h"
static int container_version_cb(const container_version_request *request, container_version_response **response)
{
......@@ -1648,7 +1648,7 @@ static int container_rename_cb(const struct isulad_container_rename_request *req
char *old_name = NULL;
char *new_name = NULL;
container_t *cont = NULL;
char annotations[EXTRA_ANNOTATION_MAX] = { 0 };
char annotations[EVENT_EXTRA_ANNOTATION_MAX] = { 0 };
DAEMON_CLEAR_ERRMSG();
......
......@@ -44,7 +44,7 @@
#include "isula_libutils/logger_json_file.h"
#include "constants.h"
#include "runtime.h"
#include "collector.h"
#include "event_sender.h"
static char *create_single_fifo(const char *statepath, const char *subpath, const char *stdflag)
{
......@@ -495,8 +495,7 @@ err_out:
return NULL;
}
static int exec_container(container_t *cont, const char *runtime, char * const console_fifos[],
defs_process_user *puser,
static int exec_container(container_t *cont, const char *runtime, char * const console_fifos[], defs_process_user *puser,
const container_exec_request *request, int *exit_code)
{
int ret = 0;
......@@ -727,7 +726,7 @@ static int container_exec_cb(const container_exec_request *request, container_ex
pthread_t thread_id = 0;
container_t *cont = NULL;
defs_process_user *puser = NULL;
char exec_command[ARGS_MAX] = { 0x00 };
char exec_command[EVENT_ARGS_MAX] = { 0x00 };
DAEMON_CLEAR_ERRMSG();
if (request == NULL || response == NULL) {
......
......@@ -33,7 +33,7 @@
#include "isulad_config.h"
#include "mediatype.h"
#include "filters.h"
#include "collector.h"
#include "event_sender.h"
#ifdef ENABLE_OCI_IMAGE
#include "oci_common_operators.h"
#endif
......
......@@ -22,7 +22,7 @@
#include "supervisor.h"
#include "mainloop.h"
#include "libisulad.h"
#include "collector.h"
#include "event_sender.h"
#include "execution.h"
#include "containers_gc.h"
......@@ -211,8 +211,7 @@ int new_clean_resources_thread(struct supervisor_handler_data *data)
}
/* supervisor exit cb */
static int supervisor_exit_cb(int fd, uint32_t events, void *cbdata,
struct epoll_descr *descr)
static int supervisor_exit_cb(int fd, uint32_t events, void *cbdata, struct epoll_descr *descr)
{
ssize_t r = 0;
int exit_code = 0;
......@@ -334,4 +333,3 @@ int new_supervisor()
out:
return ret;
}
......@@ -26,7 +26,7 @@
#include "isula_libutils/log.h"
#include "utils.h"
#include "cri_helpers.h"
#include "collector.h"
#include "event_sender.h"
static void conv_image_to_grpc(const imagetool_image *element, std::unique_ptr<runtime::v1alpha2::Image> &image)
{
......
......@@ -33,6 +33,7 @@
#include "libisulad.h"
#include "containers_store.h"
#include "container_unix.h"
#include "event_sender.h"
static struct context_lists g_context_lists;
......@@ -200,7 +201,7 @@ static int supplement_pid_for_container_msg(const container_t *cont, const struc
struct isulad_events_format *format_msg)
{
int nret = 0;
char info[EXTRA_ANNOTATION_MAX] = { 0x00 };
char info[EVENT_EXTRA_ANNOTATION_MAX] = { 0x00 };
if (cont->state == NULL || cont->state->state == NULL || cont->state->state->pid <= 0) {
return 0;
......@@ -224,7 +225,7 @@ static int supplement_exitcode_for_container_msg(const container_t *cont, const
{
int nret = 0;
int exit_code = 0;
char info[EXTRA_ANNOTATION_MAX] = { 0x00 };
char info[EVENT_EXTRA_ANNOTATION_MAX] = { 0x00 };
if (format_msg->exit_status != 0) {
exit_code = format_msg->exit_status;
......@@ -253,7 +254,7 @@ static int supplement_image_for_container_msg(const container_t *cont, const str
struct isulad_events_format *format_msg)
{
int nret = 0;
char info[EXTRA_ANNOTATION_MAX] = { 0x00 };
char info[EVENT_EXTRA_ANNOTATION_MAX] = { 0x00 };
if (cont->common_config == NULL || cont->common_config->image == NULL) {
return 0;
......@@ -276,7 +277,7 @@ static int supplement_name_for_container_msg(const container_t *cont, const stru
struct isulad_events_format *format_msg)
{
int nret = 0;
char info[EXTRA_ANNOTATION_MAX] = { 0x00 };
char info[EVENT_EXTRA_ANNOTATION_MAX] = { 0x00 };
if (cont->common_config == NULL || cont->common_config->name == NULL) {
return 0;
......@@ -306,7 +307,7 @@ static int supplement_labels_for_container_msg(const container_t *cont, const st
}
for (i = 0; i < cont->common_config->config->labels->len; i++) {
char info[EXTRA_ANNOTATION_MAX] = { 0x00 };
char info[EVENT_EXTRA_ANNOTATION_MAX] = { 0x00 };
int nret = snprintf(info, sizeof(info), "%s=%s", cont->common_config->config->labels->keys[i],
cont->common_config->config->labels->values[i]);
if (nret < 0 || nret >= sizeof(info)) {
......@@ -457,139 +458,6 @@ static bool format_msg(struct isulad_events_format *r, struct monitord_msg *msg)
return ret;
}
/* isulad monitor fifo send */
static void isulad_monitor_fifo_send(const struct monitord_msg *msg, const char *statedir)
{
int fd = -1;
ssize_t ret = 0;
char *fifo_path = NULL;
fifo_path = isulad_monitor_fifo_name(statedir);
if (fifo_path == NULL) {
return;
}
/* Open the fifo nonblock in case the monitor is dead, we don't want the
* open to wait for a reader since it may never come.
*/
fd = util_open(fifo_path, O_WRONLY | O_NONBLOCK, 0);
if (fd < 0) {
/* It is normal for this open() to fail with ENXIO when there is
* no monitor running, so we don't log it.
*/
if (errno == ENXIO || errno == ENOENT) {
goto out;
}
ERROR("Failed to open fifo to send message: %s.", strerror(errno));
goto out;
}
do {
ret = util_write_nointr(fd, msg, sizeof(struct monitord_msg));
if (ret != sizeof(struct monitord_msg)) {
usleep_nointerupt(1000);
}
} while (ret != sizeof(struct monitord_msg));
out:
free(fifo_path);
if (fd >= 0) {
close(fd);
}
}
/* isulad monitor send container event */
int isulad_monitor_send_container_event(const char *name, runtime_state_t state, int pid, int exit_code,
const char *args, const char *extra_annations)
{
int ret = 0;
char *statedir = NULL;
struct monitord_msg msg = { .type = MONITORD_MSG_STATE,
.event_type = CONTAINER_EVENT,
.value = state,
.pid = -1,
.exit_code = -1,
.args = { 0x00 },
.extra_annations = { 0x00 }
};
if (name == NULL) {
CRIT("Invalid input arguments");
ret = -1;
goto out;
}
statedir = conf_get_isulad_statedir();
if (statedir == NULL) {
CRIT("Can not get isulad root path");
ret = -1;
goto out;
}
(void)strncpy(msg.name, name, sizeof(msg.name) - 1);
msg.name[sizeof(msg.name) - 1] = '\0';
if (args != NULL) {
(void)strncpy(msg.args, args, sizeof(msg.args) - 1);
msg.args[sizeof(msg.args) - 1] = '\0';
}
if (extra_annations != NULL) {
(void)strncpy(msg.extra_annations, extra_annations, sizeof(msg.extra_annations) - 1);
msg.extra_annations[sizeof(msg.extra_annations) - 1] = '\0';
}
if (pid > 0) {
msg.pid = pid;
}
if (exit_code >= 0) {
msg.exit_code = exit_code;
}
isulad_monitor_fifo_send(&msg, statedir);
out:
free(statedir);
return ret;
}
/* isulad monitor send image event */
int isulad_monitor_send_image_event(const char *name, image_state_t state)
{
int ret = 0;
char *statedir = NULL;
struct monitord_msg msg = { .type = MONITORD_MSG_STATE,
.event_type = IMAGE_EVENT,
.value = state,
.args = { 0x00 },
.extra_annations = { 0x00 }
};
if (name == NULL) {
CRIT("Invalid input arguments");
ret = -1;
goto out;
}
statedir = conf_get_isulad_statedir();
if (statedir == NULL) {
CRIT("Can not get isulad root path");
ret = -1;
goto out;
}
(void)strncpy(msg.name, name, sizeof(msg.name) - 1);
msg.name[sizeof(msg.name) - 1] = '\0';
isulad_monitor_fifo_send(&msg, statedir);
out:
free(statedir);
return ret;
}
static int calculate_annaotation_info_len(const struct isulad_events_format *events)
{
size_t i;
......@@ -691,6 +559,24 @@ static int event_copy(const struct isulad_events_format *src, struct isulad_even
return 0;
}
struct isulad_events_format *dup_event(const struct isulad_events_format *event)
{
struct isulad_events_format *out = NULL;
if (event == NULL || event->id == NULL) {
return NULL;
}
out = util_common_calloc_s(sizeof(struct isulad_events_format));
if (out == NULL) {
return NULL;
}
event_copy(event, out);
return out;
}
/* events append */
static void events_append(const struct isulad_events_format *event)
{
......@@ -1065,25 +951,6 @@ out:
isulad_events_format_free(events);
}
/* dup event */
struct isulad_events_format *dup_event(const struct isulad_events_format *event)
{
struct isulad_events_format *out = NULL;
if (event == NULL || event->id == NULL) {
return NULL;
}
out = util_common_calloc_s(sizeof(struct isulad_events_format));
if (out == NULL) {
return NULL;
}
event_copy(event, out);
return out;
}
/* add monitor client */
int add_monitor_client(char *name, const types_timestamp_t *since, const types_timestamp_t *until,
const stream_func_wrapper *stream)
......
......@@ -19,7 +19,7 @@
#include <semaphore.h>
#include "linked_list.h"
#include "libisulad.h"
#include "monitord.h"
#include "event_type.h"
#ifdef __cplusplus
extern "C" {
......@@ -30,41 +30,6 @@ struct context_lists {
struct linked_list context_list;
};
typedef enum {
EXIT,
STOPPED,
STARTING,
RUNNING,
STOPPING,
ABORTING,
FREEZING,
FROZEN,
THAWED,
OOM,
CREATE,
START,
RESTART,
STOP,
EXEC_CREATE,
EXEC_START,
EXEC_DIE,
ATTACH,
KILL,
TOP,
RENAME,
ARCHIVE_PATH,
EXTRACT_TO_DIR,
UPDATE,
PAUSE,
UNPAUSE,
EXPORT,
RESIZE,
PAUSED1,
MAX_STATE,
} runtime_state_t;
typedef enum { IM_LOAD, IM_REMOVE, IM_PULL, IM_LOGIN, IM_LOGOUT, IM_IMPORT } image_state_t;
int newcollector();
void events_handler(struct monitord_msg *msg);
......@@ -77,11 +42,6 @@ int events_subscribe(const char *name, const types_timestamp_t *since, const typ
struct isulad_events_format *dup_event(const struct isulad_events_format *event);
int isulad_monitor_send_container_event(const char *name, runtime_state_t state, int pid, int exit_code,
const char *args, const char *extra_annations);
int isulad_monitor_send_image_event(const char *name, image_state_t state);
#ifdef __cplusplus
}
#endif
......
......@@ -129,8 +129,8 @@ static int container_state_changed(container_t *cont, const struct isulad_events
pid = state_get_pid(cont->state);
if (pid != (int)events->pid) {
DEBUG("Container's pid \'%d\' is not equal to event's pid \'%d\', ignore STOPPED event",
pid, events->pid);
DEBUG("Container's pid \'%d\' is not equal to event's pid \'%d\', ignore STOPPED event", pid,
events->pid);
container_unlock(cont);
ret = 0;
goto out;
......@@ -254,7 +254,8 @@ static void *events_handler_thread(void *args)
goto out;
}
while (handle_one(cont, handler) == 0) {}
while (handle_one(cont, handler) == 0) {
}
out:
container_unref(cont);
......@@ -264,8 +265,7 @@ out:
}
/* events handler post events */
int events_handler_post_events(events_handler_t *handler,
const struct isulad_events_format *event)
int events_handler_post_events(events_handler_t *handler, const struct isulad_events_format *event)
{
int ret = 0;
char *name = NULL;
......@@ -312,4 +312,3 @@ out:
events_handler_unlock(handler);
return ret;
}
......@@ -29,6 +29,7 @@
#include "isulad_config.h"
#include "collector.h"
#include "utils.h"
#include "event_sender.h"
struct monitord_handler {
struct epoll_descr *pdescr;
......@@ -36,27 +37,6 @@ struct monitord_handler {
char *fifo_path;
};
/* isulad monitor fifo name */
char *isulad_monitor_fifo_name(const char *rootpath)
{
int ret;
char fifo_file_path[PATH_MAX] = { 0 };
if (rootpath == NULL) {
ERROR("Invalid parameter");
goto err;
}
ret = snprintf(fifo_file_path, PATH_MAX, "%s/monitord_fifo", rootpath);
if (ret < 0 || (size_t)ret >= PATH_MAX) {
ERROR("Create monitord fifo path failed");
goto err;
}
return util_strdup_s(fifo_file_path);
err:
return NULL;
}
/* monitor event cb */
static int monitor_event_cb(int fd, uint32_t events, void *cbdata, struct epoll_descr *descr)
{
......@@ -102,7 +82,6 @@ static void free_monitord(struct monitord_handler *mhandler)
static void *monitord(void *arg)
{
int ret = 0;
char *statedir = NULL;
char *fifo_file_path = NULL;
struct monitord_handler mhandler = { 0 };
struct flock mlock;
......@@ -125,14 +104,8 @@ static void *monitord(void *arg)
}
mhandler.pdescr = &descr;
statedir = conf_get_isulad_statedir();
if (statedir == NULL) {
CRIT("Can not get isulad root path");
goto err;
}
/* 1. monitor fifo: to wait container monitor message */
fifo_file_path = isulad_monitor_fifo_name(statedir);
fifo_file_path = conf_get_isulad_monitor_fifo_path();
if (fifo_file_path == NULL) {
goto err;
}
......@@ -183,7 +156,6 @@ err:
*(msync->exit_code) = -1;
sem_post(msync->monitord_sem);
err2:
free(statedir);
free_monitord(&mhandler);
epoll_loop_close(&descr);
......
......@@ -20,34 +20,11 @@
#include "libisulad.h"
#include "utils.h"
#define ARGS_MAX 255 /* # args chars in a monitord msg */
#define EXTRA_ANNOTATION_MAX 255 /* # annotation chars in a monitord msg */
typedef enum { CONTAINER_EVENT, IMAGE_EVENT } msg_event_type_t;
typedef enum { MONITORD_MSG_STATE, MONITORD_MSG_PRIORITY, MONITORD_MSG_EXIT_CODE } msg_type_t;
struct monitord_msg {
msg_type_t type;
msg_event_type_t event_type;
char name[CONTAINER_ID_MAX_LEN + 1];
char args[ARGS_MAX];
char extra_annations[EXTRA_ANNOTATION_MAX];
int value;
int exit_code;
int pid;
};
struct monitord_sync_data {
sem_t *monitord_sem;
int *exit_code;
};
char *isulad_monitor_fifo_name(const char *rootpath);
int connect_monitord(const char *rootpath);
int read_monitord_message_timeout(int fd, struct monitord_msg *msg, int timeout);
int new_monitord(struct monitord_sync_data *msync);
#endif
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_events_sender_srcs)
set(EVENTS_SENDER_SRCS
${local_events_sender_srcs}
PARENT_SCOPE
)
set(EVENTS_SENDER_INCS
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE
)
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2020-06-23
* Description: provide container collector definition
******************************************************************************/
#define _GNU_SOURCE
#include "event_sender.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <signal.h>
#include <poll.h>
#include <sys/prctl.h>
#include <regex.h>
#include <errno.h>
#include "error.h"
#include "isula_libutils/log.h"
#include "isulad_config.h"
/* isulad monitor fifo send */
static void isulad_monitor_fifo_send(const struct monitord_msg *msg)
{
int fd = -1;
ssize_t ret = 0;
char *fifo_path = NULL;
fifo_path = conf_get_isulad_monitor_fifo_path();
if (fifo_path == NULL) {
return;
}
/* Open the fifo nonblock in case the monitor is dead, we don't want the
* open to wait for a reader since it may never come.
*/
fd = util_open(fifo_path, O_WRONLY | O_NONBLOCK, 0);
if (fd < 0) {
/* It is normal for this open() to fail with ENXIO when there is
* no monitor running, so we don't log it.
*/
if (errno == ENXIO || errno == ENOENT) {
goto out;
}
ERROR("Failed to open fifo to send message: %s.", strerror(errno));
goto out;
}
do {
ret = util_write_nointr(fd, msg, sizeof(struct monitord_msg));
if (ret != sizeof(struct monitord_msg)) {
usleep_nointerupt(1000);
}
} while (ret != sizeof(struct monitord_msg));
out:
free(fifo_path);
if (fd >= 0) {
close(fd);
}
}
/* isulad monitor send container event */
int isulad_monitor_send_container_event(const char *name, runtime_state_t state, int pid, int exit_code,
const char *args, const char *extra_annations)
{
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 }
};
if (name == NULL) {
CRIT("Invalid input arguments");
ret = -1;
goto out;
}
(void)strncpy(msg.name, name, sizeof(msg.name) - 1);
msg.name[sizeof(msg.name) - 1] = '\0';
if (args != NULL) {
(void)strncpy(msg.args, args, sizeof(msg.args) - 1);
msg.args[sizeof(msg.args) - 1] = '\0';
}
if (extra_annations != NULL) {
(void)strncpy(msg.extra_annations, extra_annations, sizeof(msg.extra_annations) - 1);
msg.extra_annations[sizeof(msg.extra_annations) - 1] = '\0';
}
if (pid > 0) {
msg.pid = pid;
}
if (exit_code >= 0) {
msg.exit_code = exit_code;
}
isulad_monitor_fifo_send(&msg);
out:
return ret;
}
/* isulad monitor send image event */
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 }
};
if (name == NULL) {
CRIT("Invalid input arguments");
ret = -1;
goto out;
}
(void)strncpy(msg.name, name, sizeof(msg.name) - 1);
msg.name[sizeof(msg.name) - 1] = '\0';
isulad_monitor_fifo_send(&msg);
out:
return ret;
}
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2020-06-23
* Description: provide container collector definition
******************************************************************************/
#ifndef __EVENT_SENDER_H
#define __EVENT_SENDER_H
#include "event_type.h"
#ifdef __cplusplus
extern "C" {
#endif
int isulad_monitor_send_container_event(const char *name, runtime_state_t state, int pid, int exit_code,
const char *args, const char *extra_annations);
int isulad_monitor_send_image_event(const char *name, image_state_t state);
#ifdef __cplusplus
}
#endif
#endif /* __EVENT_SENDER_H */
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2020-06-23
* Description: provide container collector definition
******************************************************************************/
#ifndef __EVENT_TYPE_H
#define __EVENT_TYPE_H
#include "constants.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
EXIT,
STOPPED,
STARTING,
RUNNING,
STOPPING,
ABORTING,
FREEZING,
FROZEN,
THAWED,
OOM,
CREATE,
START,
RESTART,
STOP,
EXEC_CREATE,
EXEC_START,
EXEC_DIE,
ATTACH,
KILL,
TOP,
RENAME,
ARCHIVE_PATH,
EXTRACT_TO_DIR,
UPDATE,
PAUSE,
UNPAUSE,
EXPORT,
RESIZE,
PAUSED1,
MAX_STATE,
} runtime_state_t;
typedef enum { IM_LOAD, IM_REMOVE, IM_PULL, IM_LOGIN, IM_LOGOUT, IM_IMPORT } image_state_t;
typedef enum { CONTAINER_EVENT, IMAGE_EVENT } msg_event_type_t;
typedef enum { MONITORD_MSG_STATE, MONITORD_MSG_PRIORITY, MONITORD_MSG_EXIT_CODE } msg_type_t;
struct monitord_msg {
msg_type_t type;
msg_event_type_t event_type;
char name[CONTAINER_ID_MAX_LEN + 1];
char args[EVENT_ARGS_MAX];
char extra_annations[EVENT_EXTRA_ANNOTATION_MAX];
int value;
int exit_code;
int pid;
};
#ifdef __cplusplus
}
#endif
#endif /* __EVENT_TYPE_H */
......@@ -469,6 +469,30 @@ out:
return path;
}
/* isulad monitor fifo name */
char *conf_get_isulad_monitor_fifo_path()
{
int ret;
char fifo_file_path[PATH_MAX] = { 0 };
char *rootpath = NULL;
rootpath = conf_get_isulad_statedir();
if (rootpath == NULL) {
ERROR("Invalid parameter");
goto err;
}
ret = snprintf(fifo_file_path, PATH_MAX, "%s/monitord_fifo", rootpath);
if (ret < 0 || (size_t)ret >= PATH_MAX) {
ERROR("Create monitord fifo path failed");
goto err;
}
return util_strdup_s(fifo_file_path);
err:
free(rootpath);
return NULL;
}
/* conf get isulad mount rootfs */
char *conf_get_isulad_mount_rootfs()
{
......
......@@ -93,6 +93,8 @@ bool conf_get_use_decrypted_key_flag();
bool conf_get_skip_insecure_verify_flag();
int parse_log_opts(struct service_arguments *args, const char *key, const char *value);
char *conf_get_isulad_monitor_fifo_path();
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册