X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Flist.c;h=51434a3eb37982c4d613775b293df7b897242333;hb=de3323397026157322a512b6755792fe153ad17f;hp=226eb4c871da31102c9a2c096c49442e7ad2dd38;hpb=0dda67289b8a86fd3f117d644f00f2985d399208;p=lttng-tools.git diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 226eb4c87..51434a3eb 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.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 @@ -26,6 +16,7 @@ #include #include #include +#include #include "../command.h" @@ -1538,16 +1529,29 @@ static int list_tracker_ids(enum lttng_tracker_type tracker_type) { int ret = 0; int enabled = 1; - struct lttng_tracker_id *ids = NULL; - size_t nr_ids, i; + struct lttng_tracker_ids *ids = NULL; + unsigned int nr_ids, i; + const struct lttng_tracker_id *id; + enum lttng_tracker_id_status status; - ret = lttng_list_tracker_ids(handle, tracker_type, &ids, &nr_ids); + ret = lttng_list_tracker_ids(handle, tracker_type, &ids); if (ret) { return ret; } - if (nr_ids == 1 && ids[0].type == LTTNG_ID_ALL) { - enabled = 0; + + status = lttng_tracker_ids_get_count(ids, &nr_ids); + if (status != LTTNG_TRACKER_ID_STATUS_OK) { + ret = CMD_ERROR; + goto end; + } + + if (nr_ids == 1) { + id = lttng_tracker_ids_get_at_index(ids, 0); + if (id && lttng_tracker_id_get_type(id) == LTTNG_ID_ALL) { + enabled = 0; + } } + if (enabled) { _MSG("%s tracker: [", get_tracker_str(tracker_type)); @@ -1561,23 +1565,55 @@ static int list_tracker_ids(enum lttng_tracker_type tracker_type) } for (i = 0; i < nr_ids; i++) { - struct lttng_tracker_id *id = &ids[i]; + enum lttng_tracker_id_status status = + LTTNG_TRACKER_ID_STATUS_OK; + int value; + const char *value_string; + + id = lttng_tracker_ids_get_at_index(ids, i); + if (!id) { + ret = CMD_ERROR; + goto end; + } + + switch (lttng_tracker_id_get_type(id)) { + case LTTNG_ID_ALL: + break; + case LTTNG_ID_VALUE: + status = lttng_tracker_id_get_value(id, &value); + break; + case LTTNG_ID_STRING: + status = lttng_tracker_id_get_string( + id, &value_string); + break; + case LTTNG_ID_UNKNOWN: + ret = CMD_ERROR; + goto end; + } + + if (status != LTTNG_TRACKER_ID_STATUS_OK) { + ERR("Invalid state for tracker id"); + ret = CMD_ERROR; + goto end; + } if (i) { _MSG(","); } - switch (id->type) { + switch (lttng_tracker_id_get_type(id)) { case LTTNG_ID_ALL: _MSG(" *"); break; case LTTNG_ID_VALUE: - _MSG(" %d", ids[i].value); + _MSG(" %d", value); break; case LTTNG_ID_STRING: - _MSG(" %s", ids[i].string); + _MSG(" %s", value_string); break; case LTTNG_ID_UNKNOWN: - return CMD_ERROR; + ERR("Invalid state for tracker id"); + ret = CMD_ERROR; + goto end; } /* Mi */ @@ -1600,10 +1636,7 @@ static int list_tracker_ids(enum lttng_tracker_type tracker_type) } } end: - for (i = 0; i < nr_ids; i++) { - free(ids[i].string); - } - free(ids); + lttng_tracker_ids_destroy(ids); return ret; }