Add lttng_event copy constructor
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 28 Jun 2018 13:47:51 +0000 (09:47 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 24 Aug 2018 19:54:38 +0000 (15:54 -0400)
Since the lttng_event structure now has an extended_ptr to store
additional data, such as a userspace probe location, we can't simply
memcpy the struct to duplicate it.
This commit introduces a lttng_event_copy function that allocates a new
lttng_event struct and copies the content of both the struct and its
extended_ptr.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/event.h
src/lib/lttng-ctl/event.c

index 0131defcca2357063585130d20c35113d3a51c48..548ec2a4691b7900370c4795b55e04daa8e43eca 100644 (file)
@@ -304,6 +304,8 @@ extern int lttng_list_events(struct lttng_handle *handle,
 
 extern struct lttng_event *lttng_event_create(void);
 
+extern struct lttng_event *lttng_event_copy(const struct lttng_event *event);
+
 extern void lttng_event_destroy(struct lttng_event *event);
 
 /*
index 9413b7052ee80817360853669e9ec05e36546e13..046028cd219a46b25866770c1d8c96b8405092a2 100644 (file)
@@ -54,6 +54,38 @@ error:
        goto end;
 }
 
+struct lttng_event *lttng_event_copy(const struct lttng_event *event)
+{
+       struct lttng_event *new_event;
+       struct lttng_event_extended *new_event_extended;
+
+       new_event = zmalloc(sizeof(*event));
+       if (!event) {
+               PERROR("Error allocating event structure");
+               goto end;
+       }
+
+       /* Copy the content of the old event. */
+       memcpy(new_event, event, sizeof(*event));
+
+       /*
+        * We need to create a new extended since the previous pointer is now
+        * invalid.
+        */
+       new_event_extended = zmalloc(sizeof(*new_event_extended));
+       if (!new_event_extended) {
+               PERROR("Error allocating event extended structure");
+               goto error;
+       }
+
+       new_event->extended.ptr = new_event_extended;
+end:
+       return new_event;
+error:
+       free(event);
+       goto end;
+}
+
 void lttng_event_destroy(struct lttng_event *event)
 {
        struct lttng_event_extended *event_extended;
This page took 0.027379 seconds and 5 git commands to generate.