X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fhealth.c;h=9ff6bd1ae1013d9b86e5e178f920ff7286e63114;hb=a5a309207b81778262744a9de568f6d7c54996e2;hp=e2b8cc5a3e1b3794b75299737f064e9ac3fff220;hpb=173fca4fb73279d919e1738b61e007231f43d519;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/health.c b/src/bin/lttng-sessiond/health.c index e2b8cc5a3..9ff6bd1ae 100644 --- a/src/bin/lttng-sessiond/health.c +++ b/src/bin/lttng-sessiond/health.c @@ -27,17 +27,39 @@ #include "utils.h" #include "thread.h" -static void cleanup_health_management_thread(void *thread_data) +struct thread_notifiers { + struct lttng_pipe *quit_pipe; + sem_t ready; +}; + +static +void mark_thread_as_ready(struct thread_notifiers *notifiers) +{ + DBG("Marking health management thread as ready"); + sem_post(¬ifiers->ready); +} + +static +void wait_until_thread_is_ready(struct thread_notifiers *notifiers) +{ + DBG("Waiting for health management thread to be ready"); + sem_wait(¬ifiers->ready); + DBG("Health management thread is ready"); +} + +static void cleanup_health_management_thread(void *data) { - struct lttng_pipe *quit_pipe = thread_data; + struct thread_notifiers *notifiers = data; - lttng_pipe_destroy(quit_pipe); + lttng_pipe_destroy(notifiers->quit_pipe); + sem_destroy(¬ifiers->ready); + free(notifiers); } /* * Thread managing health check socket. */ -static void *thread_manage_health(void *thread_data) +static void *thread_manage_health(void *data) { const bool is_root = (getuid() == 0); int sock = -1, new_sock = -1, ret, i, pollfd, err = -1; @@ -46,8 +68,9 @@ static void *thread_manage_health(void *thread_data) struct health_comm_msg msg; struct health_comm_reply reply; /* Thread-specific quit pipe. */ - struct lttng_pipe *quit_pipe = thread_data; - const int quit_pipe_read_fd = lttng_pipe_get_readfd(quit_pipe); + struct thread_notifiers *notifiers = data; + const int quit_pipe_read_fd = lttng_pipe_get_readfd( + notifiers->quit_pipe); DBG("[thread] Manage health check started"); @@ -72,8 +95,15 @@ static void *thread_manage_health(void *thread_data) if (is_root) { /* lttng health client socket path permissions */ - ret = chown(config.health_unix_sock_path.value, 0, - utils_get_group_id(config.tracing_group_name.value)); + gid_t gid; + + ret = utils_get_group_id(config.tracing_group_name.value, true, &gid); + if (ret) { + /* Default to root group. */ + gid = 0; + } + + ret = chown(config.health_unix_sock_path.value, 0, gid); if (ret < 0) { ERR("Unable to set group on %s", config.health_unix_sock_path.value); PERROR("chown"); @@ -111,8 +141,7 @@ static void *thread_manage_health(void *thread_data) goto error; } - sessiond_notify_ready(); - + mark_thread_as_ready(notifiers); while (1) { DBG("Health check ready"); @@ -136,11 +165,6 @@ restart: revents = LTTNG_POLL_GETEV(&events, i); pollfd = LTTNG_POLL_GETFD(&events, i); - if (!revents) { - /* No activity for this FD (poll implementation). */ - continue; - } - /* Event on the registration socket */ if (pollfd == sock) { if (revents & LPOLLIN) { @@ -228,44 +252,43 @@ error: return NULL; } -static bool shutdown_health_management_thread(void *thread_data) +static bool shutdown_health_management_thread(void *data) { - int ret; - int pipe_write_fd; - struct lttng_pipe *health_quit_pipe = thread_data; + struct thread_notifiers *notifiers = data; + const int write_fd = lttng_pipe_get_writefd(notifiers->quit_pipe); - pipe_write_fd = lttng_pipe_get_writefd(health_quit_pipe); - ret = notify_thread_pipe(pipe_write_fd); - if (ret < 0) { - ERR("Failed to notify Health management thread's quit pipe"); - goto error; - } - return true; -error: - return false; + return notify_thread_pipe(write_fd) == 1; } bool launch_health_management_thread(void) { + struct thread_notifiers *notifiers; struct lttng_thread *thread; - struct lttng_pipe *health_quit_pipe = NULL; - health_quit_pipe = lttng_pipe_open(FD_CLOEXEC); - if (!health_quit_pipe) { - goto error; + notifiers = zmalloc(sizeof(*notifiers)); + if (!notifiers) { + goto error_alloc; } + sem_init(¬ifiers->ready, 0, 0); + notifiers->quit_pipe = lttng_pipe_open(FD_CLOEXEC); + if (!notifiers->quit_pipe) { + goto error; + } thread = lttng_thread_create("Health management", thread_manage_health, shutdown_health_management_thread, cleanup_health_management_thread, - health_quit_pipe); + notifiers); if (!thread) { goto error; } + + wait_until_thread_is_ready(notifiers); lttng_thread_put(thread); return true; error: - cleanup_health_management_thread(health_quit_pipe); + cleanup_health_management_thread(notifiers); +error_alloc: return false; }