Remove O_LARGEFILE from tests
[lttng-ust.git] / liblttng-ust / ltt-events.c
index 52feeb08a7dad9c9bc9970a39197a586f9305612..2b9037ef48f0d84b8ca237733f5e3438267bb48d 100644 (file)
@@ -1,20 +1,30 @@
 /*
  * ltt-events.c
  *
- * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
  * Holds LTTng per-session event registry.
  *
- * Dual LGPL v2.1/GPL v2 license.
+ * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #define _GNU_SOURCE
 #include <stdio.h>
-#include <endian.h>
 #include <urcu/list.h>
 #include <urcu/hlist.h>
 #include <pthread.h>
-#include <uuid/uuid.h>
 #include <errno.h>
 #include <sys/shm.h>
 #include <sys/ipc.h>
@@ -22,6 +32,7 @@
 #include <stddef.h>
 #include <inttypes.h>
 #include <time.h>
+#include <lttng/ust-endian.h>
 #include "clock.h"
 
 #include <urcu-bp.h>
@@ -35,6 +46,8 @@
 #include <usterr-signal-safe.h>
 #include <helper.h>
 #include "error.h"
+#include "compat.h"
+#include "lttng-ust-uuid.h"
 
 #include "tracepoint-internal.h"
 #include "ltt-tracer.h"
@@ -166,20 +179,20 @@ int add_pending_probe(struct ltt_event *event, const char *name,
 {
        struct cds_hlist_head *head;
        struct ust_pending_probe *e;
-       size_t name_len = strlen(name);
+       size_t name_len = strlen(name) + 1;
        uint32_t hash;
 
-       if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) {
-               WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1);
-               name_len = LTTNG_UST_SYM_NAME_LEN - 1;
+       if (name_len > LTTNG_UST_SYM_NAME_LEN) {
+               WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN);
+               name_len = LTTNG_UST_SYM_NAME_LEN;
        }
-       hash = jhash(name, name_len, 0);
+       hash = jhash(name, name_len - 1, 0);
        head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)];
        e = zmalloc(sizeof(struct ust_pending_probe) + name_len);
        if (!e)
                return -ENOMEM;
-       memcpy(&e->name[0], name, name_len + 1);
-       e->name[name_len] = '\0';
+       memcpy(&e->name[0], name, name_len);
+       e->name[name_len - 1] = '\0';
        e->loglevel_type = loglevel_type;
        e->loglevel = loglevel;
        cds_hlist_add_head(&e->node, head);
@@ -215,7 +228,7 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
        const char *name = desc->name;
        int ret = 0;
        struct lttng_ust_event event_param;
-       size_t name_len = strlen(name);
+       size_t name_len = strlen(name) + 1;
        uint32_t hash;
 
        /* Wildcard */
@@ -233,9 +246,10 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
 
                                memcpy(&event_param, &sw->event_param,
                                                sizeof(event_param));
-                               memcpy(event_param.name,
+                               strncpy(event_param.name,
                                        desc->name,
                                        sizeof(event_param.name));
+                               event_param.name[sizeof(event_param.name) - 1] = '\0';
                                /* create event */
                                ret = ltt_event_create(sw->chan,
                                        &event_param, NULL,
@@ -250,18 +264,17 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
                }
        }
 
-       if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) {
-               WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1);
-               name_len = LTTNG_UST_SYM_NAME_LEN - 1;
+       if (name_len > LTTNG_UST_SYM_NAME_LEN) {
+               WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN);
+               name_len = LTTNG_UST_SYM_NAME_LEN;
        }
-       hash = jhash(name, name_len, 0);
+       hash = jhash(name, name_len - 1, 0);
        head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)];
        cds_hlist_for_each_entry_safe(e, node, p, head, node) {
                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 +282,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;
@@ -276,7 +290,7 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc)
                remove_pending_probe(e);
                ret |= __tracepoint_probe_register(name,
                                event->desc->probe_callback,
-                               event);
+                               event, event->desc->signature);
                if (ret)
                        continue;
                event->id = chan->free_event_id++;
