X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=ff418e17ee0df63f8a82518db844d500fd879bcb;hp=d58c53b66865bc0126dab3a26882d7c58d1ce41d;hb=e5f5db7fe1ce6cf8e0ac6b2be2b4c85c2ba68375;hpb=601d5acf42ebdb05ff8aa19f12fd9bdad3602781 diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index d58c53b66..ff418e17e 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; @@ -1103,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); @@ -1178,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 */ @@ -1192,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; } @@ -1231,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; } @@ -1257,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; @@ -1321,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; } @@ -1364,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; } @@ -1695,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(); @@ -1918,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; }