+ struct lttng_ust_tracepoint_iter iter;
+
+ handle = ustctl_tracepoint_list(app->key.sock);
+ if (handle < 0) {
+ ERR("UST app list events getting handle failed for app pid %d",
+ app->key.pid);
+ continue;
+ }
+
+ while ((ret = ustctl_tracepoint_list_get(app->key.sock, handle,
+ &iter)) != -ENOENT) {
+ memcpy(tmp[count].name, iter.name, LTTNG_UST_SYM_NAME_LEN);
+ /* TODO : get loglevel too */
+ if (count > nbmem) {
+ DBG2("Reallocating event list from %zu to %zu bytes", nbmem,
+ nbmem + UST_APP_EVENT_LIST_SIZE);
+ nbmem += UST_APP_EVENT_LIST_SIZE;
+ tmp = realloc(tmp, nbmem * sizeof(struct lttng_event));
+ if (tmp == NULL) {
+ PERROR("realloc ust app events");
+ ret = -ENOMEM;
+ goto rcu_error;
+ }
+ }
+
+ tmp[count].type = LTTNG_UST_TRACEPOINT;
+ tmp[count].pid = app->key.pid;
+ tmp[count].enabled = -1;
+ count++;
+ }
+ }
+
+ ret = count;
+ *events = tmp;
+
+ DBG2("UST app list events done (%zu events)", count);
+
+rcu_error:
+ rcu_read_unlock();
+error:
+ return ret;
+}
+
+/*
+ * Free and clean all traceable apps of the global list.
+ */
+void ust_app_clean_list(void)
+{
+ int ret;
+ struct cds_lfht_iter iter;
+ struct ust_app *app;
+
+ DBG2("UST app cleaning registered apps hash table");
+
+ rcu_read_lock();
+
+ cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
+ ret = hashtable_del(ust_app_ht, &iter);
+ assert(!ret);
+ call_rcu(&iter.node->head, delete_ust_app_rcu);
+ }
+
+ hashtable_destroy(ust_app_ht);
+ hashtable_destroy(ust_app_sock_key_map);
+
+ rcu_read_unlock();
+}
+
+/*
+ * Init UST app hash table.
+ */
+void ust_app_ht_alloc(void)
+{
+ ust_app_ht = hashtable_new(0);
+ ust_app_sock_key_map = hashtable_new(0);
+}
+
+/*
+ * For a specific UST session, disable the channel for all registered apps.
+ */
+int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
+ struct ltt_ust_channel *uchan)
+{
+ int ret = 0;
+ struct cds_lfht_iter iter;
+ struct cds_lfht_node *ua_chan_node;
+ struct ust_app *app;
+ struct ust_app_session *ua_sess;
+ struct ust_app_channel *ua_chan;
+
+ if (usess == NULL || uchan == NULL) {
+ ERR("Disabling UST global channel with NULL values");
+ ret = -1;
+ goto error;
+ }
+
+ DBG2("UST app disabling channel %s from global domain for session uid %d",
+ uchan->name, usess->uid);
+
+ rcu_read_lock();
+
+ /* For every registered applications */
+ cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
+ ua_sess = lookup_session_by_app(usess, app);
+ if (ua_sess == NULL) {
+ continue;
+ }
+
+ /* Get channel */
+ ua_chan_node = hashtable_lookup(ua_sess->channels,
+ (void *)uchan->name, strlen(uchan->name), &iter);
+ /* If the session if found for the app, the channel must be there */
+ assert(ua_chan_node);
+
+ ua_chan = caa_container_of(ua_chan_node, struct ust_app_channel, node);
+ /* The channel must not be already disabled */
+ assert(ua_chan->enabled == 1);
+
+ /* Disable channel onto application */
+ ret = disable_ust_app_channel(ua_sess, ua_chan, app);
+ if (ret < 0) {
+ /* XXX: We might want to report this error at some point... */
+ continue;
+ }
+ }
+
+ rcu_read_unlock();
+
+error:
+ return ret;
+}
+
+/*
+ * For a specific UST session, enable the channel for all registered apps.
+ */
+int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
+ struct ltt_ust_channel *uchan)
+{
+ int ret = 0;
+ struct cds_lfht_iter iter;
+ struct ust_app *app;
+ struct ust_app_session *ua_sess;
+
+ if (usess == NULL || uchan == NULL) {
+ ERR("Adding UST global channel to NULL values");
+ ret = -1;
+ goto error;
+ }
+
+ DBG2("UST app enabling channel %s to global domain for session uid %d",
+ uchan->name, usess->uid);
+
+ rcu_read_lock();
+
+ /* For every registered applications */
+ cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
+ ua_sess = lookup_session_by_app(usess, app);
+ if (ua_sess == NULL) {
+ continue;
+ }
+
+ /* Enable channel onto application */
+ ret = enable_ust_app_channel(ua_sess, uchan, app);
+ if (ret < 0) {
+ /* XXX: We might want to report this error at some point... */
+ continue;
+ }
+ }
+
+ rcu_read_unlock();
+
+error:
+ return ret;
+}
+
+/*
+ * Disable an event in a channel and for a specific session.
+ */
+int ust_app_disable_event_glb(struct ltt_ust_session *usess,
+ struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
+{
+ int ret = 0;
+ struct cds_lfht_iter iter, uiter;
+ struct cds_lfht_node *ua_chan_node, *ua_event_node;
+ struct ust_app *app;
+ struct ust_app_session *ua_sess;
+ struct ust_app_channel *ua_chan;
+ struct ust_app_event *ua_event;
+
+ DBG("UST app disabling event %s for all apps in channel "
+ "%s for session uid %d", uevent->attr.name, uchan->name, usess->uid);
+
+ rcu_read_lock();
+
+ /* For all registered applications */
+ cds_lfht_for_each_entry(ust_app_ht, &iter, app, node) {
+ ua_sess = lookup_session_by_app(usess, app);
+ if (ua_sess == NULL) {
+ /* Next app */