X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fenable_channels.c;h=194ec541eae167077597997fce467e3f10c101bd;hb=81663f073dbfb4b61c06a0ceb8ca33c4fc41b1c5;hp=9c84d02634c8612740b914c4a1c6d0d5e806b210;hpb=68c7f6e55254fd6e54d7bb4a6c1316bb77843a6e;p=lttng-tools.git diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 9c84d0263..194ec541e 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2011 - David Goulet + * Copyright (C) 2011 David Goulet * - * 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 @@ -24,13 +14,14 @@ #include #include #include -#include #include #include #include #include +#include + #include "../command.h" #include "../utils.h" @@ -189,7 +180,7 @@ static int enable_channel(char *session_name) } } else { /* Checked by the caller. */ - assert(0); + abort(); } set_default_attr(&dom); @@ -230,7 +221,7 @@ static int enable_channel(char *session_name) /* Mi open channels element */ if (lttng_opt_mi) { - assert(writer); + LTTNG_ASSERT(writer); ret = mi_lttng_channels_open(writer); if (ret) { ret = CMD_ERROR; @@ -244,7 +235,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; @@ -314,7 +305,8 @@ static int enable_channel(char *session_name) } } else { MSG("%s channel %s enabled for session %s", - get_domain_str(dom.type), channel_name, session_name); + lttng_domain_type_str(dom.type), + channel_name, session_name); success = 1; } @@ -434,7 +426,7 @@ int cmd_enable_channels(int argc, const char **argv) } order = get_count_order_u64(chan_opts.attr.subbuf_size); - assert(order >= 0); + LTTNG_ASSERT(order >= 0); rounded_size = 1ULL << order; if (rounded_size < chan_opts.attr.subbuf_size) { ERR("The subbuf size (%" PRIu64 ") is rounded and overflows!", @@ -450,7 +442,7 @@ int cmd_enable_channels(int argc, const char **argv) } /* Should now be power of 2 */ - assert(!((chan_opts.attr.subbuf_size - 1) & chan_opts.attr.subbuf_size)); + LTTNG_ASSERT(!((chan_opts.attr.subbuf_size - 1) & chan_opts.attr.subbuf_size)); DBG("Channel subbuf size set to %" PRIu64, chan_opts.attr.subbuf_size); break; @@ -470,7 +462,7 @@ int cmd_enable_channels(int argc, const char **argv) } order = get_count_order_u64(chan_opts.attr.num_subbuf); - assert(order >= 0); + LTTNG_ASSERT(order >= 0); rounded_size = 1ULL << order; if (rounded_size < chan_opts.attr.num_subbuf) { ERR("The number of subbuffers (%" PRIu64 ") is rounded and overflows!", @@ -486,73 +478,81 @@ int cmd_enable_channels(int argc, const char **argv) } /* Should now be power of 2 */ - assert(!((chan_opts.attr.num_subbuf - 1) & chan_opts.attr.num_subbuf)); + LTTNG_ASSERT(!((chan_opts.attr.num_subbuf - 1) & chan_opts.attr.num_subbuf)); DBG("Channel subbuf num set to %" PRIu64, chan_opts.attr.num_subbuf); break; } 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 long v; + uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); - v = strtoull(opt_arg, NULL, 0); - if (errno != 0 || !isdigit(opt_arg[0])) { - ERR("Wrong value 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 = (uint64_t) v; opt_monitor_timer.set = true; - DBG("Channel monitor timer interval set to %" PRIu64" (µs)", 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; @@ -565,10 +565,8 @@ int cmd_enable_channels(int argc, const char **argv) break; } - v = strtoll(opt_arg, NULL, 0); - if (errno != 0 || (!isdigit(opt_arg[0]) && opt_arg[0] != '-') - || v < 0) { - ERR("Wrong value in --blocking-timeout parameter: %s", opt_arg); + if (utils_parse_time_suffix(opt_arg, &v) < 0) { + ERR("Wrong value for --blocking-timeout parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } @@ -597,8 +595,9 @@ int cmd_enable_channels(int argc, const char **argv) opt_blocking_timeout.value = (int64_t) v; opt_blocking_timeout.set = true; - DBG("Channel blocking timeout set to %" PRId64 " µs%s", + DBG("Channel blocking timeout set to %" PRId64 " %s%s", opt_blocking_timeout.value, + USEC_UNIT, opt_blocking_timeout.value == 0 ? " (non-blocking)" : ""); break; @@ -647,7 +646,8 @@ 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;