X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fclient.c;h=ae0e020924b38b1929d97a1857c27eb382d5826a;hp=2c7bd4787c9371305455dfa7765ab9397d07877f;hb=ab5be9fa2eb5ba9600a82cd18fd3cfcbac69169a;hpb=2d97a0067600335f07eecb2c1d9ba68fc164583e diff --git a/src/bin/lttng-sessiond/client.c b/src/bin/lttng-sessiond/client.c index 2c7bd4787..ae0e02092 100644 --- a/src/bin/lttng-sessiond/client.c +++ b/src/bin/lttng-sessiond/client.c @@ -1,20 +1,10 @@ /* - * Copyright (C) 2011 - David Goulet - * Mathieu Desnoyers - * 2013 - Jérémie Galarneau + * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 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. */ #include @@ -28,6 +18,7 @@ #include #include #include +#include #include "client.h" #include "lttng-sessiond.h" @@ -1568,80 +1559,41 @@ error_add_context: case LTTNG_LIST_TRACKER_IDS: { struct lttcomm_tracker_command_header cmd_header; - struct lttng_tracker_id **ids = NULL; - ssize_t nr_ids, i; + struct lttng_tracker_ids *ids = NULL; + enum lttng_tracker_id_status status; + unsigned int nr_ids; struct lttng_dynamic_buffer buf; - nr_ids = cmd_list_tracker_ids( + ret = cmd_list_tracker_ids( cmd_ctx->lsm->u.id_tracker.tracker_type, cmd_ctx->session, cmd_ctx->lsm->domain.type, &ids); - if (nr_ids < 0) { - /* Return value is a negative lttng_error_code. */ - ret = -nr_ids; + if (ret != LTTNG_OK) { goto error; } lttng_dynamic_buffer_init(&buf); - for (i = 0; i < nr_ids; i++) { - struct lttng_tracker_id *id = ids[i]; - struct lttcomm_tracker_id_header id_hdr; - size_t var_data_len = 0; - enum lttng_tracker_id_status status; - const char *string; - int value; - - memset(&id_hdr, 0, sizeof(id_hdr)); - id_hdr.type = lttng_tracker_id_get_type(id); - switch (id_hdr.type) { - case LTTNG_ID_ALL: - break; - case LTTNG_ID_VALUE: - status = lttng_tracker_id_get_value(id, &value); - id_hdr.u.value = value; - if (status != LTTNG_TRACKER_ID_STATUS_OK) { - ret = LTTNG_ERR_INVALID; - goto error_list_tracker; - } - break; - case LTTNG_ID_STRING: - status = lttng_tracker_id_get_string( - id, &string); - if (status != LTTNG_TRACKER_ID_STATUS_OK) { - ret = LTTNG_ERR_INVALID; - goto error_list_tracker; - } - id_hdr.u.var_data_len = var_data_len = - strlen(string) + 1; - break; - default: - ret = LTTNG_ERR_INVALID; - goto error_list_tracker; - } - ret = lttng_dynamic_buffer_append( - &buf, &id_hdr, sizeof(id_hdr)); - if (ret) { - ret = LTTNG_ERR_NOMEM; - goto error_list_tracker; - } - ret = lttng_dynamic_buffer_append( - &buf, string, var_data_len); - if (ret) { - ret = LTTNG_ERR_NOMEM; - goto error_list_tracker; - } + status = lttng_tracker_ids_get_count(ids, &nr_ids); + if (status != LTTNG_TRACKER_ID_STATUS_OK) { + ret = -LTTNG_ERR_INVALID; + goto error_list_tracker; } cmd_header.nb_tracker_id = nr_ids; + + ret = lttng_tracker_ids_serialize(ids, &buf); + if (ret < 0) { + goto error_list_tracker; + } + ret = setup_lttng_msg(cmd_ctx, buf.data, buf.size, &cmd_header, sizeof(cmd_header)); error_list_tracker: - lttng_tracker_ids_destroy(ids, nr_ids); - free(ids); + lttng_tracker_ids_destroy(ids); lttng_dynamic_buffer_reset(&buf); if (ret < 0) { - goto setup_error; + goto error; } ret = LTTNG_OK;