- for (i = 0; i < 2; i++) {
- ret = pthread_join(threads[i], &status);
- if (ret != 0) {
- perror("pthread_join");
- goto error;
+ /* Create the thread to manage the reception of fds */
+ ret = pthread_create(&sessiond_thread, default_pthread_attr(),
+ consumer_thread_sessiond_poll,
+ (void *) ctx);
+ if (ret) {
+ errno = ret;
+ PERROR("pthread_create");
+ retval = -1;
+ goto exit_sessiond_thread;
+ }
+
+ /*
+ * Create the thread to manage the UST metadata periodic timer and
+ * live timer.
+ */
+ ret = pthread_create(&metadata_timer_thread, default_pthread_attr(),
+ consumer_timer_thread, (void *) ctx);
+ if (ret) {
+ errno = ret;
+ PERROR("pthread_create");
+ retval = -1;
+ goto exit_metadata_timer_thread;
+ }
+
+ ret = pthread_detach(metadata_timer_thread);
+ if (ret) {
+ errno = ret;
+ PERROR("pthread_detach");
+ retval = -1;
+ goto exit_metadata_timer_detach;
+ }
+
+ /*
+ * This is where we start awaiting program completion (e.g. through
+ * signal that asks threads to teardown.
+ */
+
+exit_metadata_timer_detach:
+exit_metadata_timer_thread:
+ ret = pthread_join(sessiond_thread, &status);
+ if (ret) {
+ errno = ret;
+ PERROR("pthread_join sessiond_thread");
+ retval = -1;
+ }
+
+ ret = consumer_timer_thread_get_channel_monitor_pipe();
+ if (ret >= 0) {
+ ret = close(ret);
+ if (ret) {
+ PERROR("close channel monitor pipe");