X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsave.c;h=f01c3186bf313864952610fca304f559f3b9bc08;hp=83019842d74c1e107d9581a6fa1c82ef296c3e2e;hb=ac41e67e39946acd97752ce52b964976890c5e87;hpb=2d97a0067600335f07eecb2c1d9ba68fc164583e diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 83019842d..f01c3186b 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2014 - Jérémie Galarneau + * Copyright (C) 2014 Jérémie Galarneau * - * 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 @@ -1836,10 +1826,10 @@ static int save_id_tracker(struct config_writer *writer, enum lttng_tracker_type tracker_type) { int ret = LTTNG_OK; - ssize_t nr_ids = 0, i; - struct lttng_tracker_id **ids = NULL; + unsigned int nr_ids, i; + struct lttng_tracker_ids *ids = NULL; const char *element_id_tracker, *element_target_id, *element_id; - struct lttng_tracker_id *id; + const struct lttng_tracker_id *id; enum lttng_tracker_id_status status; int value; const char *string; @@ -1883,9 +1873,9 @@ static int save_id_tracker(struct config_writer *writer, switch (domain) { case LTTNG_DOMAIN_KERNEL: { - nr_ids = kernel_list_tracker_ids( + ret = kernel_list_tracker_ids( tracker_type, sess->kernel_session, &ids); - if (nr_ids < 0) { + if (ret != LTTNG_OK) { ret = LTTNG_ERR_KERN_LIST_FAIL; goto end; } @@ -1893,9 +1883,9 @@ static int save_id_tracker(struct config_writer *writer, } case LTTNG_DOMAIN_UST: { - nr_ids = trace_ust_list_tracker_ids( + ret = trace_ust_list_tracker_ids( tracker_type, sess->ust_session, &ids); - if (nr_ids < 0) { + if (ret != LTTNG_OK) { ret = LTTNG_ERR_UST_LIST_FAIL; goto end; } @@ -1909,12 +1899,21 @@ static int save_id_tracker(struct config_writer *writer, goto end; } - if (nr_ids == 1 && lttng_tracker_id_get_type(ids[0]) == LTTNG_ID_ALL) { - /* Tracking all, nothing to output. */ - ret = LTTNG_OK; + status = lttng_tracker_ids_get_count(ids, &nr_ids); + if (status != LTTNG_TRACKER_ID_STATUS_OK) { + ret = LTTNG_ERR_INVALID; 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) { + /* Tracking all, nothing to output. */ + ret = LTTNG_OK; + goto end; + } + } + ret = config_writer_open_element(writer, element_id_tracker); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; @@ -1944,7 +1943,11 @@ static int save_id_tracker(struct config_writer *writer, } else { /* Tracking list. */ for (i = 0; i < nr_ids; i++) { - id = ids[i]; + id = lttng_tracker_ids_get_at_index(ids, i); + if (!id) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } switch (lttng_tracker_id_get_type(id)) { case LTTNG_ID_VALUE: ret = config_writer_open_element( @@ -2008,8 +2011,7 @@ static int save_id_tracker(struct config_writer *writer, ret = LTTNG_OK; end: - lttng_tracker_ids_destroy(ids, nr_ids); - free(ids); + lttng_tracker_ids_destroy(ids); return ret; }