lttng: list: replace domain headers with the official names
[lttng-tools.git] / src / bin / lttng-sessiond / save.c
index 59715d0b9d4324152641ff7b620112ad9f62bad1..f01c3186bf313864952610fca304f559f3b9bc08 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * 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
@@ -1836,9 +1826,13 @@ 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;
+       const struct lttng_tracker_id *id;
+       enum lttng_tracker_id_status status;
+       int value;
+       const char *string;
 
        switch (tracker_type) {
        case LTTNG_TRACKER_PID:
@@ -1879,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;
                }
@@ -1889,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;
                }
@@ -1905,12 +1899,21 @@ static int save_id_tracker(struct config_writer *writer,
                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;
@@ -1940,7 +1943,12 @@ static int save_id_tracker(struct config_writer *writer,
        } 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);
@@ -1948,9 +1956,9 @@ static int save_id_tracker(struct config_writer *writer,
                                        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(
@@ -1959,9 +1967,10 @@ static int save_id_tracker(struct config_writer *writer,
                                        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. */
@@ -1972,6 +1981,10 @@ static int save_id_tracker(struct config_writer *writer,
                                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);
@@ -1998,7 +2011,7 @@ static int save_id_tracker(struct config_writer *writer,
 
        ret = LTTNG_OK;
 end:
-       free(ids);
+       lttng_tracker_ids_destroy(ids);
        return ret;
 }
 
This page took 0.026357 seconds and 4 git commands to generate.