X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=184dd494c74cfa29fe3408da36f94085df91b3ca;hb=659ed79f6b4a6ebbe7219a0fd4a347d24d62c545;hp=b1e66e755bf0f621fb8c78f84a6d8c9043cedc55;hpb=c890b720e435173420cac747c5701147ff7ead99;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index b1e66e755..184dd494c 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -584,7 +584,7 @@ close_sock: static int send_consumer_relayd_sockets(int domain, struct ltt_session *session, struct consumer_output *consumer, int fd) { - int ret; + int ret = LTTNG_OK; assert(session); assert(consumer); @@ -640,7 +640,7 @@ static int setup_relayd(struct ltt_session *session) assert(socket->fd >= 0); pthread_mutex_lock(socket->lock); - send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session, + ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session, usess->consumer, socket->fd); pthread_mutex_unlock(socket->lock); if (ret != LTTNG_OK) { @@ -657,7 +657,7 @@ static int setup_relayd(struct ltt_session *session) assert(socket->fd >= 0); pthread_mutex_lock(socket->lock); - send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session, + ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session, ksess->consumer, socket->fd); pthread_mutex_unlock(socket->lock); if (ret != LTTNG_OK) { @@ -1528,11 +1528,6 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session, goto error; } - if (!session->start_consumer) { - ret = LTTNG_ERR_NO_CONSUMER; - goto error; - } - /* * This case switch makes sure the domain session has a temporary consumer * so the URL can be set. @@ -2142,11 +2137,6 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) goto error; } - if (!session->start_consumer) { - ret = LTTNG_ERR_NO_CONSUMER; - goto error; - } - switch (domain) { case 0: assert(session->consumer); @@ -2213,11 +2203,6 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) break; } - /* Append default kernel trace dir to subdir */ - strncat(ksess->consumer->subdir, DEFAULT_KERNEL_TRACE_DIR, - sizeof(ksess->consumer->subdir) - - strlen(ksess->consumer->subdir) - 1); - /* * @session-lock * This is race free for now since the session lock is acquired before @@ -2226,6 +2211,7 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) * is valid. */ rcu_read_lock(); + /* Destroy current consumer. We are about to replace it */ consumer_destroy_output(ksess->consumer); rcu_read_unlock(); ksess->consumer = consumer; @@ -2299,11 +2285,6 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) break; } - /* Append default kernel trace dir to subdir */ - strncat(usess->consumer->subdir, DEFAULT_UST_TRACE_DIR, - sizeof(usess->consumer->subdir) - - strlen(usess->consumer->subdir) - 1); - /* * @session-lock * This is race free for now since the session lock is acquired before @@ -2312,6 +2293,7 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) * is valid. */ rcu_read_lock(); + /* Destroy current consumer. We are about to replace it */ consumer_destroy_output(usess->consumer); rcu_read_unlock(); usess->consumer = consumer; @@ -2320,6 +2302,8 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) break; } + session->start_consumer = 1; + /* Enable it */ if (consumer) { consumer->enabled = 1; @@ -2334,6 +2318,47 @@ error: return ret; } +/* + * Command LTTNG_DATA_AVAILABLE returning 0 if the data is NOT ready to be read + * or else 1 if the data is available for trace analysis. + */ +int cmd_data_available(struct ltt_session *session) +{ + int ret; + struct ltt_kernel_session *ksess = session->kernel_session; + struct ltt_ust_session *usess = session->ust_session; + + assert(session); + + /* Session MUST be stopped to ask for data availability. */ + if (session->enabled) { + ret = LTTNG_ERR_SESSION_STARTED; + goto error; + } + + if (ksess && ksess->consumer) { + ret = consumer_is_data_available(ksess->id, ksess->consumer); + if (ret == 0) { + /* Data is still being extracted for the kernel. */ + goto error; + } + } + + if (usess && usess->consumer) { + ret = consumer_is_data_available(usess->id, usess->consumer); + if (ret == 0) { + /* Data is still being extracted for the kernel. */ + goto error; + } + } + + /* Data is ready to be read by a viewer */ + ret = 1; + +error: + return ret; +} + /* * Init command subsystem. */