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>
/*
* 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.
{
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(
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;
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;
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);
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". */
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) {
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)
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;
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);