+
+/*
+ * Sample the id of a session looked up via its name.
+ * Here the term "sampling" hint the caller that this return the id at a given
+ * point in time with no guarantee that the session for which the id was
+ * sampled still exist at that point.
+ *
+ * Return 0 when the session is not found,
+ * Return 1 when the session is found and set `id`.
+ */
+bool sample_session_id_by_name(const char *name, uint64_t *id)
+{
+ bool found = false;
+ struct lttng_ht_node_str *node;
+ struct lttng_ht_iter iter;
+ struct ltt_session *ls;
+
+ rcu_read_lock();
+
+ if (!ltt_sessions_ht_by_name) {
+ found = false;
+ goto end;
+ }
+
+ lttng_ht_lookup(ltt_sessions_ht_by_name, name, &iter);
+ node = lttng_ht_iter_get_node_str(&iter);
+ if (node == NULL) {
+ found = false;
+ goto end;
+ }
+
+ ls = caa_container_of(node, struct ltt_session, node_by_name);
+ *id = ls->id;
+ found = true;
+
+ DBG3("Session id `%" PRIu64 "` sampled for session `%s", *id, name);
+end:
+ rcu_read_unlock();
+ return found;
+}