char *string;
};
+struct lttng_tracker_ids {
+ struct lttng_tracker_id *id_array;
+ unsigned int count;
+};
+
LTTNG_HIDDEN
bool lttng_tracker_id_is_equal(const struct lttng_tracker_id *left,
const struct lttng_tracker_id *right);
+/*
+ * A copy acts like memcpy. It does not allocate new memory.
+ */
+LTTNG_HIDDEN
+int lttng_tracker_id_copy(struct lttng_tracker_id *dest,
+ const struct lttng_tracker_id *src);
+
+/*
+ * Duplicate an lttng_tracker_id.
+ * The returned object must be freed via lttng_tracker_id_destroy.
+ */
+LTTNG_HIDDEN
+struct lttng_tracker_id *lttng_tracker_id_duplicate(
+ const struct lttng_tracker_id *src);
+
+/*
+ * Allocate a new list of lttng_tracker_id.
+ * The returned object must be freed via lttng_tracker_ids_destroy.
+ */
+LTTNG_HIDDEN
+struct lttng_tracker_ids *lttng_tracker_ids_create(unsigned int base_count);
+
+/*
+ * Return the non-const pointer of an element at index "index" of a
+ * lttng_tracker_ids.
+ *
+ * The ownership of the lttng_tracker_id element is NOT transfered.
+ * The returned object can NOT be freed via lttng_tracker_id_destroy.
+ */
LTTNG_HIDDEN
-struct lttng_tracker_id *lttng_tracker_id_copy(
- const struct lttng_tracker_id *orig);
+struct lttng_tracker_id *lttng_tracker_ids_get_pointer_of_index(
+ const struct lttng_tracker_ids *list, unsigned int index);
#endif /* LTTNG_TRACKER_INTERNAL_H */
struct lttng_handle;
struct lttng_tracker_id;
+struct lttng_tracker_ids;
/*
* Create a tracker id for the passed tracker type.
extern enum lttng_tracker_id_status lttng_tracker_id_get_string(
const struct lttng_tracker_id *id, const char **value);
-/*
- * Destroys (frees) an array of tracker id.
- */
-extern void lttng_tracker_ids_destroy(
- struct lttng_tracker_id **ids, size_t nr_ids);
-
/*
* Add ID to session tracker.
*
* List IDs in the tracker.
*
* tracker_type is the type of tracker.
- * ids is set to an allocated array of IDs currently tracked.
- * On success, ids must be freed using lttng_tracker_id_destroy on each
- * constituent of the returned array or using lttng_tracker_ids_destroy.
- * nr_ids is set to the number of entries contained by the ids array.
+ * ids is set to an allocated lttng_tracker_ids representing IDs
+ * currently tracked.
+ * On success, caller is responsible for freeing ids
+ * using lttng_tracker_ids_destroy.
*
* Returns 0 on success, else a negative LTTng error code.
*/
extern int lttng_list_tracker_ids(struct lttng_handle *handle,
enum lttng_tracker_type tracker_type,
- struct lttng_tracker_id ***ids,
- size_t *nr_ids);
+ struct lttng_tracker_ids **ids);
/*
* Backward compatibility.
int32_t **pids,
size_t *nr_pids);
+/*
+ * Get a tracker id from the list at a given index.
+ *
+ * Note that the list maintains the ownership of the returned tracker id.
+ * It must not be destroyed by the user, nor should it be held beyond the
+ * lifetime of the tracker id list.
+ *
+ * Returns a tracker id, or NULL on error.
+ */
+extern const struct lttng_tracker_id *lttng_tracker_ids_get_at_index(
+ const struct lttng_tracker_ids *ids, unsigned int index);
+
+/*
+ * Get the number of tracker id in a tracker id list.
+ */
+extern int lttng_tracker_ids_get_count(const struct lttng_tracker_ids *ids);
+
+/*
+ * Destroy a tracker id list.
+ */
+extern void lttng_tracker_ids_destroy(struct lttng_tracker_ids *ids);
+
#ifdef __cplusplus
}
#endif
case LTTNG_LIST_TRACKER_IDS:
{
struct lttcomm_tracker_command_header cmd_header;
- struct lttng_tracker_id **ids = NULL;
- ssize_t nr_ids, i;
+ struct lttng_tracker_ids *ids = NULL;
+ size_t nr_ids, i;
struct lttng_dynamic_buffer buf;
- nr_ids = cmd_list_tracker_ids(
+ ret = cmd_list_tracker_ids(
cmd_ctx->lsm->u.id_tracker.tracker_type,
cmd_ctx->session, cmd_ctx->lsm->domain.type,
&ids);
- if (nr_ids < 0) {
- /* Return value is a negative lttng_error_code. */
- ret = -nr_ids;
+ if (ret != LTTNG_OK) {
goto error;
}
+ nr_ids = lttng_tracker_ids_get_count(ids);
lttng_dynamic_buffer_init(&buf);
for (i = 0; i < nr_ids; i++) {
- struct lttng_tracker_id *id = ids[i];
+ const struct lttng_tracker_id *id;
struct lttcomm_tracker_id_header id_hdr;
size_t var_data_len = 0;
enum lttng_tracker_id_status status;
const char *string;
int value;
+ id = lttng_tracker_ids_get_at_index(ids, i);
+ if (!id) {
+ ret = LTTNG_ERR_INVALID;
+ goto error_list_tracker;
+ }
+
memset(&id_hdr, 0, sizeof(id_hdr));
id_hdr.type = lttng_tracker_id_get_type(id);
switch (id_hdr.type) {
ret = setup_lttng_msg(cmd_ctx, buf.data, buf.size, &cmd_header,
sizeof(cmd_header));
error_list_tracker:
- lttng_tracker_ids_destroy(ids, nr_ids);
- free(ids);
+ lttng_tracker_ids_destroy(ids);
lttng_dynamic_buffer_reset(&buf);
if (ret < 0) {
goto setup_error;
*
* Called with session lock held.
*/
-ssize_t cmd_list_tracker_ids(enum lttng_tracker_type tracker_type,
+int cmd_list_tracker_ids(enum lttng_tracker_type tracker_type,
struct ltt_session *session,
enum lttng_domain_type domain,
- struct lttng_tracker_id ***ids)
+ struct lttng_tracker_ids **ids)
{
- int ret;
- ssize_t nr_pids = 0;
+ int ret = LTTNG_OK;
switch (domain) {
case LTTNG_DOMAIN_KERNEL:
struct ltt_kernel_session *ksess;
ksess = session->kernel_session;
- nr_pids = kernel_list_tracker_ids(tracker_type, ksess, ids);
- if (nr_pids < 0) {
- ret = LTTNG_ERR_KERN_LIST_FAIL;
+ ret = kernel_list_tracker_ids(tracker_type, ksess, ids);
+ if (ret != LTTNG_OK) {
+ ret = -LTTNG_ERR_KERN_LIST_FAIL;
goto error;
}
break;
struct ltt_ust_session *usess;
usess = session->ust_session;
- nr_pids = trace_ust_list_tracker_ids(tracker_type, usess, ids);
- if (nr_pids < 0) {
- ret = LTTNG_ERR_UST_LIST_FAIL;
+ ret = trace_ust_list_tracker_ids(tracker_type, usess, ids);
+ if (ret != LTTNG_OK) {
+ ret = -LTTNG_ERR_UST_LIST_FAIL;
goto error;
}
break;
case LTTNG_DOMAIN_JUL:
case LTTNG_DOMAIN_PYTHON:
default:
- ret = LTTNG_ERR_UND;
+ ret = -LTTNG_ERR_UND;
goto error;
}
- return nr_pids;
-
error:
/* Return negative value to differentiate return code */
- return -ret;
+ return ret;
}
/*
ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
struct lttng_snapshot_output **outputs);
ssize_t cmd_list_syscalls(struct lttng_event **events);
-ssize_t cmd_list_tracker_ids(enum lttng_tracker_type tracker_type,
+int cmd_list_tracker_ids(enum lttng_tracker_type tracker_type,
struct ltt_session *session,
enum lttng_domain_type domain,
- struct lttng_tracker_id ***ids);
+ struct lttng_tracker_ids **ids);
int cmd_data_pending(struct ltt_session *session);
{
int ret, value;
struct lttng_tracker_list *tracker_list;
- struct lttng_tracker_id **saved_ids;
- ssize_t saved_ids_count;
+ struct lttng_tracker_ids *saved_ids;
ret = lttng_tracker_id_lookup_string(tracker_type, id, &value);
if (ret != LTTNG_OK) {
}
/* Save list for restore on error. */
- saved_ids_count = lttng_tracker_id_get_list(tracker_list, &saved_ids);
- if (saved_ids_count < 0) {
+ ret = lttng_tracker_id_get_list(tracker_list, &saved_ids);
+ if (ret != LTTNG_OK) {
return LTTNG_ERR_INVALID;
}
break;
}
- 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:
- lttng_tracker_ids_destroy(saved_ids, saved_ids_count);
- free(saved_ids);
+ lttng_tracker_ids_destroy(saved_ids);
return ret;
}
{
int ret, value;
struct lttng_tracker_list *tracker_list;
- struct lttng_tracker_id **saved_ids;
- ssize_t saved_ids_count;
+ struct lttng_tracker_ids *saved_ids;
ret = lttng_tracker_id_lookup_string(tracker_type, id, &value);
if (ret != LTTNG_OK) {
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) {
+ ret = lttng_tracker_id_get_list(tracker_list, &saved_ids);
+ if (ret != LTTNG_OK) {
return LTTNG_ERR_INVALID;
}
/* Remove from list. */
break;
}
- 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:
- lttng_tracker_ids_destroy(saved_ids, saved_ids_count);
- free(saved_ids);
+ lttng_tracker_ids_destroy(saved_ids);
return ret;
}
/*
* Called with session lock held.
*/
-ssize_t kernel_list_tracker_ids(enum lttng_tracker_type tracker_type,
+int kernel_list_tracker_ids(enum lttng_tracker_type tracker_type,
struct ltt_kernel_session *session,
- struct lttng_tracker_id ***_ids)
+ struct lttng_tracker_ids **_ids)
{
+ int ret = 0;
struct lttng_tracker_list *tracker_list;
tracker_list = get_id_tracker_list(session, tracker_type);
if (!tracker_list) {
- return -LTTNG_ERR_INVALID;
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
}
- return lttng_tracker_id_get_list(tracker_list, _ids);
+
+ ret = lttng_tracker_id_get_list(tracker_list, _ids);
+ if (ret != LTTNG_OK) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+
+end:
+ return ret;
}
/*
enum lttng_error_code kernel_clear_session(struct ltt_session *session);
int init_kernel_workarounds(void);
-ssize_t kernel_list_tracker_ids(enum lttng_tracker_type tracker_type,
+int kernel_list_tracker_ids(enum lttng_tracker_type tracker_type,
struct ltt_kernel_session *session,
- struct lttng_tracker_id ***_ids);
+ struct lttng_tracker_ids **ids);
int kernel_supports_ring_buffer_snapshot_sample_positions(void);
int kernel_supports_ring_buffer_packet_sequence_number(void);
int init_kernel_tracer(void);
enum lttng_tracker_type tracker_type)
{
int ret = LTTNG_OK;
- ssize_t nr_ids = 0, i;
- struct lttng_tracker_id **ids = NULL;
+ size_t nr_ids = 0, i;
+ struct lttng_tracker_ids *ids = NULL;
const char *element_id_tracker, *element_target_id, *element_id;
- struct lttng_tracker_id *id;
+ const struct lttng_tracker_id *id;
enum lttng_tracker_id_status status;
int value;
const char *string;
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;
}
}
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;
}
goto end;
}
- if (nr_ids == 1 && lttng_tracker_id_get_type(ids[0]) == LTTNG_ID_ALL) {
- /* Tracking all, nothing to output. */
- ret = LTTNG_OK;
- goto end;
+ nr_ids = lttng_tracker_ids_get_count(ids);
+
+ 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);
} else {
/* Tracking list. */
for (i = 0; i < nr_ids; i++) {
- id = ids[i];
+ 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(
ret = LTTNG_OK;
end:
- lttng_tracker_ids_destroy(ids, nr_ids);
- free(ids);
+ lttng_tracker_ids_destroy(ids);
return ret;
}
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;
+ 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.");
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. */
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:
- lttng_tracker_ids_destroy(saved_ids, saved_ids_count);
- free(saved_ids);
+ lttng_tracker_ids_destroy(saved_ids);
return retval;
}
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;
+ 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.");
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. */
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:
- lttng_tracker_ids_destroy(saved_ids, saved_ids_count);
- 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) {
tracker_list = get_id_tracker_list(session, tracker_type);
if (!tracker_list) {
- return -LTTNG_ERR_INVALID;
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
}
- return lttng_tracker_id_get_list(tracker_list, _ids);
+
+ ret = lttng_tracker_id_get_list(tracker_list, _ids);
+ if (ret != LTTNG_OK) {
+ ret = -LTTNG_ERR_INVALID;
+ goto end;
+ }
+end:
+ return ret;
}
/*
struct ltt_ust_session *session,
int id);
-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);
#else /* HAVE_LIBLTTNG_UST_CTL */
{
return 0;
}
-static inline ssize_t trace_ust_list_tracker_ids(
+static inline 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)
{
return -1;
}
goto error;
}
- n->id = lttng_tracker_id_copy(_id);
+ n->id = lttng_tracker_id_duplicate(_id);
if (!n->id) {
ret = LTTNG_ERR_NOMEM;
goto error;
* Protected by session mutex held by caller.
* On success, _ids and the ids it contains must be freed by the caller.
*/
-ssize_t lttng_tracker_id_get_list(const struct lttng_tracker_list *tracker_list,
- struct lttng_tracker_id ***_ids)
+int lttng_tracker_id_get_list(const struct lttng_tracker_list *tracker_list,
+ struct lttng_tracker_ids **_ids)
{
+ int retval = LTTNG_OK, ret;
struct lttng_tracker_list_node *n;
- ssize_t count = 0, i = 0, retval = 0;
- struct lttng_tracker_id **ids;
+ ssize_t count = 0, i = 0;
+ struct lttng_tracker_ids *ids = NULL;
+ struct lttng_tracker_id *id;
enum lttng_tracker_id_status status;
switch (tracker_list->state) {
n, &tracker_list->list_head, list_node) {
count++;
}
- ids = zmalloc(sizeof(*ids) * count);
+ ids = lttng_tracker_ids_create(count);
if (ids == NULL) {
PERROR("Failed to allocate tracked ID list");
retval = -LTTNG_ERR_NOMEM;
}
cds_list_for_each_entry (
n, &tracker_list->list_head, list_node) {
- ids[i] = lttng_tracker_id_copy(n->id);
- if (!ids[i]) {
+ id = lttng_tracker_ids_get_pointer_of_index(ids, i);
+ if (!id) {
+ retval = -LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ ret = lttng_tracker_id_copy(id, n->id);
+ if (ret) {
retval = -LTTNG_ERR_NOMEM;
goto error;
}
i++;
}
- *_ids = ids;
- retval = count;
break;
case LTTNG_TRACK_ALL:
- ids = zmalloc(sizeof(*ids));
+
+ ids = lttng_tracker_ids_create(1);
if (ids == NULL) {
PERROR("Failed to allocate tracked ID list");
retval = -LTTNG_ERR_NOMEM;
goto end;
}
- ids[0] = lttng_tracker_id_create();
- status = lttng_tracker_id_set_all(ids[0]);
+
+ id = lttng_tracker_ids_get_pointer_of_index(ids, 0);
+ status = lttng_tracker_id_set_all(id);
if (status != LTTNG_TRACKER_ID_STATUS_OK) {
ERR("Invalid tracker id for track all");
retval = -LTTNG_ERR_INVALID;
goto error;
}
- *_ids = ids;
- retval = 1;
break;
case LTTNG_TRACK_NONE:
- /* No ids track, so we return 0 element. */
- *_ids = NULL;
+ /* No ids track, so we return 0 element collection. */
+ ids = lttng_tracker_ids_create(0);
+ if (ids == NULL) {
+ PERROR("alloc list ids");
+ retval = -LTTNG_ERR_NOMEM;
+ goto end;
+ }
break;
}
+ *_ids = ids;
+
end:
return retval;
error:
- lttng_tracker_ids_destroy(ids, count);
- free(ids);
+ lttng_tracker_ids_destroy(ids);
return retval;
}
int lttng_tracker_id_set_list(struct lttng_tracker_list *tracker_list,
- struct lttng_tracker_id **_ids,
- size_t count)
+ const struct lttng_tracker_ids *ids)
{
- size_t i;
+ size_t i, count;
+ const struct lttng_tracker_id *id;
+
+ assert(tracker_list);
+ assert(ids);
lttng_tracker_list_reset(tracker_list);
- if (count == 1 && lttng_tracker_id_get_type(_ids[0])) {
- /* Track all. */
- return LTTNG_OK;
- }
+ count = lttng_tracker_ids_get_count(ids);
+
if (count == 0) {
/* Set state to "track none". */
tracker_list->state = LTTNG_TRACK_NONE;
return LTTNG_OK;
}
+
+ if (count == 1) {
+ id = lttng_tracker_ids_get_at_index(ids, 0);
+ if (lttng_tracker_id_get_type(id) == LTTNG_ID_ALL) {
+ /* Track all. */
+ return LTTNG_OK;
+ }
+ }
+
for (i = 0; i < count; i++) {
- struct lttng_tracker_id *id = _ids[i];
int ret;
-
+ id = lttng_tracker_ids_get_at_index(ids, i);
ret = lttng_tracker_list_add(tracker_list, id);
if (ret != LTTNG_OK) {
return ret;
int lttng_tracker_id_lookup_string(enum lttng_tracker_type tracker_type,
const struct lttng_tracker_id *id,
int *result);
-ssize_t lttng_tracker_id_get_list(const struct lttng_tracker_list *tracker_list,
- struct lttng_tracker_id ***_ids);
+int lttng_tracker_id_get_list(const struct lttng_tracker_list *tracker_list,
+ struct lttng_tracker_ids **_ids);
int lttng_tracker_id_set_list(struct lttng_tracker_list *tracker_list,
- struct lttng_tracker_id **_ids,
- size_t count);
+ const struct lttng_tracker_ids *_ids);
#endif /* _LTT_TRACKER_H */
{
int ret = 0;
int enabled = 1;
- struct lttng_tracker_id **ids = NULL;
+ struct lttng_tracker_ids *ids = NULL;
size_t nr_ids, i;
+ const struct lttng_tracker_id *id;
- ret = lttng_list_tracker_ids(handle, tracker_type, &ids, &nr_ids);
+ ret = lttng_list_tracker_ids(handle, tracker_type, &ids);
if (ret) {
return ret;
}
- if (nr_ids == 1 && lttng_tracker_id_get_type(ids[0]) == LTTNG_ID_ALL) {
- enabled = 0;
+
+ nr_ids = lttng_tracker_ids_get_count(ids);
+ if (nr_ids == 1) {
+ id = lttng_tracker_ids_get_at_index(ids, 0);
+ if (id && lttng_tracker_id_get_type(id) == LTTNG_ID_ALL) {
+ enabled = 0;
+ }
}
+
if (enabled) {
_MSG("%s tracker: [", get_tracker_str(tracker_type));
}
for (i = 0; i < nr_ids; i++) {
- struct lttng_tracker_id *id = ids[i];
- enum lttng_tracker_id_status status;
+ enum lttng_tracker_id_status status =
+ LTTNG_TRACKER_ID_STATUS_OK;
int value;
const char *value_string;
+ id = lttng_tracker_ids_get_at_index(ids, i);
+ if (!id) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
switch (lttng_tracker_id_get_type(id)) {
case LTTNG_ID_ALL:
break;
}
}
end:
- lttng_tracker_ids_destroy(ids, nr_ids);
+ lttng_tracker_ids_destroy(ids);
return ret;
}
LTTNG_HIDDEN
int mi_lttng_id_target(struct mi_writer *writer,
enum lttng_tracker_type tracker_type,
- struct lttng_tracker_id *id,
+ const struct lttng_tracker_id *id,
int is_open)
{
int ret;
*/
int mi_lttng_id_target(struct mi_writer *writer,
enum lttng_tracker_type tracker_type,
- struct lttng_tracker_id *id,
+ const struct lttng_tracker_id *id,
int is_open);
/*
return LTTNG_TRACKER_ID_STATUS_OK;
}
-void lttng_tracker_id_destroy(struct lttng_tracker_id *id)
+static void lttng_tracker_id_reset(struct lttng_tracker_id *id)
{
if (id == NULL) {
return;
if (id->string != NULL) {
free(id->string);
+ id->string = NULL;
}
- free(id);
+ id->type = LTTNG_ID_UNKNOWN;
+ id->value = -1;
}
-void lttng_tracker_ids_destroy(struct lttng_tracker_id **ids, size_t nr_ids)
+void lttng_tracker_id_destroy(struct lttng_tracker_id *id)
{
- if (ids == NULL) {
+ if (id == NULL) {
return;
}
- for (int i = 0; i < nr_ids; i++) {
- lttng_tracker_id_destroy(ids[i]);
- }
+ lttng_tracker_id_reset(id);
+
+ free(id);
}
enum lttng_tracker_id_type lttng_tracker_id_get_type(
return 1;
}
-struct lttng_tracker_id *lttng_tracker_id_copy(
+int lttng_tracker_id_copy(struct lttng_tracker_id *dest,
const struct lttng_tracker_id *orig)
{
- struct lttng_tracker_id *copy = NULL;
+ int ret = 0;
enum lttng_tracker_id_status status;
- copy = lttng_tracker_id_create();
- if (copy == NULL) {
- goto error;
- }
+ assert(dest);
+ assert(orig);
switch (orig->type) {
case LTTNG_ID_ALL:
- status = lttng_tracker_id_set_all(copy);
+ status = lttng_tracker_id_set_all(dest);
break;
case LTTNG_ID_VALUE:
- status = lttng_tracker_id_set_value(copy, orig->value);
- if (status != LTTNG_TRACKER_ID_STATUS_OK) {
- goto error;
- }
+ status = lttng_tracker_id_set_value(dest, orig->value);
break;
case LTTNG_ID_STRING:
- status = lttng_tracker_id_set_string(copy, orig->string);
- if (status != LTTNG_TRACKER_ID_STATUS_OK) {
- goto error;
- }
+ status = lttng_tracker_id_set_string(dest, orig->string);
break;
default:
status = LTTNG_TRACKER_ID_STATUS_OK;
}
if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+ ret = -1;
+ goto error;
+ }
+error:
+ return ret;
+}
+
+struct lttng_tracker_id *lttng_tracker_id_duplicate(
+ const struct lttng_tracker_id *orig)
+{
+ int ret;
+ struct lttng_tracker_id *copy = NULL;
+
+ copy = lttng_tracker_id_create();
+ if (copy == NULL) {
+ goto error;
+ }
+
+ ret = lttng_tracker_id_copy(copy, orig);
+ if (ret) {
goto error;
}
*value = id->string;
return LTTNG_TRACKER_ID_STATUS_OK;
}
+
+struct lttng_tracker_ids *lttng_tracker_ids_create(unsigned int count)
+{
+ struct lttng_tracker_ids *ids = NULL;
+
+ ids = zmalloc(sizeof(*ids));
+ if (!ids) {
+ goto error;
+ }
+
+ ids->id_array = zmalloc(sizeof(struct lttng_tracker_id) * count);
+ if (!ids->id_array) {
+ goto error;
+ }
+
+ ids->count = count;
+
+ return ids;
+error:
+ free(ids);
+ return NULL;
+}
+
+LTTNG_HIDDEN
+struct lttng_tracker_id *lttng_tracker_ids_get_pointer_of_index(
+ const struct lttng_tracker_ids *ids, unsigned int index)
+{
+ assert(ids);
+ if (index >= ids->count) {
+ return NULL;
+ }
+
+ return &ids->id_array[index];
+}
+
+const struct lttng_tracker_id *lttng_tracker_ids_get_at_index(
+ const struct lttng_tracker_ids *ids, unsigned int index)
+{
+ assert(ids);
+ return lttng_tracker_ids_get_pointer_of_index(ids, index);
+}
+
+int lttng_tracker_ids_get_count(const struct lttng_tracker_ids *ids)
+{
+ assert(ids);
+ return ids->count;
+}
+
+void lttng_tracker_ids_destroy(struct lttng_tracker_ids *ids)
+{
+ if (!ids) {
+ return;
+ }
+
+ for (int i = 0; i < ids->count; i++) {
+ lttng_tracker_id_reset(&ids->id_array[i]);
+ }
+ free(ids->id_array);
+ free(ids);
+}
*/
int lttng_list_tracker_ids(struct lttng_handle *handle,
enum lttng_tracker_type tracker_type,
- struct lttng_tracker_id ***_ids,
- size_t *_nr_ids)
+ struct lttng_tracker_ids **_ids)
{
int ret, i;
struct lttcomm_session_msg lsm;
char *cmd_payload = NULL, *p;
size_t cmd_header_len;
size_t nr_ids = 0;
- struct lttng_tracker_id **ids = NULL;
+ struct lttng_tracker_ids *ids = NULL;
if (handle == NULL) {
return -LTTNG_ERR_INVALID;
free(cmd_header);
cmd_header = NULL;
- ids = zmalloc(sizeof(*ids) * nr_ids);
+ ids = lttng_tracker_ids_create(nr_ids);
if (!ids) {
ret = -LTTNG_ERR_NOMEM;
goto error;
tracker_id = (struct lttcomm_tracker_id_header *) p;
p += sizeof(struct lttcomm_tracker_id_header);
- id = lttng_tracker_id_create();
+ id = lttng_tracker_ids_get_pointer_of_index(ids, i);
if (!id) {
- ret = -LTTNG_ERR_NOMEM;
+ ret = -LTTNG_ERR_INVALID;
goto error;
}
ret = -LTTNG_ERR_INVALID;
goto error;
}
-
- /* Assign the new object to the list */
- ids[i] = id;
}
free(cmd_payload);
*_ids = ids;
- *_nr_ids = nr_ids;
return 0;
error:
- lttng_tracker_ids_destroy(ids, nr_ids);
- free(ids);
+ lttng_tracker_ids_destroy(ids);
free(cmd_payload);
free(cmd_header);
return ret;
int lttng_list_tracker_pids(struct lttng_handle *handle,
int *_enabled, int32_t **_pids, size_t *_nr_pids)
{
- struct lttng_tracker_id **ids = NULL;
+ struct lttng_tracker_ids *ids = NULL;
size_t nr_ids = 0;
int *pids = NULL;
int ret = 0, i;
enum lttng_tracker_id_status status;
+ const struct lttng_tracker_id *id;
- ret = lttng_list_tracker_ids(handle, LTTNG_TRACKER_PID, &ids, &nr_ids);
- if (ret < 0)
+ ret = lttng_list_tracker_ids(handle, LTTNG_TRACKER_PID, &ids);
+ if (ret < 0) {
return ret;
+ }
- if (nr_ids == 1 && lttng_tracker_id_get_type(ids[0]) == LTTNG_ID_ALL) {
- *_enabled = 0;
- goto end;
+ nr_ids = lttng_tracker_ids_get_count(ids);
+
+ if (nr_ids == 1) {
+ id = lttng_tracker_ids_get_at_index(ids, 0);
+ if (id && lttng_tracker_id_get_type(id) == LTTNG_ID_ALL) {
+ *_enabled = 0;
+ goto end;
+ }
}
+
*_enabled = 1;
pids = zmalloc(nr_ids * sizeof(*pids));
goto end;
}
for (i = 0; i < nr_ids; i++) {
- struct lttng_tracker_id *id = ids[i];
-
+ id = lttng_tracker_ids_get_at_index(ids, i);
status = lttng_tracker_id_get_value(id, &pids[i]);
if (status != LTTNG_TRACKER_ID_STATUS_OK) {
ret = -LTTNG_ERR_UNK;
*_pids = pids;
*_nr_pids = nr_ids;
end:
- lttng_tracker_ids_destroy(ids, nr_ids);
- free(ids);
+ lttng_tracker_ids_destroy(ids);
if (ret < 0) {
free(pids);
}