Destroy created kernel channel on enable all error
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 37a803b05ff12d399bb9d6de6a1c8bafe9fb2b2f..ff418e17ee0df63f8a82518db844d500fd879bcb 100644 (file)
@@ -440,7 +440,7 @@ static int init_kernel_tracing(struct ltt_kernel_session *session)
                        assert(socket->fd >= 0);
 
                        pthread_mutex_lock(socket->lock);
-                       ret = kernel_consumer_send_session(socket->fd, session);
+                       ret = kernel_consumer_send_session(socket, session);
                        pthread_mutex_unlock(socket->lock);
                        if (ret < 0) {
                                ret = LTTNG_ERR_KERN_CONSUMER_FAIL;
@@ -528,7 +528,7 @@ error:
  */
 static int send_consumer_relayd_socket(int domain, struct ltt_session *session,
                struct lttng_uri *relayd_uri, struct consumer_output *consumer,
-               int consumer_fd)
+               struct consumer_socket *consumer_sock)
 {
        int ret;
        struct lttcomm_sock *sock = NULL;
@@ -557,8 +557,8 @@ static int send_consumer_relayd_socket(int domain, struct ltt_session *session,
        }
 
        /* Send relayd socket to consumer. */
-       ret = consumer_send_relayd_socket(consumer_fd, sock,
-                       consumer, relayd_uri->stype);
+       ret = consumer_send_relayd_socket(consumer_sock, sock,
+                       consumer, relayd_uri->stype, session->id);
        if (ret < 0) {
                ret = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
                goto close_sock;
@@ -593,7 +593,8 @@ close_sock:
  * session.
  */
 static int send_consumer_relayd_sockets(int domain,
-               struct ltt_session *session, struct consumer_output *consumer, int fd)
+               struct ltt_session *session, struct consumer_output *consumer,
+               struct consumer_socket *sock)
 {
        int ret = LTTNG_OK;
 
@@ -603,7 +604,7 @@ static int send_consumer_relayd_sockets(int domain,
        /* Sending control relayd socket. */
        if (!consumer->dst.net.control_sock_sent) {
                ret = send_consumer_relayd_socket(domain, session,
-                               &consumer->dst.net.control, consumer, fd);
+                               &consumer->dst.net.control, consumer, sock);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -612,7 +613,7 @@ static int send_consumer_relayd_sockets(int domain,
        /* Sending data relayd socket. */
        if (!consumer->dst.net.data_sock_sent) {
                ret = send_consumer_relayd_socket(domain, session,
-                               &consumer->dst.net.data, consumer, fd);
+                               &consumer->dst.net.data, consumer, sock);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -652,7 +653,7 @@ static int setup_relayd(struct ltt_session *session)
 
                        pthread_mutex_lock(socket->lock);
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session,
-                                       usess->consumer, socket->fd);
+                                       usess->consumer, socket);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -669,7 +670,7 @@ static int setup_relayd(struct ltt_session *session)
 
                        pthread_mutex_lock(socket->lock);
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session,
-                                       ksess->consumer, socket->fd);
+                                       ksess->consumer, socket);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -826,9 +827,6 @@ int cmd_enable_channel(struct ltt_session *session,
        {
                struct ltt_kernel_channel *kchan;
 
-               /* Mandatory for a kernel channel. */
-               assert(wpipe > 0);
-
                kchan = trace_kernel_get_channel_by_name(attr->name,
                                session->kernel_session);
                if (kchan == NULL) {
@@ -1038,8 +1036,7 @@ error:
  * Command LTTNG_ADD_CONTEXT processed by the client thread.
  */
 int cmd_add_context(struct ltt_session *session, int domain,
-               char *channel_name, char *event_name, struct lttng_event_context *ctx,
-               int kwpipe)
+               char *channel_name, struct lttng_event_context *ctx, int kwpipe)
 {
        int ret;
 
@@ -1056,8 +1053,7 @@ int cmd_add_context(struct ltt_session *session, int domain,
                }
 
                /* Add kernel context to kernel tracer */
-               ret = context_kernel_add(session->kernel_session, ctx,
-                               event_name, channel_name);
+               ret = context_kernel_add(session->kernel_session, ctx, channel_name);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1086,8 +1082,7 @@ int cmd_add_context(struct ltt_session *session, int domain,
                        free(attr);
                }
 
-
-               ret = context_ust_add(usess, domain, ctx, event_name, channel_name);
+               ret = context_ust_add(usess, domain, ctx, channel_name);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1109,54 +1104,14 @@ error:
        return ret;
 }
 
-/*
- * Command LTTNG_SET_FILTER processed by the client thread.
- */
-int cmd_set_filter(struct ltt_session *session, int domain,
-               char *channel_name, char *event_name,
-               struct lttng_filter_bytecode *bytecode)
-{
-       int ret;
-
-       switch (domain) {
-       case LTTNG_DOMAIN_KERNEL:
-               ret = LTTNG_ERR_FATAL;
-               break;
-       case LTTNG_DOMAIN_UST:
-       {
-               struct ltt_ust_session *usess = session->ust_session;
-
-               ret = filter_ust_set(usess, domain, bytecode, event_name, channel_name);
-               if (ret != LTTNG_OK) {
-                       goto error;
-               }
-               break;
-       }
-#if 0
-       case LTTNG_DOMAIN_UST_EXEC_NAME:
-       case LTTNG_DOMAIN_UST_PID:
-       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
-       default:
-               ret = LTTNG_ERR_UND;
-               goto error;
-       }
-
-       ret = LTTNG_OK;
-
-error:
-       return ret;
-
-}
-
-
 /*
  * Command LTTNG_ENABLE_EVENT processed by the client thread.
  */
 int cmd_enable_event(struct ltt_session *session, int domain,
-               char *channel_name, struct lttng_event *event, int wpipe)
+               char *channel_name, struct lttng_event *event,
+               struct lttng_filter_bytecode *filter, int wpipe)
 {
-       int ret;
+       int ret, channel_created = 0;
        struct lttng_channel *attr;
 
        assert(session);
@@ -1184,6 +1139,8 @@ int cmd_enable_event(struct ltt_session *session, int domain,
                                goto error;
                        }
                        free(attr);
+
+                       channel_created = 1;
                }
 
                /* Get the newly created kernel channel pointer */
@@ -1198,6 +1155,10 @@ int cmd_enable_event(struct ltt_session *session, int domain,
                ret = event_kernel_enable_tracepoint(session->kernel_session, kchan,
                                event);
                if (ret != LTTNG_OK) {
+                       if (channel_created) {
+                               /* Let's not leak a useless channel. */
+                               kernel_destroy_channel(kchan);
+                       }
                        goto error;
                }
 
@@ -1237,7 +1198,7 @@ int cmd_enable_event(struct ltt_session *session, int domain,
                }
 
                /* At this point, the session and channel exist on the tracer */
-               ret = event_ust_enable_tracepoint(usess, domain, uchan, event);
+               ret = event_ust_enable_tracepoint(usess, domain, uchan, event, filter);
                if (ret != LTTNG_OK) {
                        goto error;
                }
@@ -1263,7 +1224,8 @@ error:
  * Command LTTNG_ENABLE_ALL_EVENT processed by the client thread.
  */
 int cmd_enable_event_all(struct ltt_session *session, int domain,
-               char *channel_name, int event_type, int wpipe)
+               char *channel_name, int event_type,
+               struct lttng_filter_bytecode *filter, int wpipe)
 {
        int ret;
        struct lttng_channel *attr;
@@ -1327,6 +1289,10 @@ int cmd_enable_event_all(struct ltt_session *session, int domain,
 
                /* Manage return value */
                if (ret != LTTNG_OK) {
+                       /*
+                        * On error, cmd_enable_channel call will take care of destroying
+                        * the created channel if it was needed.
+                        */
                        goto error;
                }
 
@@ -1370,7 +1336,8 @@ int cmd_enable_event_all(struct ltt_session *session, int domain,
                switch (event_type) {
                case LTTNG_EVENT_ALL:
                case LTTNG_EVENT_TRACEPOINT:
-                       ret = event_ust_enable_all_tracepoints(usess, domain, uchan);
+                       ret = event_ust_enable_all_tracepoints(usess, domain, uchan,
+                                       filter);
                        if (ret != LTTNG_OK) {
                                goto error;
                        }
@@ -1701,7 +1668,7 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session,
 
                        pthread_mutex_lock(socket->lock);
                        ret = send_consumer_relayd_socket(domain, session, &uris[i],
-                                       consumer, socket->fd);
+                                       consumer, socket);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                rcu_read_unlock();
@@ -1924,8 +1891,11 @@ int cmd_register_consumer(struct ltt_session *session, int domain,
 
                socket = consumer_allocate_socket(sock);
                if (socket == NULL) {
+                       ret = close(sock);
+                       if (ret < 0) {
+                               PERROR("close register consumer");
+                       }
                        ret = LTTNG_ERR_FATAL;
-                       close(sock);
                        goto error;
                }
 
This page took 0.026979 seconds and 4 git commands to generate.