Fix missing channel name copy for auto channel creation
[lttng-tools.git] / lttng-sessiond / main.c
index f63c351550c05a52a4a09c22d5967b6417c21746..4bb7240378161540cb4573e4a3fc91e076dbdbae 100644 (file)
@@ -335,21 +335,22 @@ error:
  */
 static void teardown_kernel_session(struct ltt_session *session)
 {
-       if (session->kernel_session != NULL) {
-               DBG("Tearing down kernel session");
+       if (!session->kernel_session) {
+               DBG3("No kernel session when tearingdown session");
+               return;
+       }
 
-               /*
-                * If a custom kernel consumer was registered, close the socket before
-                * tearing down the complete kernel session structure
-                */
-               if (session->kernel_session->consumer_fd != kconsumer_data.cmd_sock) {
-                       lttcomm_close_unix_sock(session->kernel_session->consumer_fd);
-               }
+       DBG("Tearing down kernel session");
 
-               trace_kernel_destroy_session(session->kernel_session);
-               /* Extra precaution */
-               session->kernel_session = NULL;
+       /*
+        * If a custom kernel consumer was registered, close the socket before
+        * tearing down the complete kernel session structure
+        */
+       if (session->kernel_session->consumer_fd != kconsumer_data.cmd_sock) {
+               lttcomm_close_unix_sock(session->kernel_session->consumer_fd);
        }
+
+       trace_kernel_destroy_session(session->kernel_session);
 }
 
 /*
@@ -360,12 +361,18 @@ static void teardown_ust_session(struct ltt_session *session)
 {
        int ret;
 
+       if (!session->ust_session) {
+               DBG3("No UST session when tearingdown session");
+               return;
+       }
+
        DBG("Tearing down UST session(s)");
 
        ret = ust_app_destroy_trace_all(session->ust_session);
        if (ret) {
                ERR("Error in ust_app_destroy_trace_all");
        }
+
        trace_ust_destroy_session(session->ust_session);
 }
 
@@ -1915,6 +1922,7 @@ static void list_lttng_channels(int domain, struct ltt_session *session,
                        channels[i].attr.read_timer_interval =
                                uchan->attr.read_timer_interval;
                        channels[i].attr.output = uchan->attr.output;
+                       channels[i].enabled = uchan->enabled;
                        i++;
                }
                break;
@@ -2065,22 +2073,52 @@ static int cmd_disable_channel(struct ltt_session *session,
                int domain, char *channel_name)
 {
        int ret;
+       struct ltt_ust_session *usess;
+
+       usess = session->ust_session;
 
        switch (domain) {
-               case LTTNG_DOMAIN_KERNEL:
-                       ret = channel_kernel_disable(session->kernel_session,
-                                       channel_name);
-                       if (ret != LTTCOMM_OK) {
-                               goto error;
-                       }
+       case LTTNG_DOMAIN_KERNEL:
+       {
+               ret = channel_kernel_disable(session->kernel_session,
+                               channel_name);
+               if (ret != LTTCOMM_OK) {
+                       goto error;
+               }
 
-                       kernel_wait_quiescent(kernel_tracer_fd);
-                       break;
-               case LTTNG_DOMAIN_UST_PID:
-                       break;
-               default:
-                       ret = LTTCOMM_UNKNOWN_DOMAIN;
+               kernel_wait_quiescent(kernel_tracer_fd);
+               break;
+       }
+       case LTTNG_DOMAIN_UST:
+       {
+               struct ltt_ust_channel *uchan;
+
+               /* Get channel in global UST domain HT */
+               uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
+                               channel_name);
+               if (uchan == NULL) {
+                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
                        goto error;
+               }
+
+               ret = ust_app_disable_channel_all(usess, uchan);
+               if (ret < 0) {
+                       ret = LTTCOMM_UST_DISABLE_FAIL;
+                       goto error;
+               }
+
+               uchan->enabled = 0;
+
+               break;
+       }
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+               ret = LTTCOMM_NOT_IMPLEMENTED;
+               goto error;
+       default:
+               ret = LTTCOMM_UNKNOWN_DOMAIN;
+               goto error;
        }
 
        ret = LTTCOMM_OK;
