X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=e9529f1bf9378dc46bb3ddeaa250b10fafaef249;hb=785d2d0dc3aec3a4e44fcf677155dd07e8e4cc1f;hp=859223a11216b1d342b0899ebdd4e66bc657d657;hpb=840cb59cfc335e2ca44841f6fd57972ac3a623be;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 859223a11..e9529f1bf 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -664,14 +664,13 @@ error: } /* - * For each tracing session, update newly registered apps. + * For each tracing session, update newly registered apps. The session list + * lock MUST be acquired before calling this. */ static void update_ust_app(int app_sock) { struct ltt_session *sess, *stmp; - session_lock_list(); - /* For all tracing session(s) */ cds_list_for_each_entry_safe(sess, stmp, &session_list_ptr->head, list) { session_lock(sess); @@ -680,8 +679,6 @@ static void update_ust_app(int app_sock) } session_unlock(sess); } - - session_unlock_list(); } /* @@ -746,9 +743,9 @@ static void *thread_manage_kernel(void *data) /* Poll infinite value of time */ restart: - health_poll_update(); + health_poll_entry(); ret = lttng_poll_wait(&events, -1); - health_poll_update(); + health_poll_exit(); if (ret < 0) { /* * Restart interrupted system call. @@ -867,24 +864,7 @@ static void *thread_manage_consumer(void *data) health_register(HEALTH_TYPE_CONSUMER); - /* - * Since the consumer thread can be spawned at any moment in time, we init - * the health to a poll status (1, which is a valid health over time). - * When the thread starts, we update here the health to a "code" path being - * an even value so this thread, when reaching a poll wait, does not - * trigger an error with an even value. - * - * Here is the use case we avoid. - * - * +1: the first poll update during initialization (main()) - * +2 * x: multiple code update once in this thread. - * +1: poll wait in this thread (being a good health state). - * == even number which after the wait period shows as a bad health. - * - * In a nutshell, the following poll update to the health state brings back - * the state to an even value meaning a code path. - */ - health_poll_update(); + health_code_update(); /* * Pass 2 as size here for the thread quit pipe and kconsumerd_err_sock. @@ -909,14 +889,14 @@ static void *thread_manage_consumer(void *data) /* Inifinite blocking call, waiting for transmission */ restart: - health_poll_update(); + health_poll_entry(); if (testpoint(thread_manage_consumer)) { goto error; } ret = lttng_poll_wait(&events, -1); - health_poll_update(); + health_poll_exit(); if (ret < 0) { /* * Restart interrupted system call. @@ -1008,9 +988,9 @@ restart: /* Inifinite blocking call, waiting for transmission */ restart_poll: - health_poll_update(); + health_poll_entry(); ret = lttng_poll_wait(&events, -1); - health_poll_update(); + health_poll_exit(); if (ret < 0) { /* * Restart interrupted system call. @@ -1150,9 +1130,9 @@ static void *thread_manage_apps(void *data) /* Inifinite blocking call, waiting for transmission */ restart: - health_poll_update(); + health_poll_entry(); ret = lttng_poll_wait(&events, -1); - health_poll_update(); + health_poll_exit(); if (ret < 0) { /* * Restart interrupted system call. @@ -1196,12 +1176,22 @@ static void *thread_manage_apps(void *data) health_code_update(); + /* + * @session_lock + * Lock the global session list so from the register up to + * the registration done message, no thread can see the + * application and change its state. + */ + session_lock_list(); + /* Register applicaton to the session daemon */ ret = ust_app_register(&ust_cmd.reg_msg, ust_cmd.sock); if (ret == -ENOMEM) { + session_unlock_list(); goto error; } else if (ret < 0) { + session_unlock_list(); break; } @@ -1237,6 +1227,7 @@ static void *thread_manage_apps(void *data) ret = lttng_poll_add(&events, ust_cmd.sock, LPOLLERR & LPOLLHUP & LPOLLRDHUP); if (ret < 0) { + session_unlock_list(); goto error; } @@ -1249,6 +1240,7 @@ static void *thread_manage_apps(void *data) DBG("Apps with sock %d added to poll set", ust_cmd.sock); } + session_unlock_list(); health_code_update(); @@ -1430,9 +1422,9 @@ static void *thread_registration_apps(void *data) /* Inifinite blocking call, waiting for transmission */ restart: - health_poll_update(); + health_poll_entry(); ret = lttng_poll_wait(&events, -1); - health_poll_update(); + health_poll_exit(); if (ret < 0) { /* * Restart interrupted system call. @@ -2351,8 +2343,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, /* Start the kernel consumer daemon */ pthread_mutex_lock(&kconsumer_data.pid_mutex); if (kconsumer_data.pid == 0 && - cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER && - cmd_ctx->session->start_consumer) { + cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) { pthread_mutex_unlock(&kconsumer_data.pid_mutex); ret = start_consumerd(&kconsumer_data); if (ret < 0) { @@ -2399,8 +2390,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, pthread_mutex_lock(&ustconsumer64_data.pid_mutex); if (consumerd64_bin[0] != '\0' && ustconsumer64_data.pid == 0 && - cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER && - cmd_ctx->session->start_consumer) { + cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) { pthread_mutex_unlock(&ustconsumer64_data.pid_mutex); ret = start_consumerd(&ustconsumer64_data); if (ret < 0) { @@ -2428,8 +2418,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, /* 32-bit */ if (consumerd32_bin[0] != '\0' && ustconsumer32_data.pid == 0 && - cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER && - cmd_ctx->session->start_consumer) { + cmd_ctx->lsm->cmd_type != LTTNG_REGISTER_CONSUMER) { pthread_mutex_unlock(&ustconsumer32_data.pid_mutex); ret = start_consumerd(&ustconsumer32_data); if (ret < 0) { @@ -2493,6 +2482,21 @@ skip_domain: } } + /* + * Send relayd information to consumer as soon as we have a domain and a + * session defined. + */ + if (cmd_ctx->session && need_domain) { + /* + * Setup relayd if not done yet. If the relayd information was already + * sent to the consumer, this call will gracefully return. + */ + ret = cmd_setup_relayd(cmd_ctx->session); + if (ret != LTTNG_OK) { + goto error; + } + } + /* Process by command type */ switch (cmd_ctx->lsm->cmd_type) { case LTTNG_ADD_CONTEXT: @@ -2523,41 +2527,12 @@ skip_domain: cmd_ctx->lsm->u.disable.channel_name); break; } - case LTTNG_DISABLE_CONSUMER: - { - ret = cmd_disable_consumer(cmd_ctx->lsm->domain.type, cmd_ctx->session); - break; - } case LTTNG_ENABLE_CHANNEL: { ret = cmd_enable_channel(cmd_ctx->session, cmd_ctx->lsm->domain.type, &cmd_ctx->lsm->u.channel.chan, kernel_poll_pipe[1]); break; } - case LTTNG_ENABLE_CONSUMER: - { - /* - * XXX: 0 means that this URI should be applied on the session. Should - * be a DOMAIN enuam. - */ - ret = cmd_enable_consumer(cmd_ctx->lsm->domain.type, cmd_ctx->session); - if (ret != LTTNG_OK) { - goto error; - } - - if (cmd_ctx->lsm->domain.type == 0) { - /* Add the URI for the UST session if a consumer is present. */ - if (cmd_ctx->session->ust_session && - cmd_ctx->session->ust_session->consumer) { - ret = cmd_enable_consumer(LTTNG_DOMAIN_UST, cmd_ctx->session); - } else if (cmd_ctx->session->kernel_session && - cmd_ctx->session->kernel_session->consumer) { - ret = cmd_enable_consumer(LTTNG_DOMAIN_KERNEL, - cmd_ctx->session); - } - } - break; - } case LTTNG_ENABLE_EVENT: { ret = cmd_enable_event(cmd_ctx->session, cmd_ctx->lsm->domain.type, @@ -3208,9 +3183,9 @@ static void *thread_manage_clients(void *data) /* Inifinite blocking call, waiting for transmission */ restart: - health_poll_update(); + health_poll_entry(); ret = lttng_poll_wait(&events, -1); - health_poll_update(); + health_poll_exit(); if (ret < 0) { /* * Restart interrupted system call.