X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=ff418e17ee0df63f8a82518db844d500fd879bcb;hp=386b99ae216504e86cf9225f300816791e4f4234;hb=e5f5db7fe1ce6cf8e0ac6b2be2b4c85c2ba68375;hpb=9aa9f90096acb57bdc6939920bea9fc7e4f60231 diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 386b99ae2..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; @@ -736,7 +737,7 @@ static int start_kernel_session(struct ltt_kernel_session *ksess, int wpipe) } /* Quiescent wait after starting trace */ - kernel_wait_quiescent(wpipe); + kernel_wait_quiescent(kernel_tracer_fd); ksess->started = 1; @@ -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) { @@ -841,7 +839,7 @@ int cmd_enable_channel(struct ltt_session *session, goto error; } - kernel_wait_quiescent(wpipe); + kernel_wait_quiescent(kernel_tracer_fd); /* * If the session was previously started, start as well this newly @@ -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,47 +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); - 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_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); + ret = context_ust_add(usess, domain, ctx, channel_name); if (ret != LTTNG_OK) { goto error; } @@ -1146,17 +1102,16 @@ int cmd_set_filter(struct ltt_session *session, int domain, 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; }