@@ -294,6 +308,7 @@ void synchronize_trace(void)
 struct ltt_session *ltt_session_create(void)
 {
        struct ltt_session *session;
+       int ret;
 
        session = zmalloc(sizeof(struct ltt_session));
        if (!session)
@@ -301,7 +316,10 @@ struct ltt_session *ltt_session_create(void)
        CDS_INIT_LIST_HEAD(&session->chan);
        CDS_INIT_LIST_HEAD(&session->events);
        CDS_INIT_LIST_HEAD(&session->wildcards);
-       uuid_generate(session->uuid);
+       ret = lttng_ust_uuid_generate(session->uuid);
+       if (ret != 0) {
+               session->uuid[0] = '\0';
+       }
        cds_list_add(&session->list, &sessions);
        return session;
 }
@@ -450,7 +468,7 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session,
         * headers. Therefore the "chan" information used as input
         * should be already accessible.
         */
-       chan = transport->ops.channel_create("[lttng]", buf_addr,
+       chan = transport->ops.channel_create(transport_name, buf_addr,
                        subbuf_size, num_subbuf, switch_timer_interval,
                        read_timer_interval, shm_fd, wait_fd,
                        memory_map_size, chan_priv_init);
@@ -483,14 +501,14 @@ void _ltt_channel_destroy(struct ltt_channel *chan)
  */
 int ltt_event_create(struct ltt_channel *chan,
                struct lttng_ust_event *event_param,
-               void *filter,
+               void (*filter)(struct ltt_event *event),
                struct ltt_event **_event)
 {
        const struct lttng_event_desc *desc = NULL;     /* silence gcc */
        struct ltt_event *event;
        int ret = 0;
 
-       if (chan->used_event_id == -1UL) {
+       if (chan->used_event_id == -1U) {
                ret = -ENOMEM;
                goto full;
        }
@@ -512,12 +530,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) {
@@ -541,7 +565,7 @@ int ltt_event_create(struct ltt_channel *chan,
                if (event->desc) {
                        ret = __tracepoint_probe_register(event_param->name,
                                        event->desc->probe_callback,
-                                       event);
+                                       event, event->desc->signature);
                        if (ret)
                                goto register_error;
                        event->id = chan->free_event_id++;
@@ -869,6 +893,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 +916,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,
@@ -1065,7 +1091,7 @@ uint64_t measure_clock_offset(void)
                return 0;
        monotonic[1] = trace_clock_read64();
        offset = (monotonic[0] + monotonic[1]) >> 1;
-       realtime = rts.tv_sec * 1000000000ULL;
+       realtime = (uint64_t) rts.tv_sec * 1000000000ULL;
        realtime += rts.tv_nsec;
        offset = realtime - offset;
        return offset;
@@ -1078,10 +1104,12 @@ static
 int _ltt_session_metadata_statedump(struct ltt_session *session)
 {
        unsigned char *uuid_c = session->uuid;
-       char uuid_s[37], clock_uuid_s[CLOCK_UUID_LEN];
+       char uuid_s[LTTNG_UST_UUID_STR_LEN],
+               clock_uuid_s[LTTNG_UST_UUID_STR_LEN];
        struct ltt_channel *chan;
        struct ltt_event *event;
        int ret = 0;
+       char procname[LTTNG_UST_PROCNAME_LEN] = "";
 
        if (!CMM_ACCESS_ONCE(session->active))
                return 0;
@@ -1122,8 +1150,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 +1162,28 @@ int _ltt_session_metadata_statedump(struct ltt_session *session)
        if (ret)
                goto end;
 
+       /* ignore error, just use empty string if error. */
+       lttng_ust_getprocname(procname);
+       procname[LTTNG_UST_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",
@@ -1310,6 +1360,8 @@ struct session_wildcard *add_wildcard(struct ltt_channel *chan,
                if (!e)
                        return ERR_PTR(-ENOMEM);
                memcpy(&e->name[0], event_param->name, name_len);
+               e->loglevel_type = event_param->loglevel_type;
+               e->loglevel = event_param->loglevel;
                cds_list_add(&e->list, &wildcard_list);
                CDS_INIT_LIST_HEAD(&e->session_list);
        }
@@ -1421,3 +1473,16 @@ int ltt_wildcard_disable(struct session_wildcard *wildcard)
        wildcard->enabled = 0;
        return 0;
 }
+
+/*
+ * Take the TLS "fault" in libuuid if dlopen'd, which can take the
+ * dynamic linker mutex, outside of the UST lock, since the UST lock is
+ * taken in constructors, which are called with dynamic linker mutex
+ * held.
+ */
+void lttng_fixup_event_tls(void)
+{
+       unsigned char uuid[37];
+
+       (void) uuid_generate(uuid);
+}
This page took 0.029252 seconds and 4 git commands to generate.