Fix: deny overwrite mode and num subbuf less than 2
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 5bf00be8536f12cb124fd0d828486344b75734b7..8ee641d8e07726b7826572fb19a745cef76514f1 100644 (file)
@@ -458,6 +458,7 @@ static int add_uri_to_consumer(struct consumer_output *consumer,
                         * URI was the same in the consumer so we do not append the subdir
                         * again so to not duplicate output dir.
                         */
+                       ret = LTTNG_OK;
                        goto error;
                }
 
@@ -930,6 +931,16 @@ int cmd_enable_channel(struct ltt_session *session,
                attr->attr.switch_timer_interval = 0;
        }
 
+       /*
+        * The ringbuffer (both in user space and kernel) behave badly in overwrite
+        * mode and with less than 2 subbuf so block it right away and send back an
+        * invalid attribute error.
+        */
+       if (attr->attr.overwrite && attr->attr.num_subbuf < 2) {
+               ret = LTTNG_ERR_INVALID;
+               goto error;
+       }
+
        switch (domain->type) {
        case LTTNG_DOMAIN_KERNEL:
        {
@@ -1442,7 +1453,13 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                memset(&uevent, 0, sizeof(uevent));
                uevent.type = LTTNG_EVENT_TRACEPOINT;
                uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
-               strncpy(uevent.name, DEFAULT_JUL_EVENT_NAME, sizeof(uevent.name));
+               if (is_root) {
+                       strncpy(uevent.name, DEFAULT_SYS_JUL_EVENT_NAME,
+                                       sizeof(uevent.name));
+               } else {
+                       strncpy(uevent.name, DEFAULT_USER_JUL_EVENT_NAME,
+                                       sizeof(uevent.name));
+               }
                uevent.name[sizeof(uevent.name) - 1] = '\0';
 
                /*
@@ -1454,7 +1471,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                tmp_dom.type = LTTNG_DOMAIN_UST;
 
                ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
-                               &uevent, NULL, NULL, wpipe);
+                               &uevent, filter, NULL, wpipe);
                if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
                        goto error;
                }
@@ -1654,7 +1671,13 @@ int cmd_enable_event_all(struct ltt_session *session,
                /* Create the default JUL tracepoint. */
                uevent.type = LTTNG_EVENT_TRACEPOINT;
                uevent.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
-               strncpy(uevent.name, DEFAULT_JUL_EVENT_NAME, sizeof(uevent.name));
+               if (is_root) {
+                       strncpy(uevent.name, DEFAULT_SYS_JUL_EVENT_NAME,
+                                       sizeof(uevent.name));
+               } else {
+                       strncpy(uevent.name, DEFAULT_USER_JUL_EVENT_NAME,
+                                       sizeof(uevent.name));
+               }
                uevent.name[sizeof(uevent.name) - 1] = '\0';
 
                /*
@@ -2494,6 +2517,7 @@ void cmd_list_lttng_sessions(struct lttng_session *sessions, uid_t uid,
                sessions[i].name[NAME_MAX - 1] = '\0';
                sessions[i].enabled = session->enabled;
                sessions[i].snapshot_mode = session->snapshot_mode;
+               sessions[i].live_timer_interval = session->live_timer;
                i++;
        }
 }
@@ -2514,6 +2538,21 @@ int cmd_data_pending(struct ltt_session *session)
        if (session->enabled) {
                ret = LTTNG_ERR_SESSION_STARTED;
                goto error;
+       } else {
+               /*
+                * If stopped, just make sure we've started before else the above call
+                * will always send that there is data pending.
+                *
+                * The consumer assumes that when the data pending command is received,
+                * the trace has been started before or else no output data is written
+                * by the streams which is a condition for data pending. So, this is
+                * *VERY* important that we don't ask the consumer before a start
+                * trace.
+                */
+               if (!session->started) {
+                       ret = 0;
+                       goto error;
+               }
        }
 
        if (ksess && ksess->consumer) {
This page took 0.026417 seconds and 4 git commands to generate.