X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Ftrack-untrack.c;h=24e2d02aeb50e1f6ffb9c5eb3864913b84547715;hp=0d716972980701009bb389a14e89ae38a62a04e5;hb=refs%2Fheads%2Fsow-2019-0002-rev1;hpb=72aee8ec709045acec9c7e5f5574fe334cf03ad6 diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index 0d7169729..24e2d02ae 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -1,24 +1,15 @@ /* - * Copyright (C) 2011 - David Goulet - * Copyright (C) 2015 - Mathieu Desnoyers + * Copyright (C) 2011 David Goulet + * Copyright (C) 2015 Mathieu Desnoyers * - * 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 #include #include +#include #include #include #include @@ -460,7 +451,7 @@ static enum cmd_error_code track_untrack_id(enum cmd_type cmd_type, ret = cmd_func(handle, tracker_type, item); if (ret) { - char *msg = NULL; + const char *msg = NULL; switch (-ret) { case LTTNG_ERR_ID_TRACKED: @@ -591,9 +582,11 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, int argc, const char **argv, const char *help_msg) { int opt, ret = 0, success = 1; + bool opt_all_present = false; enum cmd_error_code command_ret = CMD_SUCCESS; static poptContext pc; char *session_name = NULL; + const char *leftover = NULL; struct mi_writer *writer = NULL; if (argc < 1) { @@ -669,29 +662,7 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, type_state = STATE_VGID; break; case OPT_ALL: - switch (type_state) { - case STATE_PID: - opt_pid.all = 1; - break; - case STATE_VPID: - opt_vpid.all = 1; - break; - case STATE_UID: - opt_uid.all = 1; - break; - case STATE_VUID: - opt_vuid.all = 1; - break; - case STATE_GID: - opt_gid.all = 1; - break; - case STATE_VGID: - opt_vgid.all = 1; - break; - default: - command_ret = CMD_ERROR; - goto end; - } + opt_all_present = true; break; default: command_ret = CMD_UNDEFINED; @@ -705,6 +676,36 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, goto end; } + /* + * If the `--all` option is present set the appropriate tracker's `all` + * field. + */ + if (opt_all_present) { + switch (type_state) { + case STATE_PID: + opt_pid.all = 1; + break; + case STATE_VPID: + opt_vpid.all = 1; + break; + case STATE_UID: + opt_uid.all = 1; + break; + case STATE_VUID: + opt_vuid.all = 1; + break; + case STATE_GID: + opt_gid.all = 1; + break; + case STATE_VGID: + opt_vgid.all = 1; + break; + default: + command_ret = CMD_ERROR; + goto end; + } + } + if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { @@ -715,6 +716,13 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, session_name = opt_session_name; } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);