CUSTOM: liver timer: immediate liver timer control on data pending and destroy
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 731040a3c6c9e157ec2fe9f9b91268ae4fdbccf6..8cb60b3aa51d2ace2f7efaea0375e809cf78dbed 100644 (file)
@@ -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;
@@ -1191,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;
 
@@ -1209,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;
                }
@@ -1223,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;
                }
@@ -1242,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;
 
@@ -1260,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;
                }
@@ -1274,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;
                }
@@ -1341,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:
        {
@@ -1613,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;
@@ -2064,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);
@@ -2297,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;
@@ -2313,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;
@@ -2325,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;
@@ -2732,6 +2773,8 @@ int cmd_destroy_session(struct ltt_session *session, int wpipe)
                /* Close any relayd session */
                consumer_output_send_destroy_relayd(usess->consumer);
 
+               ust_force_stop_live_timer(usess);
+
                /* Destroy every UST application related to this session. */
                ret = ust_app_destroy_trace_all(usess);
                if (ret) {
@@ -3131,11 +3174,21 @@ int cmd_data_pending(struct ltt_session *session)
        }
 
        if (usess && usess->consumer) {
+               /*
+                * Stop the live timer since it can lead to stream and relayd
+                * contention for the data pending check.
+                */
+               ust_force_stop_live_timer(usess);
                ret = consumer_is_data_pending(usess->id, usess->consumer);
                if (ret == 1) {
                        /* Data is still being extracted for the kernel. */
                        goto error;
                }
+               /*
+                * Restart the live timer to ensure that we send inactivity
+                * beacon as needed
+                */
+               ust_force_start_live_timer(usess);
        }
 
        /* Data is ready to be read by a viewer */
@@ -3394,10 +3447,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;
        }
 
This page took 0.034748 seconds and 5 git commands to generate.