Introduce "--blocking-timeout" channel parameter
[lttng-tools.git] / src / bin / lttng / commands / enable_channels.c
index 22331cec2b2ead8d032ede422df7f581df4f7c38..27d4618a9d0fd5b2f40f7c0dd7b05055bbd90d79 100644 (file)
@@ -48,6 +48,10 @@ static struct {
        bool set;
        uint32_t interval;
 } opt_monitor_timer;
+static struct {
+       bool set;
+       int64_t value;
+} opt_blocking_timeout;
 
 static struct mi_writer *writer;
 
@@ -70,6 +74,7 @@ enum {
        OPT_LIST_OPTIONS,
        OPT_TRACEFILE_SIZE,
        OPT_TRACEFILE_COUNT,
+       OPT_BLOCKING_TIMEOUT,
 };
 
 static struct lttng_handle *handle;
@@ -97,6 +102,7 @@ static struct poptOption long_options[] = {
        {"buffers-global", 0,   POPT_ARG_VAL, &opt_buffer_global, 1, 0, 0},
        {"tracefile-size", 'C',   POPT_ARG_INT, 0, OPT_TRACEFILE_SIZE, 0, 0},
        {"tracefile-count", 'W',   POPT_ARG_INT, 0, OPT_TRACEFILE_COUNT, 0, 0},
+       {"blocking-timeout",     0,   POPT_ARG_INT, 0, OPT_BLOCKING_TIMEOUT, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -151,6 +157,15 @@ static int enable_channel(char *session_name)
 
        memset(&dom, 0, sizeof(dom));
 
+       /* Validate options. */
+       if (opt_kernel) {
+               if (opt_blocking_timeout.set) {
+                       ERR("Retry timeout option not supported for kernel domain (-k)");
+                       ret = CMD_ERROR;
+                       goto error;
+               }
+       }
+
        /* Create lttng domain */
        if (opt_kernel) {
                dom.type = LTTNG_DOMAIN_KERNEL;
@@ -262,6 +277,15 @@ static int enable_channel(char *session_name)
                                goto error;
                        }
                }
+               if (opt_blocking_timeout.set) {
+                       ret = lttng_channel_set_blocking_timeout(channel,
+                                       opt_blocking_timeout.value);
+                       if (ret) {
+                               ERR("Failed to set the channel's blocking timeout");
+                               error = 1;
+                               goto error;
+                       }
+               }
 
                DBG("Enabling channel %s", channel_name);
 
@@ -530,6 +554,51 @@ int cmd_enable_channels(int argc, const char **argv)
                        DBG("Channel monitor timer interval set to %d", opt_monitor_timer.interval);
                        break;
                }
+               case OPT_BLOCKING_TIMEOUT:
+               {
+                       long long v;    /* in usec */
+                       long long v_msec;
+
+                       errno = 0;
+                       opt_arg = poptGetOptArg(pc);
+                       v = strtoll(opt_arg, NULL, 0);
+                       if (errno != 0 || (!isdigit(opt_arg[0]) && opt_arg[0] != '-')
+                                       || v < -1) {
+                               ERR("Wrong value in --blocking-timeout parameter: %s", opt_arg);
+                               ret = CMD_ERROR;
+                               goto end;
+                       }
+                       if (v >= 0) {
+                               /*
+                                * While LTTng-UST and LTTng-tools will accept
+                                * a blocking timeout expressed in µs, the
+                                * current tracer implementation relies on
+                                * poll() which takes an "int timeout" parameter
+                                * expressed in msec.
+                                *
+                                * Since the error reporting from the tracer
+                                * is not precise, we perform this check here
+                                * to provide a helpful error message in case of
+                                * overflow.
+                                *
+                                * The setter (liblttng-ctl) also performs an
+                                * equivalent check.
+                                */
+                               v_msec = v / 1000;
+                               if (v_msec != (int32_t) v_msec) {
+                                       ERR("32-bit milliseconds overflow in --blocking-timeout parameter: %s", opt_arg);
+                                       ret = CMD_ERROR;
+                                       goto end;
+                               }
+                       } else if (v != -1) {
+                               ERR("Invalid negative value passed as --blocking-timeout parameter; -1 (block forever) is the only valid negative value");
+                       }
+                       opt_blocking_timeout.value = (int64_t) v;
+                       opt_blocking_timeout.set = true;
+                       DBG("Channel blocking timeout set to %" PRId64 " (µs)",
+                                       opt_blocking_timeout.value);
+                       break;
+               }
                case OPT_USERSPACE:
                        opt_userspace = 1;
                        break;
This page took 0.024182 seconds and 4 git commands to generate.