Add FreeBSD compat layer for endian.h
[lttng-ust.git] / liblttng-ust / ltt-events.c
index 52feeb08a7dad9c9bc9970a39197a586f9305612..f49746e99ff17b1676b8fba02feb1898a6547a04 100644 (file)
@@ -10,7 +10,6 @@
 
 #define _GNU_SOURCE
 #include <stdio.h>
-#include <endian.h>
 #include <urcu/list.h>
 #include <urcu/hlist.h>
 #include <pthread.h>
@@ -22,6 +21,8 @@
 #include <stddef.h>
 #include <inttypes.h>
 #include <time.h>
+#include <sys/prctl.h>
+#include <lttng/ust-endian.h>
 #include "clock.h"
 
 #include <urcu-bp.h>
@@ -43,6 +44,8 @@
 #include "../libringbuffer/shm.h"
 #include "jhash.h"
 
+#define PROCNAME_LEN 17
+
 /*
  * The sessions mutex is the centralized mutex across UST tracing
  * control and probe registration. All operations within this file are
@@ -260,8 +263,7 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
                struct ltt_event *event;
                struct ltt_channel *chan;
 
-               event = e->event;
-               if (!ltt_loglevel_match(event->desc,
+               if (!ltt_loglevel_match(desc,
                                e->loglevel_type,
                                e->loglevel)) {
                        continue;
@@ -269,6 +271,7 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
                if (strncmp(name, e->name, LTTNG_UST_SYM_NAME_LEN - 1)) {
                        continue;
                }
+               event = e->event;
                chan = event->chan;
                assert(!event->desc);
                event->desc = desc;
@@ -512,12 +515,18 @@ int ltt_event_create(struct ltt_channel *chan,
         */
        if (event_param->instrumentation == LTTNG_UST_TRACEPOINT) {
                desc = ltt_event_get(event_param->name);
-               if (!ltt_loglevel_match(desc,
-                               event_param->loglevel_type,
-                               event_param->loglevel)) {
-                       ret = -EPERM;
-                       goto no_loglevel_match;
+               if (desc) {
+                       if (!ltt_loglevel_match(desc,
+                                       event_param->loglevel_type,
+                                       event_param->loglevel)) {
+                               ret = -EPERM;
+                               goto no_loglevel_match;
+                       }
                }
+               /*
+                * If descriptor is not there, it will be added to
+                * pending probes.
+                */
        }
        event = zmalloc(sizeof(struct ltt_event));
        if (!event) {
@@ -869,6 +878,7 @@ int _ltt_event_metadata_statedump(struct ltt_session *session,
                                  struct ltt_event *event)
 {
        int ret = 0;
+       int loglevel = TRACE_DEFAULT;
 
        if (event->metadata_dumped || !CMM_ACCESS_ONCE(session->active))
                return 0;
@@ -891,13 +901,14 @@ int _ltt_event_metadata_statedump(struct ltt_session *session,
        if (ret)
                goto end;
 
-       if (event->desc->loglevel) {
-               ret = lttng_metadata_printf(session,
-                       "       loglevel = %d;\n",
-                       *(*event->desc->loglevel));
-               if (ret)
-                       goto end;
-       }
+       if (event->desc->loglevel)
+               loglevel = *(*event->desc->loglevel);
+
+       ret = lttng_metadata_printf(session,
+               "       loglevel = %d;\n",
+               loglevel);
+       if (ret)
+               goto end;
 
        if (event->ctx) {
                ret = lttng_metadata_printf(session,
@@ -1082,6 +1093,7 @@ int _ltt_session_metadata_statedump(struct ltt_session *session)
        struct ltt_channel *chan;
        struct ltt_event *event;
        int ret = 0;
+       char procname[PROCNAME_LEN] = "";
 
        if (!CMM_ACCESS_ONCE(session->active))
                return 0;
@@ -1122,8 +1134,8 @@ int _ltt_session_metadata_statedump(struct ltt_session *session)
                lttng_alignof(uint16_t) * CHAR_BIT,
                lttng_alignof(uint32_t) * CHAR_BIT,
                lttng_alignof(uint64_t) * CHAR_BIT,
-               CTF_VERSION_MAJOR,
-               CTF_VERSION_MINOR,
+               CTF_SPEC_MAJOR,
+               CTF_SPEC_MINOR,
                uuid_s,
 #if (BYTE_ORDER == BIG_ENDIAN)
                "be"
@@ -1134,6 +1146,28 @@ int _ltt_session_metadata_statedump(struct ltt_session *session)
        if (ret)
                goto end;
 
+       /* ignore error, just use empty string if error. */
+       (void) prctl(PR_GET_NAME, (unsigned long) procname, 0, 0, 0);
+       procname[PROCNAME_LEN - 1] = '\0';
+       ret = lttng_metadata_printf(session,
+               "env {\n"
+               "       vpid = %d;\n"
+               "       procname = \"%s\";\n"
+               "       domain = \"ust\";\n"
+               "       tracer_name = \"lttng-ust\";\n"
+               "       tracer_major = %u;\n"
+               "       tracer_minor = %u;\n"
+               "       tracer_patchlevel = %u;\n"
+               "};\n\n",
+               (int) getpid(),
+               procname,
+               LTTNG_UST_MAJOR_VERSION,
+               LTTNG_UST_MINOR_VERSION,
+               LTTNG_UST_PATCHLEVEL_VERSION
+               );
+       if (ret)
+               goto end;
+
        ret = lttng_metadata_printf(session,
                "clock {\n"
                "       name = %s;\n",
This page took 0.024349 seconds and 4 git commands to generate.