X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fregister.c;h=e809834faa4632b961d19053145b39b23c0f9e9a;hb=df4f5a87a21110a5f9447bcfd7ffeb25098a5fd4;hp=319514a366839460f9e1bbf176fd0f21793a817f;hpb=9c9d917cfe2e6a9f35ef82cb64e442451210716f;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/register.c b/src/bin/lttng-sessiond/register.c index 319514a36..e809834fa 100644 --- a/src/bin/lttng-sessiond/register.c +++ b/src/bin/lttng-sessiond/register.c @@ -38,6 +38,7 @@ struct thread_notifiers { struct lttng_pipe *quit_pipe; struct ust_cmd_queue *ust_cmd_queue; sem_t ready; + bool running; }; /* @@ -114,19 +115,31 @@ static void cleanup_application_registration_thread(void *data) free(notifiers); } -static -void mark_thread_as_ready(struct thread_notifiers *notifiers) +static void set_thread_status(struct thread_notifiers *notifiers, bool running) { - DBG("Marking application registration thread as ready"); + DBG("Marking application registration thread's state as %s", running ? "running" : "error"); + notifiers->running = running; sem_post(¬ifiers->ready); } -static -void wait_until_thread_is_ready(struct thread_notifiers *notifiers) +static bool wait_thread_status(struct thread_notifiers *notifiers) { DBG("Waiting for application registration thread to be ready"); sem_wait(¬ifiers->ready); - DBG("Application registration thread is ready"); + if (notifiers->running) { + DBG("Application registration thread is ready"); + } else { + ERR("Initialization of application registration thread failed"); + } + + return notifiers->running; +} + +static void thread_init_cleanup(void *data) +{ + struct thread_notifiers *notifiers = data; + + set_thread_status(notifiers, false); } /* @@ -150,12 +163,9 @@ static void *thread_application_registration(void *data) DBG("[thread] Manage application registration started"); + pthread_cleanup_push(thread_init_cleanup, NULL); health_register(health_sessiond, HEALTH_SESSIOND_TYPE_APP_REG); - if (testpoint(sessiond_thread_registration_apps)) { - goto error_testpoint; - } - apps_sock = create_application_socket(); if (apps_sock < 0) { goto error_listen; @@ -166,7 +176,12 @@ static void *thread_application_registration(void *data) goto error_listen; } - mark_thread_as_ready(notifiers); + set_thread_status(notifiers, true); + pthread_cleanup_pop(0); + + if (testpoint(sessiond_thread_registration_apps)) { + goto error_create_poll; + } /* * Pass 2 as size here for the thread quit pipe and apps_sock. Nothing @@ -224,11 +239,6 @@ static void *thread_application_registration(void *data) revents = LTTNG_POLL_GETEV(&events, i); pollfd = LTTNG_POLL_GETFD(&events, i); - if (!revents) { - /* No activity for this FD (poll implementation). */ - continue; - } - /* Thread quit pipe has been closed. Killing thread. */ if (pollfd == quit_pipe_read_fd) { err = 0; @@ -361,7 +371,6 @@ error_poll_add: lttng_poll_clean(&events); error_listen: error_create_poll: -error_testpoint: DBG("UST Registration thread cleanup complete"); if (err) { health_error(); @@ -386,13 +395,12 @@ struct lttng_thread *launch_application_registration_thread( struct thread_notifiers *notifiers = NULL; struct lttng_thread *thread; - quit_pipe = lttng_pipe_open(FD_CLOEXEC); - if (!quit_pipe) { - goto error; - } - notifiers = zmalloc(sizeof(*notifiers)); if (!notifiers) { + goto error_alloc; + } + quit_pipe = lttng_pipe_open(FD_CLOEXEC); + if (!quit_pipe) { goto error; } notifiers->quit_pipe = quit_pipe; @@ -407,9 +415,13 @@ struct lttng_thread *launch_application_registration_thread( if (!thread) { goto error; } - wait_until_thread_is_ready(notifiers); + if (!wait_thread_status(notifiers)) { + lttng_thread_put(thread); + thread = NULL; + } return thread; error: cleanup_application_registration_thread(notifiers); +error_alloc: return NULL; }