event-rule: userspace probe: rename get/set_name to get/set_event_name
[lttng-tools.git] / src / bin / lttng / commands / enable_channels.c
index 27d4618a9d0fd5b2f40f7c0dd7b05055bbd90d79..fa65b1eaa9257d84e3be698a7e10a9960683c0d8 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
@@ -46,7 +36,7 @@ static int opt_buffer_pid;
 static int opt_buffer_global;
 static struct {
        bool set;
-       uint32_t interval;
+       uint64_t interval;
 } opt_monitor_timer;
 static struct {
        bool set;
@@ -244,7 +234,7 @@ static int enable_channel(char *session_name)
                void *extended_ptr;
 
                /* Validate channel name's length */
-               if (strlen(channel_name) >= NAME_MAX) {
+               if (strlen(channel_name) >= sizeof(chan_opts.name)) {
                        ERR("Channel name is too long (max. %zu characters)",
                                        sizeof(chan_opts.name) - 1);
                        error = 1;
@@ -400,6 +390,7 @@ int cmd_enable_channels(int argc, const char **argv)
        static poptContext pc;
        char *session_name = NULL;
        char *opt_arg = NULL;
+       const char *leftover = NULL;
 
        init_channel_config();
 
@@ -492,111 +483,121 @@ int cmd_enable_channels(int argc, const char **argv)
                }
                case OPT_SWITCH_TIMER:
                {
-                       unsigned long v;
+                       uint64_t v;
 
                        errno = 0;
                        opt_arg = poptGetOptArg(pc);
-                       v = strtoul(opt_arg, NULL, 0);
-                       if (errno != 0 || !isdigit(opt_arg[0])) {
-                               ERR("Wrong value in --switch-timer parameter: %s", opt_arg);
+
+                       if (utils_parse_time_suffix(opt_arg, &v) < 0) {
+                               ERR("Wrong value for --switch-timer parameter: %s", opt_arg);
                                ret = CMD_ERROR;
                                goto end;
                        }
+
                        if (v != (uint32_t) v) {
                                ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg);
                                ret = CMD_ERROR;
                                goto end;
                        }
                        chan_opts.attr.switch_timer_interval = (uint32_t) v;
-                       DBG("Channel switch timer interval set to %d", chan_opts.attr.switch_timer_interval);
+                       DBG("Channel switch timer interval set to %d %s",
+                                       chan_opts.attr.switch_timer_interval,
+                                       USEC_UNIT);
                        break;
                }
                case OPT_READ_TIMER:
                {
-                       unsigned long v;
+                       uint64_t v;
 
                        errno = 0;
                        opt_arg = poptGetOptArg(pc);
-                       v = strtoul(opt_arg, NULL, 0);
-                       if (errno != 0 || !isdigit(opt_arg[0])) {
-                               ERR("Wrong value in --read-timer parameter: %s", opt_arg);
+
+                       if (utils_parse_time_suffix(opt_arg, &v) < 0) {
+                               ERR("Wrong value for --read-timer parameter: %s", opt_arg);
                                ret = CMD_ERROR;
                                goto end;
                        }
+
                        if (v != (uint32_t) v) {
                                ERR("32-bit overflow in --read-timer parameter: %s", opt_arg);
                                ret = CMD_ERROR;
                                goto end;
                        }
                        chan_opts.attr.read_timer_interval = (uint32_t) v;
-                       DBG("Channel read timer interval set to %d", chan_opts.attr.read_timer_interval);
+                       DBG("Channel read timer interval set to %d %s",
+                                       chan_opts.attr.read_timer_interval,
+                                       USEC_UNIT);
                        break;
                }
                case OPT_MONITOR_TIMER:
                {
-                       unsigned long v;
+                       uint64_t v;
 
                        errno = 0;
                        opt_arg = poptGetOptArg(pc);
-                       v = strtoul(opt_arg, NULL, 0);
-                       if (errno != 0 || !isdigit(opt_arg[0])) {
-                               ERR("Wrong value in --monitor-timer parameter: %s", opt_arg);
-                               ret = CMD_ERROR;
-                               goto end;
-                       }
-                       if (v != (uint32_t) v) {
-                               ERR("32-bit overflow in --monitor-timer parameter: %s", opt_arg);
+
+                       if (utils_parse_time_suffix(opt_arg, &v) < 0) {
+                               ERR("Wrong value for --monitor-timer parameter: %s", opt_arg);
                                ret = CMD_ERROR;
                                goto end;
                        }
-                       opt_monitor_timer.interval = (uint32_t) v;
+                       opt_monitor_timer.interval = (uint64_t) v;
                        opt_monitor_timer.set = true;
-                       DBG("Channel monitor timer interval set to %d", opt_monitor_timer.interval);
+                       DBG("Channel monitor timer interval set to %" PRIu64 " %s",
+                                       opt_monitor_timer.interval,
+                                       USEC_UNIT);
                        break;
                }
                case OPT_BLOCKING_TIMEOUT:
                {
-                       long long v;    /* in usec */
+                       uint64_t v;
                        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);
+
+                       if (strcmp(opt_arg, "inf") == 0) {
+                               opt_blocking_timeout.value = (int64_t) -1;
+                               opt_blocking_timeout.set = true;
+                               DBG("Channel blocking timeout set to infinity");
+                               break;
+                       }
+
+                       if (utils_parse_time_suffix(opt_arg, &v) < 0) {
+                               ERR("Wrong value for --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");
+
+                       /*
+                        * 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;
                        }
+
                        opt_blocking_timeout.value = (int64_t) v;
                        opt_blocking_timeout.set = true;
-                       DBG("Channel blocking timeout set to %" PRId64 " (µs)",
-                                       opt_blocking_timeout.value);
+                       DBG("Channel blocking timeout set to %" PRId64 " %s%s",
+                                       opt_blocking_timeout.value,
+                                       USEC_UNIT,
+                                       opt_blocking_timeout.value == 0 ?
+                                               " (non-blocking)" : "");
                        break;
                }
                case OPT_USERSPACE:
@@ -643,12 +644,21 @@ int cmd_enable_channels(int argc, const char **argv)
                }
        }
 
-       ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace);
+       ret = print_missing_or_multiple_domains(
+                       opt_kernel + opt_userspace, false);
        if (ret) {
                ret = CMD_ERROR;
                goto end;
        }
 
+       if (chan_opts.attr.overwrite == 1 && opt_blocking_timeout.set &&
+                       opt_blocking_timeout.value != 0) {
+               ERR("You cannot specify --overwrite and --blocking-timeout=N, "
+                       "where N is different than 0");
+               ret = CMD_ERROR;
+               goto end;
+       }
+
        /* Mi check */
        if (lttng_opt_mi) {
                writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
@@ -682,6 +692,14 @@ int cmd_enable_channels(int argc, const char **argv)
                goto mi_closing;
        }
 
+       leftover = poptGetArg(pc);
+       if (leftover) {
+               ERR("Unknown argument: %s", leftover);
+               ret = CMD_ERROR;
+               success = 0;
+               goto mi_closing;
+       }
+
        if (!opt_session_name) {
                session_name = get_session_name();
                if (session_name == NULL) {
This page took 0.03091 seconds and 4 git commands to generate.