X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=d5ed1dcfc39e4d02a6d0a8996f1d7945c91f2137;hb=c92af2a5fd6587a03f1a0e927fd734751032b3a1;hp=fb5f19bdbab6cb19ddc2d07466750a36e1366a9c;hpb=24624ef25108477e62badb945319c06ed41ff49d;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index fb5f19bdb..d5ed1dcfc 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -41,6 +41,7 @@ #include "syscall.h" #include "agent.h" #include "buffer-registry.h" +#include "agent-thread.h" #include "cmd.h" @@ -856,8 +857,11 @@ static int create_connect_relayd(struct lttng_uri *uri, /* Check relayd version */ ret = relayd_version_check(rsock); - if (ret < 0) { - ret = LTTNG_ERR_RELAYD_VERSION_FAIL; + if (ret == LTTNG_ERR_RELAYD_VERSION_FAIL) { + goto close_sock; + } else if (ret < 0) { + ERR("Unable to reach lttng-relayd"); + ret = LTTNG_ERR_RELAYD_CONNECT_FAIL; goto close_sock; } consumer->relay_major_version = rsock->major; @@ -886,6 +890,8 @@ error: /* * Connect to the relayd using URI and send the socket to the right consumer. + * + * The consumer socket lock must be held by the caller. */ static int send_consumer_relayd_socket(enum lttng_domain_type domain, unsigned int session_id, struct lttng_uri *relayd_uri, @@ -899,7 +905,7 @@ static int send_consumer_relayd_socket(enum lttng_domain_type domain, /* Connect to relayd and make version check if uri is the control. */ ret = create_connect_relayd(relayd_uri, &rsock, consumer); if (ret != LTTNG_OK) { - goto error; + goto relayd_comm_error; } assert(rsock); @@ -939,10 +945,6 @@ static int send_consumer_relayd_socket(enum lttng_domain_type domain, */ close_sock: - (void) relayd_close(rsock); - free(rsock); - -error: if (ret != LTTNG_OK) { /* * The consumer output for this session should not be used anymore @@ -951,6 +953,10 @@ error: */ consumer->enabled = 0; } + (void) relayd_close(rsock); + free(rsock); + +relayd_comm_error: return ret; } @@ -958,6 +964,8 @@ error: * Send both relayd sockets to a specific consumer and domain. This is a * helper function to facilitate sending the information to the consumer for a * session. + * + * The consumer socket lock must be held by the caller. */ static int send_consumer_relayd_sockets(enum lttng_domain_type domain, unsigned int session_id, struct consumer_output *consumer, @@ -1187,12 +1195,14 @@ error: } /* - * Command LTTNG_TRACK_PID processed by the client thread. + * Command LTTNG_TRACK_ID processed by the client thread. * * Called with session lock held. */ -int cmd_track_pid(struct ltt_session *session, enum lttng_domain_type domain, - int pid) +int cmd_track_id(struct ltt_session *session, + enum lttng_tracker_type tracker_type, + enum lttng_domain_type domain, + struct lttng_tracker_id *id) { int ret; @@ -1205,7 +1215,7 @@ int cmd_track_pid(struct ltt_session *session, enum lttng_domain_type domain, ksess = session->kernel_session; - ret = kernel_track_pid(ksess, pid); + ret = kernel_track_id(tracker_type, ksess, id); if (ret != LTTNG_OK) { goto error; } @@ -1219,7 +1229,7 @@ int cmd_track_pid(struct ltt_session *session, enum lttng_domain_type domain, usess = session->ust_session; - ret = trace_ust_track_pid(usess, pid); + ret = trace_ust_track_id(tracker_type, usess, id); if (ret != LTTNG_OK) { goto error; } @@ -1238,12 +1248,14 @@ error: } /* - * Command LTTNG_UNTRACK_PID processed by the client thread. + * Command LTTNG_UNTRACK_ID processed by the client thread. * * Called with session lock held. */ -int cmd_untrack_pid(struct ltt_session *session, enum lttng_domain_type domain, - int pid) +int cmd_untrack_id(struct ltt_session *session, + enum lttng_tracker_type tracker_type, + enum lttng_domain_type domain, + struct lttng_tracker_id *id) { int ret; @@ -1256,7 +1268,7 @@ int cmd_untrack_pid(struct ltt_session *session, enum lttng_domain_type domain, ksess = session->kernel_session; - ret = kernel_untrack_pid(ksess, pid); + ret = kernel_untrack_id(tracker_type, ksess, id); if (ret != LTTNG_OK) { goto error; } @@ -1270,7 +1282,7 @@ int cmd_untrack_pid(struct ltt_session *session, enum lttng_domain_type domain, usess = session->ust_session; - ret = trace_ust_untrack_pid(usess, pid); + ret = trace_ust_untrack_id(tracker_type, usess, id); if (ret != LTTNG_OK) { goto error; } @@ -1337,6 +1349,21 @@ int cmd_enable_channel(struct ltt_session *session, attr->attr.switch_timer_interval = 0; } + /* Check for feature support */ + switch (domain->type) { + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: + case LTTNG_DOMAIN_PYTHON: + if (!agent_tracing_is_enabled()) { + DBG("Attempted to enable a channel in an agent domain but the agent thread is not running"); + ret = LTTNG_ERR_AGENT_TRACING_DISABLED; + goto error; + } + break; + default: + break; + } + switch (domain->type) { case LTTNG_DOMAIN_KERNEL: { @@ -1609,6 +1636,16 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain, int ret, chan_kern_created = 0, chan_ust_created = 0; char *app_ctx_provider_name = NULL, *app_ctx_name = NULL; + /* + * Don't try to add a context if the session has been started at + * some point in time before. The tracer does not allow it and would + * result in a corrupted trace. + */ + if (session->has_been_started) { + ret = LTTNG_ERR_TRACE_ALREADY_STARTED; + goto end; + } + if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { app_ctx_provider_name = ctx->u.app_ctx.provider_name; app_ctx_name = ctx->u.app_ctx.ctx_name; @@ -2060,6 +2097,12 @@ static int _cmd_enable_event(struct ltt_session *session, assert(usess); + if (!agent_tracing_is_enabled()) { + DBG("Attempted to enable an event in an agent domain but the agent thread is not running"); + ret = LTTNG_ERR_AGENT_TRACING_DISABLED; + goto error; + } + agt = trace_ust_find_agent(usess, domain->type); if (!agt) { agt = agent_create(domain->type); @@ -2293,12 +2336,14 @@ ssize_t cmd_list_syscalls(struct lttng_event **events) } /* - * Command LTTNG_LIST_TRACKER_PIDS processed by the client thread. + * Command LTTNG_LIST_TRACKER_IDS processed by the client thread. * * Called with session lock held. */ -ssize_t cmd_list_tracker_pids(struct ltt_session *session, - enum lttng_domain_type domain, int32_t **pids) +ssize_t cmd_list_tracker_ids(enum lttng_tracker_type tracker_type, + struct ltt_session *session, + enum lttng_domain_type domain, + struct lttng_tracker_id **ids) { int ret; ssize_t nr_pids = 0; @@ -2309,7 +2354,7 @@ ssize_t cmd_list_tracker_pids(struct ltt_session *session, struct ltt_kernel_session *ksess; ksess = session->kernel_session; - nr_pids = kernel_list_tracker_pids(ksess, pids); + nr_pids = kernel_list_tracker_ids(tracker_type, ksess, ids); if (nr_pids < 0) { ret = LTTNG_ERR_KERN_LIST_FAIL; goto error; @@ -2321,7 +2366,7 @@ ssize_t cmd_list_tracker_pids(struct ltt_session *session, struct ltt_ust_session *usess; usess = session->ust_session; - nr_pids = trace_ust_list_tracker_pids(usess, pids); + nr_pids = trace_ust_list_tracker_ids(tracker_type, usess, ids); if (nr_pids < 0) { ret = LTTNG_ERR_UST_LIST_FAIL; goto error; @@ -3390,10 +3435,12 @@ static int clear_metadata_file(int fd) { int ret; + off_t lseek_ret; - ret = lseek(fd, 0, SEEK_SET); - if (ret < 0) { + lseek_ret = lseek(fd, 0, SEEK_SET); + if (lseek_ret < 0) { PERROR("lseek"); + ret = -1; goto end; } @@ -3606,10 +3653,12 @@ static int set_relayd_for_snapshot(struct consumer_output *consumer, rcu_read_lock(); cds_lfht_for_each_entry(snap_output->consumer->socks->ht, &iter.iter, socket, node.node) { + pthread_mutex_lock(socket->lock); ret = send_consumer_relayd_sockets(0, session->id, snap_output->consumer, socket, session->name, session->hostname, session->live_timer); + pthread_mutex_unlock(socket->lock); if (ret != LTTNG_OK) { rcu_read_unlock(); goto error;