/*
- * Copyright (C) 2014 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
- * 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
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;
+ const struct lttng_tracker_id *id;
+ enum lttng_tracker_id_status status;
+ int value;
+ const char *string;
switch (tracker_type) {
case LTTNG_TRACKER_PID:
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;
}
}
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;
}
goto end;
}
- if (nr_ids == 1 && ids[0].type == 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;
} else {
/* Tracking list. */
for (i = 0; i < nr_ids; i++) {
- switch (ids[i].type) {
+ 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(
writer, element_target_id);
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
+ status = lttng_tracker_id_get_value(id, &value);
ret = config_writer_write_element_unsigned_int(
- writer, element_id,
- ids[i].value);
+ writer, element_id, value);
break;
case LTTNG_ID_STRING:
ret = config_writer_open_element(
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
+ status = lttng_tracker_id_get_string(
+ id, &string);
ret = config_writer_write_element_string(writer,
- config_element_name,
- ids[i].string);
+ config_element_name, string);
break;
default:
/* Unexpected. */
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
+ if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
/* /$element_target_id */
ret = config_writer_close_element(writer);
ret = LTTNG_OK;
end:
- free(ids);
+ lttng_tracker_ids_destroy(ids);
return ret;
}