From: Jonathan Rajotte Date: Wed, 20 Nov 2019 19:40:22 +0000 (-0500) Subject: Refactoring: move count to an output parameter X-Git-Tag: v2.12.0-rc1~93 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e283e4a062cc16b5839a8a479e12498789320b5e;p=lttng-tools.git Refactoring: move count to an output parameter This mimics what is done for lttng_rotation_schedules_get_count. Signed-off-by: Jonathan Rajotte Change-Id: I576d112de4a9bfa258a78cb52b8da8a5f25adefb Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/tracker.h b/include/lttng/tracker.h index a66a2cfce..1da12f82b 100644 --- a/include/lttng/tracker.h +++ b/include/lttng/tracker.h @@ -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. diff --git a/src/bin/lttng-sessiond/client.c b/src/bin/lttng-sessiond/client.c index 8eff1650e..ed0498ffa 100644 --- a/src/bin/lttng-sessiond/client.c +++ b/src/bin/lttng-sessiond/client.c @@ -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; diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index b95ee2df0..395c0f65c 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -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); diff --git a/src/bin/lttng-sessiond/tracker.c b/src/bin/lttng-sessiond/tracker.c index 48dc176c1..38bf8a473 100644 --- a/src/bin/lttng-sessiond/tracker.c +++ b/src/bin/lttng-sessiond/tracker.c @@ -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". */ diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 229648e07..2af59c433 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -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) { diff --git a/src/common/tracker.c b/src/common/tracker.c index 7742f47bc..afc253def 100644 --- a/src/common/tracker.c +++ b/src/common/tracker.c @@ -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) diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 88daf45aa..cfe437118 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -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);