+ health_code_update(&health_thread_cmd);
+
+ if (!app->compatible) {
+ /*
+ * TODO: In time, we should notice the caller of this error by
+ * telling him that this is a version error.
+ */
+ continue;
+ }
+ handle = ustctl_tracepoint_field_list(app->sock);
+ if (handle < 0) {
+ ERR("UST app list event fields getting handle failed for app pid %d",
+ app->pid);
+ continue;
+ }
+
+ while ((ret = ustctl_tracepoint_field_list_get(app->sock, handle,
+ &uiter)) != -LTTNG_UST_ERR_NOENT) {
+ health_code_update(&health_thread_cmd);
+ if (count >= nbmem) {
+ /* In case the realloc fails, we free the memory */
+ void *ptr;
+
+ DBG2("Reallocating event field list from %zu to %zu entries", nbmem,
+ 2 * nbmem);
+ nbmem *= 2;
+ ptr = realloc(tmp_event, nbmem * sizeof(struct lttng_event_field));
+ if (ptr == NULL) {
+ PERROR("realloc ust app event fields");
+ free(tmp_event);
+ ret = -ENOMEM;
+ goto rcu_error;
+ }
+ tmp_event = ptr;
+ }
+
+ memcpy(tmp_event[count].field_name, uiter.field_name, LTTNG_UST_SYM_NAME_LEN);
+ tmp_event[count].type = uiter.type;
+ tmp_event[count].nowrite = uiter.nowrite;
+
+ memcpy(tmp_event[count].event.name, uiter.event_name, LTTNG_UST_SYM_NAME_LEN);
+ tmp_event[count].event.loglevel = uiter.loglevel;
+ tmp_event[count].event.type = LTTNG_UST_TRACEPOINT;
+ tmp_event[count].event.pid = app->pid;
+ tmp_event[count].event.enabled = -1;
+ count++;
+ }
+ }
+
+ ret = count;
+ *fields = tmp_event;
+
+ DBG2("UST app list event fields done (%zu events)", count);
+
+rcu_error:
+ rcu_read_unlock();
+error:
+ health_code_update(&health_thread_cmd);
+ return ret;
+}
+
+/*
+ * Free and clean all traceable apps of the global list.
+ */
+void ust_app_clean_list(void)
+{
+ int ret;
+ struct ust_app *app;
+ struct lttng_ht_iter iter;
+
+ DBG2("UST app cleaning registered apps hash table");
+
+ rcu_read_lock();
+
+ cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
+ ret = lttng_ht_del(ust_app_ht, &iter);
+ assert(!ret);
+ call_rcu(&app->pid_n.head, delete_ust_app_rcu);
+ }
+
+ /* Cleanup socket hash table */
+ cds_lfht_for_each_entry(ust_app_ht_by_sock->ht, &iter.iter, app,
+ sock_n.node) {
+ ret = lttng_ht_del(ust_app_ht_by_sock, &iter);
+ assert(!ret);
+ }
+
+ /* Destroy is done only when the ht is empty */
+ lttng_ht_destroy(ust_app_ht);
+ lttng_ht_destroy(ust_app_ht_by_sock);