+static const char *default_reg_uri =
+ "tcp://" DEFAULT_NETWORK_VIEWER_BIND_ADDRESS;
+
+/*
+ * Update JUL application using the given socket. This is done just after
+ * registration was successful.
+ *
+ * This is a quite heavy call in terms of locking since the session list lock
+ * AND session lock are acquired.
+ */
+static void update_jul_app(int sock)
+{
+ struct ltt_session *session, *stmp;
+ struct ltt_session_list *list;
+
+ list = session_get_list();
+ assert(list);
+
+ session_lock_list();
+ cds_list_for_each_entry_safe(session, stmp, &list->head, list) {
+ session_lock(session);
+ if (session->ust_session) {
+ jul_update(&session->ust_session->domain_jul, sock);
+ }
+ session_unlock(session);
+ }
+ session_unlock_list();
+}
+
+/*
+ * Destroy a JUL application by socket.
+ */
+static void destroy_jul_app(int sock)
+{
+ struct jul_app *app;
+
+ assert(sock >= 0);
+
+ /*
+ * Not finding an application is a very important error that should NEVER
+ * happen. The hash table deletion is ONLY done through this call even on
+ * thread cleanup.
+ */
+ rcu_read_lock();
+ app = jul_find_app_by_sock(sock);
+ assert(app);
+ rcu_read_unlock();
+
+ /* RCU read side lock is taken in this function call. */
+ jul_delete_app(app);
+
+ /* The application is freed in a RCU call but the socket is closed here. */
+ jul_destroy_app(app);
+}
+
+/*
+ * Cleanup remaining JUL apps in the hash table. This should only be called in
+ * the exit path of the thread.
+ */
+static void clean_jul_apps_ht(void)
+{
+ struct lttng_ht_node_ulong *node;
+ struct lttng_ht_iter iter;
+
+ DBG3("[jul-thread] Cleaning JUL apps ht");
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(jul_apps_ht_by_sock->ht, &iter.iter, node, node) {
+ struct jul_app *app;
+
+ app = caa_container_of(node, struct jul_app, node);
+ destroy_jul_app(app->sock->fd);
+ }
+ rcu_read_unlock();
+}