X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fdisable_channels.c;h=aba7aac826be87c58b55366e728aea0728912678;hb=b7f4ea0f4c6ac71da5e4e6fe988df4d35734332a;hp=96a9e5d6c93292f9c6d101d56b9b8f904ebdce2a;hpb=6c1c0768320135c6936c371b09731851b508c023;p=lttng-tools.git diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 96a9e5d6c..aba7aac82 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -1,21 +1,10 @@ /* - * Copyright (C) 2011 - David Goulet + * Copyright (C) 2011 EfficiOS Inc. * - * 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 _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -27,17 +16,18 @@ #include #include +#include #include "../command.h" -static char *opt_channels; static int opt_kernel; static char *opt_session_name; static int opt_userspace; -#if 0 -/* Not implemented yet */ -static char *opt_cmd_name; -static pid_t opt_pid; + +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; #endif enum { @@ -54,33 +44,11 @@ static struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, -#if 0 - /* Not implemented yet */ - {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, - {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, -#else {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, -#endif {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, {0, 0, 0, 0, 0, 0, 0} }; -/* - * usage - */ -static void usage(FILE *ofp) -{ - fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] (-k | -u) [OPTIONS]\n"); - fprintf(ofp, "\n"); - fprintf(ofp, "Options:\n"); - fprintf(ofp, " -h, --help Show this help\n"); - fprintf(ofp, " --list-options Simple listing of options\n"); - fprintf(ofp, " -s, --session NAME Apply to session name\n"); - fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n"); - fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); - fprintf(ofp, "\n"); -} - static int mi_partial_channel_print(char *channel_name, unsigned int enabled, int success) { @@ -126,7 +94,7 @@ end: /* * Disabling channel using the lttng API. */ -static int disable_channels(char *session_name) +static int disable_channels(char *session_name, char *channel_list) { int ret = CMD_SUCCESS, warn = 0, success; @@ -143,9 +111,8 @@ static int disable_channels(char *session_name) } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } handle = lttng_create_handle(session_name, &dom); @@ -166,7 +133,7 @@ static int disable_channels(char *session_name) } /* Strip channel list */ - channel_name = strtok(opt_channels, ","); + channel_name = strtok(channel_list, ","); while (channel_name != NULL) { DBG("Disabling channel %s", channel_name); @@ -188,7 +155,8 @@ static int disable_channels(char *session_name) } else { MSG("%s channel %s disabled for session %s", - get_domain_str(dom.type), channel_name, session_name); + lttng_domain_type_str(dom.type), + channel_name, session_name); enabled = 0; success = 1; } @@ -239,6 +207,9 @@ int cmd_disable_channels(int argc, const char **argv) int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; + char *channel_list = NULL; + const char *arg_channel_list = NULL; + const char *leftover = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -246,7 +217,7 @@ int cmd_disable_channels(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stdout); + SHOW_HELP(); goto end; case OPT_USERSPACE: opt_userspace = 1; @@ -255,16 +226,35 @@ int cmd_disable_channels(int argc, const char **argv) list_cmd_options(stdout, long_options); goto end; default: - usage(stderr); ret = CMD_UNDEFINED; goto end; } } - opt_channels = (char*) poptGetArg(pc); - if (opt_channels == NULL) { - ERR("Missing channel name(s).\n"); - usage(stderr); + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace, false); + if (ret) { + ret = CMD_ERROR; + goto end; + } + + arg_channel_list = poptGetArg(pc); + if (arg_channel_list == NULL) { + ERR("Missing channel name(s)."); + ret = CMD_ERROR; + goto end; + } + + channel_list = strdup(arg_channel_list); + if (channel_list == NULL) { + PERROR("Failed to copy channel name"); + ret = CMD_ERROR; + goto end; + } + + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); ret = CMD_ERROR; goto end; } @@ -304,7 +294,7 @@ int cmd_disable_channels(int argc, const char **argv) } } - command_ret = disable_channels(session_name); + command_ret = disable_channels(session_name, channel_list); if (command_ret) { success = 0; } @@ -345,6 +335,8 @@ end: free(session_name); } + free(channel_list); + /* Overwrite ret if an error occurred in disable_channels */ ret = command_ret ? command_ret : ret;