X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=4a2bc4fdd3ebd363c6a4fb35bd4a2de3039e8cb8;hb=0b2dc8df2a6d7b3341a72a04767dd6328907c97c;hp=2cb8f5a23e77b267b37dc513d5dccb8bdc994c40;hpb=ae9c20bc3d88d014d850b9e9b7df6b0f1e7ff894;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 2cb8f5a23..4a2bc4fdd 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -161,6 +161,7 @@ static pthread_t client_thread; static pthread_t kernel_thread; static pthread_t dispatch_thread; static pthread_t health_thread; +static pthread_t ht_cleanup_thread; /* * UST registration command queue. This queue is tied with a futex and uses a N @@ -705,9 +706,9 @@ static void *thread_manage_kernel(void *data) /* * This first step of the while is to clean this structure which could free - * non NULL pointers so zero it before the loop. + * non NULL pointers so initialize it before the loop. */ - memset(&events, 0, sizeof(events)); + lttng_poll_init(&events); if (testpoint(thread_manage_kernel)) { goto error_testpoint; @@ -1380,6 +1381,11 @@ static void *thread_dispatch_ust_registration(void *data) wait_node = zmalloc(sizeof(*wait_node)); if (!wait_node) { PERROR("zmalloc wait_node dispatch"); + ret = close(ust_cmd->sock); + if (ret < 0) { + PERROR("close ust sock dispatch %d", ust_cmd->sock); + } + lttng_fd_put(1, LTTNG_FD_APPS); free(ust_cmd); goto error; } @@ -1427,6 +1433,19 @@ static void *thread_dispatch_ust_registration(void *data) break; } } + + /* + * With no application at this stage the received socket is + * basically useless so close it before we free the cmd data + * structure for good. + */ + if (!app) { + ret = close(ust_cmd->sock); + if (ret < 0) { + PERROR("close ust sock dispatch %d", ust_cmd->sock); + } + lttng_fd_put(1, LTTNG_FD_APPS); + } free(ust_cmd); } @@ -1488,13 +1507,6 @@ static void *thread_dispatch_ust_registration(void *data) rcu_read_unlock(); session_unlock_list(); - } else { - /* Application manager threads are not available. */ - ret = close(ust_cmd->sock); - if (ret < 0) { - PERROR("close ust_cmd sock"); - } - lttng_fd_put(1, LTTNG_FD_APPS); } } while (node != NULL); @@ -3097,6 +3109,9 @@ static void *thread_manage_health(void *data) rcu_register_thread(); + /* We might hit an error path before this is created. */ + lttng_poll_init(&events); + /* Create unix socket */ sock = lttcomm_create_unix_sock(health_unix_sock_path); if (sock < 0) { @@ -3211,13 +3226,17 @@ restart: case LTTNG_HEALTH_CONSUMER: reply.ret_code = check_consumer_health(); break; + case LTTNG_HEALTH_HT_CLEANUP: + reply.ret_code = health_check_state(HEALTH_TYPE_HT_CLEANUP); + break; case LTTNG_HEALTH_ALL: reply.ret_code = health_check_state(HEALTH_TYPE_APP_MANAGE) && health_check_state(HEALTH_TYPE_APP_REG) && health_check_state(HEALTH_TYPE_CMD) && health_check_state(HEALTH_TYPE_KERNEL) && - check_consumer_health(); + check_consumer_health() && + health_check_state(HEALTH_TYPE_HT_CLEANUP); break; default: reply.ret_code = LTTNG_ERR_UND; @@ -3262,12 +3281,6 @@ error: PERROR("close"); } } - if (new_sock >= 0) { - ret = close(new_sock); - if (ret) { - PERROR("close"); - } - } lttng_poll_clean(&events); @@ -3449,13 +3462,11 @@ static void *thread_manage_clients(void *data) ret = process_client_msg(cmd_ctx, sock, &sock_error); rcu_thread_offline(); if (ret < 0) { - if (sock_error) { - ret = close(sock); - if (ret) { - PERROR("close"); - } - sock = -1; + ret = close(sock); + if (ret) { + PERROR("close"); } + sock = -1; /* * TODO: Inform client somehow of the fatal error. At * this point, ret < 0 means that a zmalloc failed @@ -4287,6 +4298,11 @@ int main(int argc, char **argv) } } + /* Setup the thread ht_cleanup communication pipe. */ + if (utils_create_pipe_cloexec(ht_cleanup_pipe) < 0) { + goto exit; + } + /* Setup the thread apps communication pipe. */ if ((ret = utils_create_pipe_cloexec(apps_cmd_pipe)) < 0) { goto exit; @@ -4325,6 +4341,14 @@ int main(int argc, char **argv) write_pidfile(); + /* Create thread to manage the client socket */ + ret = pthread_create(&ht_cleanup_thread, NULL, + thread_ht_cleanup, (void *) NULL); + if (ret != 0) { + PERROR("pthread_create ht_cleanup"); + goto exit_ht_cleanup; + } + /* Create thread to manage the client socket */ ret = pthread_create(&health_thread, NULL, thread_manage_health, (void *) NULL); @@ -4444,6 +4468,12 @@ exit_client: } exit_health: + ret = pthread_join(ht_cleanup_thread, &status); + if (ret != 0) { + PERROR("pthread_join ht cleanup thread"); + goto error; /* join error, exit without cleanup */ + } +exit_ht_cleanup: exit: /* * cleanup() is called when no other thread is running.