@@ -2127,14 +2165,14 @@ error:
  * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
  */
 static int cmd_enable_channel(struct ltt_session *session,
-               struct lttng_domain *domain, struct lttng_channel *attr)
+               int domain, struct lttng_channel *attr)
 {
        int ret;
        struct ltt_ust_session *usess = session->ust_session;
 
        DBG("Enabling channel %s for session %s", attr->name, session->name);
 
-       switch (domain->type) {
+       switch (domain) {
        case LTTNG_DOMAIN_KERNEL:
        {
                struct ltt_kernel_channel *kchan;
@@ -2175,65 +2213,36 @@ static int cmd_enable_channel(struct ltt_session *session,
                        hashtable_add_unique(usess->domain_global.channels, &uchan->node);
                        rcu_read_unlock();
                        DBG2("UST channel %s added to global domain HT", attr->name);
+
+                       /* Add channel to all registered applications */
+                       ret = ust_app_create_channel_all(usess, uchan);
+                       if (ret != 0) {
+                               ret = LTTCOMM_UST_CHAN_FAIL;
+                               goto error;
+                       }
                } else {
-                       ret = LTTCOMM_UST_CHAN_EXIST;
-                       goto error;
-               }
+                       /* If already enabled, everything is OK */
+                       if (uchan->enabled) {
+                               ret = LTTCOMM_OK;
+                               goto error;
+                       }
 
-               /* Add channel to all registered applications */
-               ret = ust_app_create_channel_all(usess, uchan);
-               if (ret != 0) {
-                       goto error;
+                       ret = ust_app_enable_channel_all(usess, uchan);
+                       if (ret < 0) {
+                               ret = LTTCOMM_UST_ENABLE_FAIL;
+                               goto error;
+                       }
                }
 
                uchan->enabled = 1;
 
                break;
        }
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
        case LTTNG_DOMAIN_UST_PID:
-       {
-               /*
-               int sock;
-               struct ltt_ust_channel *uchan;
-               struct ltt_ust_session *usess;
-               struct ust_app *app;
-
-               usess = trace_ust_get_session_by_pid(&session->ust_session_list,
-                               domain->attr.pid);
-               if (usess == NULL) {
-                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
-                       goto error;
-               }
-
-               app = ust_app_get_by_pid(domain->attr.pid);
-               if (app == NULL) {
-                       ret = LTTCOMM_APP_NOT_FOUND;
-                       goto error;
-               }
-               sock = app->sock;
-
-               uchan = trace_ust_get_channel_by_name(attr->name, usess);
-               if (uchan == NULL) {
-                       ret = channel_ust_create(usess, attr, sock);
-               } else {
-                       ret = channel_ust_enable(usess, uchan, sock);
-               }
-
-               if (ret != LTTCOMM_OK) {
-                       goto error;
-               }
-
-               ret = copy_ust_channel_to_app(usess, attr, app);
-               if (ret != LTTCOMM_OK) {
-                       goto error;
-               }
-
-               DBG("UST channel %s created for app sock %d with pid %d",
-                               attr->name, app->sock, domain->attr.pid);
-               */
                ret = LTTCOMM_NOT_IMPLEMENTED;
                goto error;
-       }
        default:
                ret = LTTCOMM_UNKNOWN_DOMAIN;
                goto error;
@@ -2425,13 +2434,35 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
        {
                struct ltt_ust_channel *uchan;
                struct ltt_ust_event *uevent;
+               struct lttng_channel *attr;
 
                uchan = trace_ust_find_channel_by_name(usess->domain_global.channels,
                                channel_name);
                if (uchan == NULL) {
-                       /* TODO: Create default channel */
-                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
-                       goto error;
+                       /* Create default channel */
+                       attr = channel_new_default_attr(domain);
+                       if (attr == NULL) {
+                               ret = LTTCOMM_FATAL;
+                               goto error;
+                       }
+                       snprintf(attr->name, NAME_MAX, "%s", channel_name);
+
+                       /* Use the internal command enable channel */
+                       ret = cmd_enable_channel(session, domain, attr);
+                       if (ret < 0) {
+                               goto error;
+                       }
+
+                       free(attr);
+
+                       /* Get the newly created channel reference back */
+                       uchan = trace_ust_find_channel_by_name(
+                                       usess->domain_global.channels, channel_name);
+                       if (uchan == NULL) {
+                               /* Something is really wrong */
+                               ret = LTTCOMM_FATAL;
+                               goto error;
+                       }
                }
 
                uevent = trace_ust_find_event_by_name(uchan->events, event->name);
@@ -2713,7 +2744,6 @@ static int cmd_stop_trace(struct ltt_session *session)
                kernel_wait_quiescent(kernel_tracer_fd);
        }
 
-       /* Flag session that trace should start automatically */
        if (usess) {
                usess->start_trace = 0;
 
@@ -3152,7 +3182,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        }
        case LTTNG_ENABLE_CHANNEL:
        {
-               ret = cmd_enable_channel(cmd_ctx->session, &cmd_ctx->lsm->domain,
+               ret = cmd_enable_channel(cmd_ctx->session, cmd_ctx->lsm->domain.type,
                                &cmd_ctx->lsm->u.channel.chan);
                break;
        }
This page took 0.026408 seconds and 4 git commands to generate.