Fix: don't start session if no channel
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 4343fb114191352dbdaf13ee7a928fc283119c08..5bf00be8536f12cb124fd0d828486344b75734b7 100644 (file)
@@ -1439,6 +1439,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
                assert(usess);
 
                /* Create the default JUL tracepoint. */
+               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));
@@ -1460,7 +1461,7 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
 
                /* The wild card * means that everything should be enabled. */
                if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
-                       ret = event_jul_enable_all(usess);
+                       ret = event_jul_enable_all(usess, event);
                } else {
                        ret = event_jul_enable(usess, event);
                }
@@ -1644,7 +1645,7 @@ int cmd_enable_event_all(struct ltt_session *session,
        }
        case LTTNG_DOMAIN_JUL:
        {
-               struct lttng_event uevent;
+               struct lttng_event uevent, event;
                struct lttng_domain tmp_dom;
                struct ltt_ust_session *usess = session->ust_session;
 
@@ -1670,7 +1671,12 @@ int cmd_enable_event_all(struct ltt_session *session,
                        goto error;
                }
 
-               ret = event_jul_enable_all(usess);
+               event.loglevel = LTTNG_LOGLEVEL_JUL_ALL;
+               event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
+               strncpy(event.name, "*", sizeof(event.name));
+               event.name[sizeof(event.name) - 1] = '\0';
+
+               ret = event_jul_enable_all(usess, &event);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1773,6 +1779,7 @@ error:
 int cmd_start_trace(struct ltt_session *session)
 {
        int ret;
+       unsigned long nb_chan = 0;
        struct ltt_kernel_session *ksession;
        struct ltt_ust_session *usess;
 
@@ -1788,6 +1795,21 @@ int cmd_start_trace(struct ltt_session *session)
                goto error;
        }
 
+       /*
+        * Starting a session without channel is useless since after that it's not
+        * possible to enable channel thus inform the client.
+        */
+       if (usess && usess->domain_global.channels) {
+               nb_chan += lttng_ht_get_count(usess->domain_global.channels);
+       }
+       if (ksession) {
+               nb_chan += ksession->channel_count;
+       }
+       if (!nb_chan) {
+               ret = LTTNG_ERR_NO_CHANNEL;
+               goto error;
+       }
+
        session->enabled = 1;
 
        /* Kernel tracing */
@@ -2846,12 +2868,17 @@ static int record_ust_snapshot(struct ltt_ust_session *usess,
 
        ret = ust_app_snapshot_record(usess, output, wait, nb_streams);
        if (ret < 0) {
-               if (ret == -EINVAL) {
+               switch (-ret) {
+               case EINVAL:
                        ret = LTTNG_ERR_INVALID;
-                       goto error_snapshot;
+                       break;
+               case ENODATA:
+                       ret = LTTNG_ERR_SNAPSHOT_NODATA;
+                       break;
+               default:
+                       ret = LTTNG_ERR_SNAPSHOT_FAIL;
+                       break;
                }
-
-               ret = LTTNG_ERR_SNAPSHOT_FAIL;
                goto error_snapshot;
        }
 
This page took 0.024432 seconds and 4 git commands to generate.