ltt_event_create should return error values
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 29 Nov 2011 21:39:58 +0000 (16:39 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 29 Nov 2011 21:39:58 +0000 (16:39 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-events.h
liblttng-ust/ltt-events.c
liblttng-ust/lttng-ust-abi.c

index afcc67f910795aaf10cfa63a2be3e0fa58f34741..0ccef46ab33fa8769c0b3fd09424bfd81c4187a0 100644 (file)
@@ -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);
index 2595ea89b11fd89e8cbfa375a00588eb15b98c86..b852b313eeb3056bae87ab1564839c3ab87b73d9 100644 (file)
@@ -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;
 }
 
 /*
index 76af511f582836553ee4d5622ed204432ddfe1b4..e6ffa41f071e2f50a40ab826ab577ba2674ca4bf 100644 (file)
@@ -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);
This page took 0.028938 seconds and 4 git commands to generate.