From: Mathieu Desnoyers Date: Tue, 29 Nov 2011 21:39:58 +0000 (-0500) Subject: ltt_event_create should return error values X-Git-Tag: v1.9.1~50 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=576599a076803d5306b939bfd8333202919bb56e;p=lttng-ust.git ltt_event_create should return error values Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index afcc67f9..0ccef46a 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -336,9 +336,10 @@ struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, int *shm_fd, int *wait_fd, uint64_t *memory_map_size); -struct ltt_event *ltt_event_create(struct ltt_channel *chan, - struct lttng_ust_event *event_param, - void *filter); +int ltt_event_create(struct ltt_channel *chan, + struct lttng_ust_event *event_param, + void *filter, + struct ltt_event **event); int ltt_channel_enable(struct ltt_channel *channel); int ltt_channel_disable(struct ltt_channel *channel); diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 2595ea89..b852b313 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -350,25 +350,33 @@ void _ltt_channel_destroy(struct ltt_channel *chan) /* * Supports event creation while tracing session is active. */ -struct ltt_event *ltt_event_create(struct ltt_channel *chan, - struct lttng_ust_event *event_param, - void *filter) +int ltt_event_create(struct ltt_channel *chan, + struct lttng_ust_event *event_param, + void *filter, + struct ltt_event **_event) { struct ltt_event *event; - int ret; + int ret = 0; - if (chan->used_event_id == -1UL) + if (chan->used_event_id == -1UL) { + ret = -ENOMEM; goto full; + } /* * This is O(n^2) (for each event, the loop is called at event * creation). Might require a hash if we have lots of events. */ - cds_list_for_each_entry(event, &chan->session->events, list) - if (event->desc && !strcmp(event->desc->name, event_param->name)) + cds_list_for_each_entry(event, &chan->session->events, list) { + if (event->desc && !strcmp(event->desc->name, event_param->name)) { + ret = -EEXIST; goto exist; + } + } event = zmalloc(sizeof(struct ltt_event)); - if (!event) + if (!event) { + ret = -ENOMEM; goto cache_error; + } event->chan = chan; event->filter = filter; /* @@ -410,7 +418,8 @@ struct ltt_event *ltt_event_create(struct ltt_channel *chan, goto statedump_error; } cds_list_add(&event->list, &chan->session->events); - return event; + *_event = event; + return 0; statedump_error: if (event->desc) { @@ -425,7 +434,7 @@ register_error: cache_error: exist: full: - return NULL; + return ret; } /* diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 76af511f..e6ffa41f 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -334,13 +334,14 @@ void lttng_metadata_create_events(int channel_objd) .name = "lttng_ust:metadata", }; struct ltt_event *event; + int ret; /* * We tolerate no failure path after event creation. It will stay * invariant for the rest of the session. */ - event = ltt_event_create(channel, &metadata_params, NULL); - if (!event) { + ret = ltt_event_create(channel, &metadata_params, NULL, &event); + if (ret < 0) { goto create_error; } return; @@ -656,9 +657,8 @@ int lttng_abi_create_event(int channel_objd, * We tolerate no failure path after event creation. It will stay * invariant for the rest of the session. */ - event = ltt_event_create(channel, event_param, NULL); - if (!event) { - ret = -EINVAL; + ret = ltt_event_create(channel, event_param, NULL, &event); + if (ret < 0) { goto event_error; } objd_set_private(event_objd, event);