Refactoring: move count to an output parameter
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 20 Nov 2019 19:40:22 +0000 (14:40 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 20 Dec 2019 05:31:04 +0000 (00:31 -0500)
This mimics what is done for lttng_rotation_schedules_get_count.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: I576d112de4a9bfa258a78cb52b8da8a5f25adefb
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/tracker.h
src/bin/lttng-sessiond/client.c
src/bin/lttng-sessiond/save.c
src/bin/lttng-sessiond/tracker.c
src/bin/lttng/commands/list.c
src/common/tracker.c
src/lib/lttng-ctl/lttng-ctl.c

index a66a2cfce4dea3701fd0cb53fe25329bdd12eb78..1da12f82be6909bbbf183e449a26fe9647b44530 100644 (file)
@@ -223,8 +223,12 @@ extern const struct lttng_tracker_id *lttng_tracker_ids_get_at_index(
 
 /*
  * Get the number of tracker id in a tracker id list.
+ *
+ * Return LTTNG_TRACKER_ID_STATUS on sucess,
+ * LTTNG_TRACKER_ID_STATUS_INVALID when passed invalid parameters.
  */
-extern int lttng_tracker_ids_get_count(const struct lttng_tracker_ids *ids);
+extern enum lttng_tracker_id_status lttng_tracker_ids_get_count(
+               const struct lttng_tracker_ids *ids, unsigned int *count);
 
 /*
  * Destroy a tracker id list.
index 8eff1650ebfe1036f83fced7929f0e136c044ffd..ed0498ffa91c96a36cda70f60da9a275e63b968c 100644 (file)
@@ -1569,7 +1569,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, i;
                struct lttng_dynamic_buffer buf;
 
                ret = cmd_list_tracker_ids(
@@ -1580,7 +1581,12 @@ error_add_context:
                        goto error;
                }
 
-               nr_ids = lttng_tracker_ids_get_count(ids);
+               status = lttng_tracker_ids_get_count(ids, &nr_ids);
+               if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+                       ret = LTTNG_ERR_INVALID;
+                       goto error_list_tracker;
+               }
+
                lttng_dynamic_buffer_init(&buf);
                for (i = 0; i < nr_ids; i++) {
                        const struct lttng_tracker_id *id;
index b95ee2df0f4bbbb27e2281fd694df51bbaee0455..395c0f65c145e882a5ae44918eed3e645d19f3fd 100644 (file)
@@ -1836,7 +1836,7 @@ static int save_id_tracker(struct config_writer *writer,
                enum lttng_tracker_type tracker_type)
 {
        int ret = LTTNG_OK;
-       size_t nr_ids = 0, i;
+       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;
@@ -1909,7 +1909,11 @@ static int save_id_tracker(struct config_writer *writer,
                goto end;
        }
 
-       nr_ids = lttng_tracker_ids_get_count(ids);
+       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);
index 48dc176c15374d2810532dfc3207aa0625882516..38bf8a473d70530488e25a1142e72d449ca44fbb 100644 (file)
@@ -493,14 +493,19 @@ error:
 int lttng_tracker_id_set_list(struct lttng_tracker_list *tracker_list,
                const struct lttng_tracker_ids *ids)
 {
-       size_t i, count;
+       unsigned int i, count;
        const struct lttng_tracker_id *id;
+       enum lttng_tracker_id_status status;
 
        assert(tracker_list);
        assert(ids);
 
        lttng_tracker_list_reset(tracker_list);
-       count = lttng_tracker_ids_get_count(ids);
+
+       status = lttng_tracker_ids_get_count(ids, &count);
+       if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+               return LTTNG_ERR_INVALID;
+       }
 
        if (count == 0) {
                /* Set state to "track none". */
index 229648e07cebe7018d2dfa80fc67151fff97a15c..2af59c433067a030da7c221cccb61b3c8b77f9cf 100644 (file)
@@ -1540,15 +1540,21 @@ static int list_tracker_ids(enum lttng_tracker_type tracker_type)
        int ret = 0;
        int enabled = 1;
        struct lttng_tracker_ids *ids = NULL;
-       size_t nr_ids, i;
+       unsigned int nr_ids, i;
        const struct lttng_tracker_id *id;
+       enum lttng_tracker_id_status status;
 
        ret = lttng_list_tracker_ids(handle, tracker_type, &ids);
        if (ret) {
                return ret;
        }
 
-       nr_ids = lttng_tracker_ids_get_count(ids);
+       status = lttng_tracker_ids_get_count(ids, &nr_ids);
+       if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+               ret = CMD_ERROR;
+               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) {
index 7742f47bcbdd88d9bb5bb67f51483ebff59a0cb1..afc253def71f990f77bb50923adde56bf481880e 100644 (file)
@@ -277,10 +277,19 @@ const struct lttng_tracker_id *lttng_tracker_ids_get_at_index(
        return lttng_tracker_ids_get_pointer_of_index(ids, index);
 }
 
-int lttng_tracker_ids_get_count(const struct lttng_tracker_ids *ids)
+int lttng_tracker_ids_get_count(const struct lttng_tracker_ids *ids, unsigned int *count)
 {
-       assert(ids);
-       return ids->count;
+
+       enum lttng_tracker_id_status status = LTTNG_ROTATION_STATUS_OK;
+
+       if (!ids || !count) {
+               status = LTTNG_ROTATION_STATUS_INVALID;
+               goto end;
+       }
+
+       *count = ids->count;
+end:
+       return status;
 }
 
 void lttng_tracker_ids_destroy(struct lttng_tracker_ids *ids)
index 88daf45aa40140bcc38715271cd4dd655c6c3a2e..cfe4371186447a1bbe51f8676e59550c7b7efcf3 100644 (file)
@@ -2943,7 +2943,7 @@ int lttng_list_tracker_pids(struct lttng_handle *handle,
                int *_enabled, int32_t **_pids, size_t *_nr_pids)
 {
        struct lttng_tracker_ids *ids = NULL;
-       size_t nr_ids = 0;
+       unsigned int nr_ids = 0;
        int *pids = NULL;
        int ret = 0, i;
        enum lttng_tracker_id_status status;
@@ -2954,7 +2954,11 @@ int lttng_list_tracker_pids(struct lttng_handle *handle,
                return ret;
        }
 
-       nr_ids = lttng_tracker_ids_get_count(ids);
+       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);
This page took 0.046144 seconds and 4 git commands to generate.