Add kernel trace destroy functions
authorDavid Goulet <david.goulet@polymtl.ca>
Fri, 27 May 2011 18:29:12 +0000 (14:29 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Fri, 27 May 2011 18:29:12 +0000 (14:29 -0400)
Adds clean trace data structure cleanup using trace_destroy_kernel_*
functions.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
ltt-sessiond/main.c
ltt-sessiond/trace.c
ltt-sessiond/trace.h

index eb5d47f62bb6b9bab5e04c7f91524ce22c8c1b12..722402311586b7f7341e229939608d448ddfe502 100644 (file)
@@ -90,50 +90,6 @@ static sem_t kconsumerd_sem;
 
 static pthread_mutex_t kconsumerd_pid_mutex;   /* Mutex to control kconsumerd pid assignation */
 
-/*
- *  free_kernel_session
- *
- *  Free all data structure inside a kernel session and the session pointer.
- */
-static void free_kernel_session(struct ltt_kernel_session *session)
-{
-       struct ltt_kernel_channel *chan;
-       struct ltt_kernel_stream *stream;
-       struct ltt_kernel_event *event;
-
-       /* Clean metadata */
-       close(session->metadata_stream_fd);
-       close(session->metadata->fd);
-       free(session->metadata->conf);
-       free(session->metadata);
-
-       cds_list_for_each_entry(chan, &session->channel_list.head, list) {
-               /* Clean all event(s) */
-               cds_list_for_each_entry(event, &chan->events_list.head, list) {
-                       close(event->fd);
-                       free(event->event);
-                       free(event);
-               }
-
-               /* Clean streams */
-               cds_list_for_each_entry(stream, &chan->stream_list.head, list) {
-                       close(stream->fd);
-                       free(stream->pathname);
-                       free(stream);
-               }
-               /* Clean channel */
-               close(chan->fd);
-               free(chan->channel);
-               free(chan->pathname);
-               free(chan);
-       }
-
-       close(session->fd);
-       free(session);
-
-       DBG("All kernel session data structures freed");
-}
-
 /*
  *  teardown_kernel_session
  *
@@ -144,7 +100,7 @@ static void teardown_kernel_session(struct ltt_session *session)
 {
        if (session->kernel_session != NULL) {
                DBG("Tearing down kernel session");
-               free_kernel_session(session->kernel_session);
+               trace_destroy_kernel_session(session->kernel_session);
                /* Extra precaution */
                session->kernel_session = NULL;
                /* Decrement session count */
index 8b1d15e105b730501bd149cd67088e8d12800356..5214cddfcfe6433560646c3d62dd1c181d6e3bf3 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <urcu/list.h>
 
 #include "ltt-sessiond.h"
@@ -207,3 +208,79 @@ struct ltt_kernel_stream *trace_create_kernel_stream(void)
 error:
        return NULL;
 }
+
+void trace_destroy_kernel_stream(struct ltt_kernel_stream *stream)
+{
+       /* Close kernel fd */
+       close(stream->fd);
+       free(stream->pathname);
+
+       /* Remove from stream list */
+       cds_list_del(&stream->list);
+       free(stream);
+}
+
+void trace_destroy_kernel_event(struct ltt_kernel_event *event)
+{
+       /* Close kernel fd */
+       close(event->fd);
+       /* Free attributes */
+       free(event->event);
+
+       /* Remove from event list */
+       cds_list_del(&event->list);
+       free(event);
+}
+
+void trace_destroy_kernel_channel(struct ltt_kernel_channel *channel)
+{
+       struct ltt_kernel_stream *stream;
+       struct ltt_kernel_event *event;
+
+       /* Close kernel fd */
+       close(channel->fd);
+       free(channel->pathname);
+       /* Free attributes structure */
+       free(channel->channel);
+
+       /* For each stream in the channel list */
+       cds_list_for_each_entry(stream, &channel->stream_list.head, list) {
+               trace_destroy_kernel_stream(stream);
+       }
+
+       /* For each event in the channel list */
+       cds_list_for_each_entry(event, &channel->events_list.head, list) {
+               trace_destroy_kernel_event(event);
+       }
+
+       /* Remove from channel list */
+       cds_list_del(&channel->list);
+       free(channel);
+}
+
+void trace_destroy_kernel_metadata(struct ltt_kernel_metadata *metadata)
+{
+       /* Close kernel fd */
+       close(metadata->fd);
+       /* Free attributes */
+       free(metadata->conf);
+
+       free(metadata);
+}
+
+void trace_destroy_kernel_session(struct ltt_kernel_session *session)
+{
+       struct ltt_kernel_channel *channel;
+
+       /* Close kernel fds */
+       close(session->fd);
+       close(session->metadata_stream_fd);
+
+       trace_destroy_kernel_metadata(session->metadata);
+
+       cds_list_for_each_entry(channel, &session->channel_list.head, list) {
+               trace_destroy_kernel_channel(channel);
+       }
+
+       free(session);
+}
index 488fd757d3dfabf4d06a894ad2375876f6857cf6..444126ba01e4322c7727a3341f85fd13467e8e90 100644 (file)
@@ -104,23 +104,23 @@ struct ltt_ust_marker {
 };
 
 /*
- * Function prototype
+ * Create functions malloc() the data structure.
  */
-
-/* Kernel session */
 struct ltt_kernel_session *trace_create_kernel_session(void);
-
-/* Kernel channel */
 struct ltt_kernel_channel *trace_create_kernel_channel(void);
-
-/* Kernel event */
 struct ltt_kernel_event *trace_create_kernel_event(char *name,
                enum lttng_kernel_instrumentation type);
-
-/* Kernel metadata */
 struct ltt_kernel_metadata *trace_create_kernel_metadata(void);
-
-/* Kernel stream */
 struct ltt_kernel_stream *trace_create_kernel_stream(void);
 
+/*
+ * Destroy functions free() the data structure and remove from linked list if
+ * it's applies.
+ */
+void trace_destroy_kernel_session(struct ltt_kernel_session *session);
+void trace_destroy_kernel_metadata(struct ltt_kernel_metadata *metadata);
+void trace_destroy_kernel_channel(struct ltt_kernel_channel *channel);
+void trace_destroy_kernel_event(struct ltt_kernel_event *event);
+void trace_destroy_kernel_stream(struct ltt_kernel_stream *stream);
+
 #endif /* _LTT_TRACE_H */
This page took 0.038441 seconds and 4 git commands to generate.