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
*
{
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 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <urcu/list.h>
#include "ltt-sessiond.h"
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);
+}
};
/*
- * 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 */