X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=91fba2643fc2ae94acf79850fd0e9aa589cfbf90;hp=0a156d8e7e1d024c218b03be6a6e81b29ed7979f;hb=c617c0c651432f9d5ae7adf4c5c1a5fd92ad828e;hpb=178191b3899f114001f000c2e7f46909969f9c6f diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 0a156d8e7..91fba2643 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -59,7 +59,6 @@ #include "ust-consumer.h" #include "utils.h" #include "fd-limit.h" -#include "filter.h" #include "health.h" #include "testpoint.h" @@ -462,7 +461,7 @@ static void cleanup(void) static int send_unix_sock(int sock, void *buf, size_t len) { /* Check valid length */ - if (len <= 0) { + if (len == 0) { return -1; } @@ -634,7 +633,7 @@ static int update_kernel_stream(struct consumer_data *consumer_data, int fd) assert(socket->fd >= 0); pthread_mutex_lock(socket->lock); - ret = kernel_consumer_send_channel_stream(socket->fd, + ret = kernel_consumer_send_channel_stream(socket, channel, ksess); pthread_mutex_unlock(socket->lock); if (ret < 0) { @@ -690,14 +689,14 @@ static void *thread_manage_kernel(void *data) char tmp; struct lttng_poll_event events; - DBG("Thread manage kernel started"); + DBG("[thread] Thread manage kernel started"); - testpoint(thread_manage_kernel); + if (testpoint(thread_manage_kernel)) { + goto error_testpoint; + } health_code_update(&health_thread_kernel); - testpoint(thread_manage_kernel_before_loop); - ret = create_thread_poll_set(&events, 2); if (ret < 0) { goto error_poll_create; @@ -708,6 +707,10 @@ static void *thread_manage_kernel(void *data) goto error; } + if (testpoint(thread_manage_kernel_before_loop)) { + goto error; + } + while (1) { health_code_update(&health_thread_kernel); @@ -725,12 +728,7 @@ static void *thread_manage_kernel(void *data) update_poll_flag = 0; } - nb_fd = LTTNG_POLL_GETNB(&events); - - DBG("Thread kernel polling on %d fds", nb_fd); - - /* Zeroed the poll events */ - lttng_poll_reset(&events); + DBG("Thread kernel polling on %d fds", events.nb_fd); /* Poll infinite value of time */ restart: @@ -752,6 +750,8 @@ static void *thread_manage_kernel(void *data) continue; } + nb_fd = ret; + for (i = 0; i < nb_fd; i++) { /* Fetch once the poll data */ revents = LTTNG_POLL_GETEV(&events, i); @@ -795,6 +795,7 @@ exit: error: lttng_poll_clean(&events); error_poll_create: +error_testpoint: utils_close_pipe(kernel_poll_pipe); kernel_poll_pipe[0] = kernel_poll_pipe[1] = -1; if (err) { @@ -882,15 +883,15 @@ static void *thread_manage_consumer(void *data) goto error; } - nb_fd = LTTNG_POLL_GETNB(&events); - health_code_update(&consumer_data->health); /* Inifinite blocking call, waiting for transmission */ restart: health_poll_update(&consumer_data->health); - testpoint(thread_manage_consumer); + if (testpoint(thread_manage_consumer)) { + goto error; + } ret = lttng_poll_wait(&events, -1); health_poll_update(&consumer_data->health); @@ -904,6 +905,8 @@ restart: goto error; } + nb_fd = ret; + for (i = 0; i < nb_fd; i++) { /* Fetch once the poll data */ revents = LTTNG_POLL_GETEV(&events, i); @@ -981,9 +984,6 @@ restart: health_code_update(&consumer_data->health); - /* Update number of fd */ - nb_fd = LTTNG_POLL_GETNB(&events); - /* Inifinite blocking call, waiting for transmission */ restart_poll: health_poll_update(&consumer_data->health); @@ -999,6 +999,8 @@ restart_poll: goto error; } + nb_fd = ret; + for (i = 0; i < nb_fd; i++) { /* Fetch once the poll data */ revents = LTTNG_POLL_GETEV(&events, i); @@ -1094,11 +1096,13 @@ static void *thread_manage_apps(void *data) DBG("[thread] Manage application started"); - testpoint(thread_manage_apps); - rcu_register_thread(); rcu_thread_online(); + if (testpoint(thread_manage_apps)) { + goto error_testpoint; + } + health_code_update(&health_thread_app_manage); ret = create_thread_poll_set(&events, 2); @@ -1111,17 +1115,14 @@ static void *thread_manage_apps(void *data) goto error; } - testpoint(thread_manage_apps_before_loop); + if (testpoint(thread_manage_apps_before_loop)) { + goto error; + } health_code_update(&health_thread_app_manage); while (1) { - /* Zeroed the events structure */ - lttng_poll_reset(&events); - - nb_fd = LTTNG_POLL_GETNB(&events); - - DBG("Apps thread polling on %d fds", nb_fd); + DBG("Apps thread polling on %d fds", events.nb_fd); /* Inifinite blocking call, waiting for transmission */ restart: @@ -1138,6 +1139,8 @@ static void *thread_manage_apps(void *data) goto error; } + nb_fd = ret; + for (i = 0; i < nb_fd; i++) { /* Fetch once the poll data */ revents = LTTNG_POLL_GETEV(&events, i); @@ -1251,6 +1254,7 @@ exit: error: lttng_poll_clean(&events); error_poll_create: +error_testpoint: utils_close_pipe(apps_cmd_pipe); apps_cmd_pipe[0] = apps_cmd_pipe[1] = -1; @@ -1359,7 +1363,9 @@ static void *thread_registration_apps(void *data) DBG("[thread] Manage application registration started"); - testpoint(thread_registration_apps); + if (testpoint(thread_registration_apps)) { + goto error_testpoint; + } ret = lttcomm_listen_unix_sock(apps_sock); if (ret < 0) { @@ -1392,8 +1398,6 @@ static void *thread_registration_apps(void *data) while (1) { DBG("Accepting application registration"); - nb_fd = LTTNG_POLL_GETNB(&events); - /* Inifinite blocking call, waiting for transmission */ restart: health_poll_update(&health_thread_app_reg); @@ -1409,6 +1413,8 @@ static void *thread_registration_apps(void *data) goto error; } + nb_fd = ret; + for (i = 0; i < nb_fd; i++) { health_code_update(&health_thread_app_reg); @@ -1514,7 +1520,6 @@ error: health_error(&health_thread_app_reg); ERR("Health error occurred in %s", __func__); } - health_exit(&health_thread_app_reg); /* Notify that the registration thread is gone */ notify_ust_apps(0); @@ -1538,7 +1543,9 @@ error_poll_add: lttng_poll_clean(&events); error_listen: error_create_poll: +error_testpoint: DBG("UST Registration thread cleanup complete"); + health_exit(&health_thread_app_reg); return NULL; } @@ -1670,10 +1677,10 @@ error: static int join_consumer_thread(struct consumer_data *consumer_data) { void *status; - int ret; /* Consumer pid must be a real one. */ if (consumer_data->pid > 0) { + int ret; ret = kill(consumer_data->pid, SIGTERM); if (ret) { ERR("Error killing consumer daemon"); @@ -1852,7 +1859,7 @@ error: */ static int start_consumerd(struct consumer_data *consumer_data) { - int ret, err; + int ret; /* * Set the listen() state on the socket since there is a possible race @@ -1895,6 +1902,8 @@ end: error: /* Cleanup already created socket on error. */ if (consumer_data->err_sock >= 0) { + int err; + err = close(consumer_data->err_sock); if (err < 0) { PERROR("close consumer data error socket"); @@ -2525,7 +2534,7 @@ skip_domain: { ret = cmd_enable_event(cmd_ctx->session, cmd_ctx->lsm->domain.type, cmd_ctx->lsm->u.enable.channel_name, - &cmd_ctx->lsm->u.enable.event, kernel_poll_pipe[1]); + &cmd_ctx->lsm->u.enable.event, NULL, kernel_poll_pipe[1]); break; } case LTTNG_ENABLE_ALL_EVENT: @@ -2534,7 +2543,7 @@ skip_domain: ret = cmd_enable_event_all(cmd_ctx->session, cmd_ctx->lsm->domain.type, cmd_ctx->lsm->u.enable.channel_name, - cmd_ctx->lsm->u.enable.event.type, kernel_poll_pipe[1]); + cmd_ctx->lsm->u.enable.event.type, NULL, kernel_poll_pipe[1]); break; } case LTTNG_LIST_TRACEPOINTS: @@ -2846,15 +2855,19 @@ skip_domain: cmd_ctx->lsm->u.reg.path, cdata); break; } - case LTTNG_SET_FILTER: + case LTTNG_ENABLE_EVENT_WITH_FILTER: { struct lttng_filter_bytecode *bytecode; - if (cmd_ctx->lsm->u.filter.bytecode_len > LTTNG_FILTER_MAX_LEN) { + if (cmd_ctx->lsm->u.enable.bytecode_len > LTTNG_FILTER_MAX_LEN) { + ret = LTTNG_ERR_FILTER_INVAL; + goto error; + } + if (cmd_ctx->lsm->u.enable.bytecode_len == 0) { ret = LTTNG_ERR_FILTER_INVAL; goto error; } - bytecode = zmalloc(cmd_ctx->lsm->u.filter.bytecode_len); + bytecode = zmalloc(cmd_ctx->lsm->u.enable.bytecode_len); if (!bytecode) { ret = LTTNG_ERR_FILTER_NOMEM; goto error; @@ -2862,7 +2875,7 @@ skip_domain: /* Receive var. len. data */ DBG("Receiving var len data from client ..."); ret = lttcomm_recv_unix_sock(sock, bytecode, - cmd_ctx->lsm->u.filter.bytecode_len); + cmd_ctx->lsm->u.enable.bytecode_len); if (ret <= 0) { DBG("Nothing recv() from client var len data... continuing"); *sock_error = 1; @@ -2871,16 +2884,15 @@ skip_domain: } if (bytecode->len + sizeof(*bytecode) - != cmd_ctx->lsm->u.filter.bytecode_len) { + != cmd_ctx->lsm->u.enable.bytecode_len) { free(bytecode); ret = LTTNG_ERR_FILTER_INVAL; goto error; } - ret = cmd_set_filter(cmd_ctx->session, cmd_ctx->lsm->domain.type, - cmd_ctx->lsm->u.filter.channel_name, - &cmd_ctx->lsm->u.filter.event, - bytecode); + ret = cmd_enable_event(cmd_ctx->session, cmd_ctx->lsm->domain.type, + cmd_ctx->lsm->u.enable.channel_name, + &cmd_ctx->lsm->u.enable.event, bytecode, kernel_poll_pipe[1]); break; } case LTTNG_DATA_PENDING: @@ -2965,8 +2977,6 @@ static void *thread_manage_health(void *data) while (1) { DBG("Health check ready"); - nb_fd = LTTNG_POLL_GETNB(&events); - /* Inifinite blocking call, waiting for transmission */ restart: ret = lttng_poll_wait(&events, -1); @@ -2980,6 +2990,8 @@ restart: goto error; } + nb_fd = ret; + for (i = 0; i < nb_fd; i++) { /* Fetch once the poll data */ revents = LTTNG_POLL_GETEV(&events, i); @@ -3120,10 +3132,12 @@ static void *thread_manage_clients(void *data) DBG("[thread] Manage client started"); - testpoint(thread_manage_clients); - rcu_register_thread(); + if (testpoint(thread_manage_clients)) { + goto error_testpoint; + } + health_code_update(&health_thread_cmd); ret = lttcomm_listen_unix_sock(client_sock); @@ -3153,15 +3167,15 @@ static void *thread_manage_clients(void *data) kill(ppid, SIGUSR1); } - testpoint(thread_manage_clients_before_loop); + if (testpoint(thread_manage_clients_before_loop)) { + goto error; + } health_code_update(&health_thread_cmd); while (1) { DBG("Accepting client command ..."); - nb_fd = LTTNG_POLL_GETNB(&events); - /* Inifinite blocking call, waiting for transmission */ restart: health_poll_update(&health_thread_cmd); @@ -3177,6 +3191,8 @@ static void *thread_manage_clients(void *data) goto error; } + nb_fd = ret; + for (i = 0; i < nb_fd; i++) { /* Fetch once the poll data */ revents = LTTNG_POLL_GETEV(&events, i); @@ -3328,6 +3344,7 @@ error: error_listen: error_create_poll: +error_testpoint: unlink(client_unix_sock_path); if (client_sock >= 0) { ret = close(client_sock); @@ -3833,7 +3850,7 @@ int main(int argc, char **argv) /* Parse arguments */ progname = argv[0]; - if ((ret = parse_args(argc, argv) < 0)) { + if ((ret = parse_args(argc, argv)) < 0) { goto error; }