+ /*
+ * Set the CLOEXEC flag. Return code is useless because either way, the
+ * show must go on.
+ */
+ (void) utils_set_fd_cloexec(new_sock);
+
+ DBG("Receiving data from client for health...");
+ ret = lttcomm_recv_unix_sock(new_sock, (void *)&msg, sizeof(msg));
+ if (ret <= 0) {
+ DBG("Nothing recv() from client... continuing");
+ ret = close(new_sock);
+ if (ret) {
+ PERROR("close");
+ }
+ continue;
+ }
+
+ rcu_thread_online();
+
+ memset(&reply, 0, sizeof(reply));
+ for (i = 0; i < NR_HEALTH_SESSIOND_TYPES; i++) {
+ /*
+ * health_check_state returns 0 if health is
+ * bad.
+ */
+ if (!health_check_state(health_sessiond, i)) {
+ reply.ret_code |= 1ULL << i;
+ }
+ }
+
+ DBG2("Health check return value %" PRIx64, reply.ret_code);
+
+ ret = lttcomm_send_unix_sock(new_sock, (void *) &reply,
+ sizeof(reply));
+ if (ret < 0) {
+ ERR("Failed to send health data back to client");
+ }
+
+ /* End of transmission */
+ ret = close(new_sock);
+ if (ret) {
+ PERROR("close");
+ }
+ }
+
+exit:
+error:
+ if (err) {
+ ERR("Health error occurred in %s", __func__);
+ }
+ DBG("Health check thread dying");
+ unlink(config.health_unix_sock_path.value);
+ if (sock >= 0) {
+ ret = close(sock);
+ if (ret) {
+ PERROR("close");
+ }
+ }
+
+ lttng_poll_clean(&events);
+ rcu_unregister_thread();
+ return NULL;
+}
+
+static bool shutdown_health_management_thread(void *thread_data)
+{
+ int ret;
+ int pipe_write_fd;
+ struct lttng_pipe *health_quit_pipe = thread_data;
+
+ 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;
+}
+
+bool launch_health_management_thread(void)
+{
+ 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;
+ }
+
+ thread = lttng_thread_create("Health management",
+ thread_manage_health,
+ shutdown_health_management_thread,
+ cleanup_health_management_thread,
+ health_quit_pipe);
+ if (!thread) {
+ goto error;
+ }
+ lttng_thread_put(thread);
+ return true;
+error:
+ cleanup_health_management_thread(health_quit_pipe);
+ return false;