Move to kernel style SPDX license identifiers
[lttng-tools.git] / src / bin / lttng-sessiond / client.c
index 8eff1650ebfe1036f83fced7929f0e136c044ffd..ae0e020924b38b1929d97a1857c27eb382d5826a 100644 (file)
@@ -1,20 +1,10 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
- *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *               2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2013 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.
  */
 
 #include <stddef.h>
@@ -28,6 +18,7 @@
 #include <lttng/event-internal.h>
 #include <lttng/session-internal.h>
 #include <lttng/session-descriptor-internal.h>
+#include <lttng/tracker-internal.h>
 
 #include "client.h"
 #include "lttng-sessiond.h"
@@ -1569,7 +1560,8 @@ error_add_context:
        {
                struct lttcomm_tracker_command_header cmd_header;
                struct lttng_tracker_ids *ids = NULL;
-               size_t nr_ids, i;
+               enum lttng_tracker_id_status status;
+               unsigned int nr_ids;
                struct lttng_dynamic_buffer buf;
 
                ret = cmd_list_tracker_ids(
@@ -1580,72 +1572,28 @@ error_add_context:
                        goto error;
                }
 
-               nr_ids = lttng_tracker_ids_get_count(ids);
                lttng_dynamic_buffer_init(&buf);
-               for (i = 0; i < nr_ids; i++) {
-                       const struct lttng_tracker_id *id;
-                       struct lttcomm_tracker_id_header id_hdr;
-                       size_t var_data_len = 0;
-                       enum lttng_tracker_id_status status;
-                       const char *string;
-                       int value;
-
-                       id = lttng_tracker_ids_get_at_index(ids, i);
-                       if (!id) {
-                               ret = LTTNG_ERR_INVALID;
-                               goto error_list_tracker;
-                       }
 
-                       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);
                lttng_dynamic_buffer_reset(&buf);
                if (ret < 0) {
-                       goto setup_error;
+                       goto error;
                }
 
                ret = LTTNG_OK;
This page took 0.027239 seconds and 5 git commands to generate.