!17 sync from openeuler 3.7
Merge pull request !17 from Grooooot/events
This commit is contained in:
commit
356044983e
@ -108,10 +108,11 @@ bool file_exists(const char *f)
|
||||
int cmd_combined_output(const char *binary, const char *params[], void *output, int *output_len)
|
||||
{
|
||||
int ret = SHIM_ERR;
|
||||
int status = 0;
|
||||
int exec_fd[2] = { -1, -1 };
|
||||
int stdio[2] = { -1, -1 };
|
||||
pid_t pid = 0;
|
||||
char exec_buff[BUFSIZ + 1] = { 0 };
|
||||
char exec_buff[BUFSIZ] = { 0 };
|
||||
ssize_t nread;
|
||||
|
||||
if (pipe2(exec_fd, O_CLOEXEC) != 0) {
|
||||
@ -135,23 +136,24 @@ int cmd_combined_output(const char *binary, const char *params[], void *output,
|
||||
dup2(stdio[1], 2);
|
||||
execvp(binary, (char * const *)params);
|
||||
(void)dprintf(exec_fd[1], "fork/exec error: %s", strerror(errno));
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// parent
|
||||
close(exec_fd[1]);
|
||||
close(stdio[1]);
|
||||
nread = read_nointr(exec_fd[0], exec_buff, sizeof(exec_buff));
|
||||
nread = read_nointr(exec_fd[0], exec_buff, BUFSIZ - 1);
|
||||
if (nread > 0) {
|
||||
ret = SHIM_ERR;
|
||||
goto out;
|
||||
}
|
||||
*output_len = read_nointr(stdio[0], output, 8191);
|
||||
*output_len = read_nointr(stdio[0], output, BUFSIZ - 1);
|
||||
|
||||
close(stdio[0]);
|
||||
close(exec_fd[0]);
|
||||
int status = 0;
|
||||
wait(&status);
|
||||
ret = SHIM_OK;
|
||||
|
||||
out:
|
||||
if (ret != SHIM_OK && pid != 0) {
|
||||
kill(pid, 9);
|
||||
|
||||
@ -34,7 +34,7 @@ void signal_routine(int sig)
|
||||
switch (sig) {
|
||||
case SIGALRM:
|
||||
write_message(g_log_fd, ERR_MSG, "runtime timeout");
|
||||
exit(1);
|
||||
exit(EXIT_FAILURE);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -58,9 +58,8 @@ static shim_client_process_state* load_process()
|
||||
p_state = shim_client_process_state_parse_file("process.json", NULL, &err);
|
||||
if (p_state == NULL) {
|
||||
write_message(g_log_fd, ERR_MSG, "parse process state failed");
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
|
||||
if (err != NULL) {
|
||||
free(err);
|
||||
}
|
||||
@ -156,6 +155,7 @@ static int add_io_dispatch(int epfd, io_thread_t *io_thd, int from, int to)
|
||||
|
||||
ret = epoll_ctl(epfd, EPOLL_CTL_ADD, from, &ev);
|
||||
if (ret != SHIM_OK) {
|
||||
free(fn);
|
||||
write_message(g_log_fd, ERR_MSG, "add fd %d to epoll loop failed:%d", from, SHIM_SYS_ERR(errno));
|
||||
pthread_mutex_unlock(&(ioc->mutex));
|
||||
return SHIM_ERR;
|
||||
@ -417,13 +417,13 @@ static void* task_console_accept(void *data)
|
||||
conn_fd = accept(ac->listen_fd, NULL, NULL);
|
||||
if (conn_fd < 0) {
|
||||
write_message(g_log_fd, ERR_MSG, "accept from fd %d failed:%d", ac->listen_fd, SHIM_SYS_ERR(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
goto out;
|
||||
}
|
||||
|
||||
recv_fd = receive_fd(conn_fd);
|
||||
if (check_fd(recv_fd) != true) {
|
||||
write_message(g_log_fd, ERR_MSG, "check console fd failed");
|
||||
exit(EXIT_FAILURE);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// do console io copy
|
||||
@ -431,18 +431,19 @@ static void* task_console_accept(void *data)
|
||||
// p.state.stdin---->runtime.console
|
||||
ret = connect_to_isulad(ac->p, stdid_in, ac->p->state->isulad_stdin, recv_fd);
|
||||
if (ret != SHIM_OK) {
|
||||
exit(EXIT_FAILURE);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// p.state.stdout<------runtime.console
|
||||
ret = connect_to_isulad(ac->p, stdid_out, ac->p->state->isulad_stdout, recv_fd);
|
||||
if (ret != SHIM_OK) {
|
||||
exit(EXIT_FAILURE);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// if the terminal is used, we do not need to active the io copy of stderr pipe
|
||||
destory_io_thread(ac->p, stdid_err);
|
||||
|
||||
out:
|
||||
// release listen socket
|
||||
close_fd(&ac->listen_fd);
|
||||
if (ac->p->console_sock_path != NULL) {
|
||||
@ -451,6 +452,9 @@ static void* task_console_accept(void *data)
|
||||
ac->p->console_sock_path = NULL;
|
||||
}
|
||||
free(ac);
|
||||
if (ret != SHIM_OK) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -513,7 +517,8 @@ static int console_init(process_t *p)
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
return SHIM_SYS_ERR(errno);
|
||||
write_message(g_log_fd, ERR_MSG, "create socket failed:%d", SHIM_SYS_ERR(errno));
|
||||
goto failure;
|
||||
}
|
||||
|
||||
(void)memset(&addr, 0, sizeof(addr));
|
||||
@ -556,6 +561,7 @@ failure:
|
||||
if (ac != NULL) {
|
||||
free(ac);
|
||||
}
|
||||
unlink(p->console_sock_path);
|
||||
|
||||
return SHIM_ERR;
|
||||
}
|
||||
@ -628,12 +634,7 @@ static int open_terminal_io(process_t *p)
|
||||
}
|
||||
|
||||
// begin listen and accept fd from p->console_sock_path
|
||||
ret = console_init(p);
|
||||
if (ret != SHIM_OK) {
|
||||
write_message(g_log_fd, ERR_MSG, "init console failed:%d", ret);
|
||||
return SHIM_ERR;
|
||||
}
|
||||
return SHIM_OK;
|
||||
return console_init(p);
|
||||
}
|
||||
|
||||
|
||||
@ -821,7 +822,7 @@ static void process_kill_all(process_t *p)
|
||||
return;
|
||||
}
|
||||
|
||||
void process_delete(process_t *p)
|
||||
static void process_delete(process_t *p)
|
||||
{
|
||||
if (p->state->exec) {
|
||||
return;
|
||||
|
||||
@ -90,7 +90,6 @@ int open_io(process_t *p);
|
||||
int process_io_init(process_t *p);
|
||||
int create_process(process_t *p);
|
||||
int process_signal_handle_routine(process_t *p);
|
||||
void process_delete(process_t *p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -180,9 +180,9 @@ static void supplement_msg_for_events_handler(const struct monitord_msg *msg, st
|
||||
static int supplement_operator_for_container_msg(const struct monitord_msg *msg,
|
||||
struct isulad_events_format *format_msg)
|
||||
{
|
||||
#define OPERATOR_MAX_LEN 50
|
||||
#define CONTAINER_OPERATOR_MAX_LEN 300
|
||||
int nret = 0;
|
||||
char opt[OPERATOR_MAX_LEN] = {0x00};
|
||||
char opt[CONTAINER_OPERATOR_MAX_LEN] = {0x00};
|
||||
|
||||
if (strlen(msg->args) != 0) {
|
||||
nret = snprintf(opt, sizeof(opt), "container %s: %s", isulad_event_sta2str(msg->value), msg->args);
|
||||
@ -403,10 +403,10 @@ out:
|
||||
|
||||
static int supplement_msg_for_image(struct monitord_msg *msg, struct isulad_events_format *format_msg)
|
||||
{
|
||||
#define OPERATOR_MAX_LEN 50
|
||||
#define IMAGE_OPERATOR_MAX_LEN 50
|
||||
int ret = 0;
|
||||
int nret = 0;
|
||||
char opt[OPERATOR_MAX_LEN] = {0x00};
|
||||
char opt[IMAGE_OPERATOR_MAX_LEN] = {0x00};
|
||||
|
||||
format_msg->id = util_strdup_s(msg->name);
|
||||
|
||||
@ -672,17 +672,17 @@ static int event_copy(const struct isulad_events_format *src, struct isulad_even
|
||||
}
|
||||
|
||||
if (src->annotations_len != 0) {
|
||||
util_free_array(dest->annotations);
|
||||
util_free_array_by_len(dest->annotations, dest->annotations_len);
|
||||
dest->annotations = (char **)util_common_calloc_s(src->annotations_len * sizeof(char *));
|
||||
if (dest->annotations == NULL) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dest->annotations)
|
||||
for (i = 0; i < src->annotations_len; i++) {
|
||||
dest->annotations[i] = util_strdup_s(src->annotations[i]);
|
||||
}
|
||||
|
||||
dest->annotations_len = src->annotations_len;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user