Remove enable/disable consumer obsolete command
[lttng-tools.git] / src / bin / lttng-sessiond / event.c
index 52fd9f5478a753492eb9ffee7b0c6d8eaf18d5e4..59b591de9d5e454add9567a8f07636c123f0d6ca 100644 (file)
@@ -710,6 +710,34 @@ error:
        return ret;
 }
 
+/*
+ * Return the agent default event name to use by testing if the process is root
+ * or not. Return NULL on error.
+ */
+const char *event_get_default_agent_ust_name(enum lttng_domain_type domain)
+{
+       const char *default_event_name = NULL;
+
+       if (domain == LTTNG_DOMAIN_JUL) {
+               if (is_root) {
+                       default_event_name = DEFAULT_SYS_JUL_EVENT_NAME;
+               } else {
+                       default_event_name = DEFAULT_USER_JUL_EVENT_NAME;
+               }
+       } else if (domain == LTTNG_DOMAIN_LOG4J) {
+               if (is_root) {
+                       default_event_name = DEFAULT_SYS_LOG4J_EVENT_NAME;
+               } else {
+                       default_event_name = DEFAULT_USER_LOG4J_EVENT_NAME;
+               }
+       } else {
+               assert(0);
+       }
+
+       return default_event_name;
+}
+
+
 /*
  * Disable a single agent event for a given UST session.
  *
@@ -722,7 +750,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
        struct agent_event *aevent;
        struct ltt_ust_event *uevent = NULL;
        struct ltt_ust_channel *uchan = NULL;
-       char *ust_event_name;
+       const char *ust_event_name;
 
        assert(agt);
        assert(usess);
@@ -752,10 +780,10 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
                goto error;
        }
 
-       if (is_root) {
-               ust_event_name = DEFAULT_SYS_JUL_EVENT_NAME;
-       } else {
-               ust_event_name = DEFAULT_USER_JUL_EVENT_NAME;
+       ust_event_name = event_get_default_agent_ust_name(agt->domain);
+       if (!ust_event_name) {
+               ret = LTTNG_ERR_FATAL;
+               goto error;
        }
 
        /*
@@ -763,7 +791,7 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
         * with the loglevel type to ALL thus the loglevel stays 0. The event's
         * filter is the one handling the loglevel for agent.
         */
-       uevent = trace_ust_find_event(uchan->events, ust_event_name,
+       uevent = trace_ust_find_event(uchan->events, (char *) ust_event_name,
                        aevent->filter, 0, NULL);
        /* If the agent event exists, it must be available on the UST side. */
        assert(uevent);
@@ -774,6 +802,12 @@ int event_agent_disable(struct ltt_ust_session *usess, struct agent *agt,
                goto error;
        }
 
+       /*
+        * Flag event that it's disabled so the shadow copy on the ust app side
+        * will disable it if an application shows up.
+        */
+       uevent->enabled = 0;
+
        ret = agent_disable_event(aevent, agt->domain);
        if (ret != LTTNG_OK) {
                goto error;
@@ -793,40 +827,35 @@ error:
 int event_agent_disable_all(struct ltt_ust_session *usess,
                struct agent *agt)
 {
-       int ret, do_disable = 0;
+       int ret;
        struct agent_event *aevent;
        struct lttng_ht_iter iter;
 
        assert(agt);
        assert(usess);
 
-       /* Disable event on agent application through TCP socket. */
+       /*
+        * Disable event on agent application. Continue to disable all other events
+        * if the * event is not found.
+        */
        ret = event_agent_disable(usess, agt, "*");
-       if (ret != LTTNG_OK) {
-               if (ret == LTTNG_ERR_UST_EVENT_NOT_FOUND) {
-                       /*
-                        * This means that no enable all was done before but still a user
-                        * could want to disable everything even though the * wild card
-                        * event does not exists.
-                        */
-                       do_disable = 1;
-               } else {
-                       goto error;
-               }
+       if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_NOT_FOUND) {
+               goto error;
        }
 
        /* Flag every event that they are now enabled. */
        rcu_read_lock();
        cds_lfht_for_each_entry(agt->events->ht, &iter.iter, aevent,
                        node.node) {
-               if (aevent->enabled && do_disable) {
-                       ret = event_agent_disable(usess, agt, aevent->name);
-                       if (ret != LTTNG_OK) {
-                               rcu_read_unlock();
-                               goto error;
-                       }
+               if (!aevent->enabled) {
+                       continue;
+               }
+
+               ret = event_agent_disable(usess, agt, aevent->name);
+               if (ret != LTTNG_OK) {
+                       rcu_read_unlock();
+                       goto error;
                }
-               aevent->enabled = 0;
        }
        rcu_read_unlock();
 
This page took 0.03321 seconds and 5 git commands to generate.