+static int init_pipe(int *pipe_fds)
+{
+ int ret, i;
+
+ ret = pipe(pipe_fds);
+ if (ret < 0) {
+ PERROR("ht_cleanup thread quit pipe");
+ goto error;
+ }
+
+ for (i = 0; i < 2; i++) {
+ ret = fcntl(pipe_fds[i], F_SETFD, FD_CLOEXEC);
+ if (ret < 0) {
+ PERROR("fcntl ht_cleanup_quit_pipe");
+ goto error;
+ }
+ }
+error:
+ return ret;
+}
+
+/*
+ * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
+ */
+static int set_pollset(struct lttng_poll_event *events, size_t size)
+{
+ int ret;
+
+ ret = lttng_poll_create(events, size, LTTNG_CLOEXEC);
+ if (ret < 0) {
+ goto error;
+ }
+
+ ret = lttng_poll_add(events, ht_cleanup_quit_pipe[0],
+ LPOLLIN | LPOLLERR);
+ if (ret < 0) {
+ goto error;
+ }
+
+ ret = lttng_poll_add(events, ht_cleanup_pipe[0], LPOLLIN | LPOLLERR);
+ if (ret < 0) {
+ DBG("[ht-thread] lttng_poll_add error %d.", ret);
+ goto error;
+ }
+
+ return 0;
+
+error:
+ return ret;
+}
+
+static void cleanup_ht_cleanup_thread(void *data)
+{
+ utils_close_pipe(ht_cleanup_quit_pipe);
+ utils_close_pipe(ht_cleanup_pipe);
+}
+
+static void *thread_ht_cleanup(void *data)