SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.c
index f64f51c280d670b9b83070abb6e2666d97ce51e2..ebb9ca47450980e72ad0245c0e99e5b2eae41467 100644 (file)
@@ -1,19 +1,9 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
- * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 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
@@ -918,8 +908,7 @@ int trace_ust_track_id(enum lttng_tracker_type tracker_type,
        struct ust_id_tracker *id_tracker;
        struct lttng_tracker_list *tracker_list;
        int value;
-       struct lttng_tracker_id *saved_ids;
-       ssize_t saved_ids_count, i;
+       struct lttng_tracker_ids *saved_ids;
 
        if (tracker_type == LTTNG_TRACKER_PID) {
                DBG("Backward compatible behavior: translate PID tracker to VPID tracker for UST domain.");
@@ -935,8 +924,8 @@ int trace_ust_track_id(enum lttng_tracker_type tracker_type,
                return LTTNG_ERR_INVALID;
        }
        /* Save list for restore on error. */
-       saved_ids_count = lttng_tracker_id_get_list(tracker_list, &saved_ids);
-       if (saved_ids_count < 0) {
+       retval = lttng_tracker_id_get_list(tracker_list, &saved_ids);
+       if (retval != LTTNG_OK) {
                return LTTNG_ERR_INVALID;
        }
        /* Add to list. */
@@ -992,20 +981,17 @@ int trace_ust_track_id(enum lttng_tracker_type tracker_type,
                }
        }
        if (should_update_apps && session->active) {
+               /* TODO: should tokens be affected by tracking? */
                ust_app_global_update_all(session);
        }
        goto end;
 
 end_restore:
-       if (lttng_tracker_id_set_list(tracker_list, saved_ids,
-                           saved_ids_count) != LTTNG_OK) {
+       if (lttng_tracker_id_set_list(tracker_list, saved_ids) != LTTNG_OK) {
                ERR("Error on tracker add error handling.\n");
        }
 end:
-       for (i = 0; i < saved_ids_count; i++) {
-               free(saved_ids[i].string);
-       }
-       free(saved_ids);
+       lttng_tracker_ids_destroy(saved_ids);
        return retval;
 }
 
@@ -1021,8 +1007,7 @@ int trace_ust_untrack_id(enum lttng_tracker_type tracker_type,
        struct ust_id_tracker *id_tracker;
        struct lttng_tracker_list *tracker_list;
        int value;
-       struct lttng_tracker_id *saved_ids;
-       ssize_t saved_ids_count, i;
+       struct lttng_tracker_ids *saved_ids;
 
        if (tracker_type == LTTNG_TRACKER_PID) {
                DBG("Backward compatible behavior: translate PID tracker to VPID tracker for UST domain.");
@@ -1039,8 +1024,8 @@ int trace_ust_untrack_id(enum lttng_tracker_type tracker_type,
                return LTTNG_ERR_INVALID;
        }
        /* Save list for restore on error. */
-       saved_ids_count = lttng_tracker_id_get_list(tracker_list, &saved_ids);
-       if (saved_ids_count < 0) {
+       retval = lttng_tracker_id_get_list(tracker_list, &saved_ids);
+       if (retval != LTTNG_OK) {
                return LTTNG_ERR_INVALID;
        }
        /* Remove from list. */
@@ -1097,30 +1082,28 @@ int trace_ust_untrack_id(enum lttng_tracker_type tracker_type,
                }
        }
        if (should_update_apps && session->active) {
+               /* TODO should tokens be affected by tracker */
                ust_app_global_update_all(session);
        }
        goto end;
 
 end_restore:
-       if (lttng_tracker_id_set_list(tracker_list, saved_ids,
-                           saved_ids_count) != LTTNG_OK) {
+       if (lttng_tracker_id_set_list(tracker_list, saved_ids) != LTTNG_OK) {
                ERR("Error on tracker remove error handling.\n");
        }
 end:
-       for (i = 0; i < saved_ids_count; i++) {
-               free(saved_ids[i].string);
-       }
-       free(saved_ids);
+       lttng_tracker_ids_destroy(saved_ids);
        return retval;
 }
 
 /*
  * Called with session lock held.
  */
-ssize_t trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type,
+int trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type,
                struct ltt_ust_session *session,
-               struct lttng_tracker_id **_ids)
+               struct lttng_tracker_ids **_ids)
 {
+       int ret = LTTNG_OK;
        struct lttng_tracker_list *tracker_list;
 
        if (tracker_type == LTTNG_TRACKER_PID) {
@@ -1130,9 +1113,17 @@ ssize_t trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type,
 
        tracker_list = get_id_tracker_list(session, tracker_type);
        if (!tracker_list) {
-               return -LTTNG_ERR_INVALID;
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       ret = lttng_tracker_id_get_list(tracker_list, _ids);
+       if (ret != LTTNG_OK) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
        }
-       return lttng_tracker_id_get_list(tracker_list, _ids);
+end:
+       return ret;
 }
 
 /*
This page took 0.027251 seconds and 5 git commands to generate.