fix: redundant decl of channel_destroy (-Wredundant-decls)
[lttng-ust.git] / liblttng-ust / lttng-probes.c
index a09497f87ba444adc58a1765d0757a04fda7a809..95a1c12bbe2ff2d5cf331f08c7d3d6c2e05d002f 100644 (file)
@@ -1,23 +1,9 @@
 /*
- * lttng-probes.c
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
- * Holds LTTng probes registry.
- *
- * Copyright 2010-2012 (c) - 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.
+ * Copyright 2010-2012 (C) Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * 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
+ * Holds LTTng probes registry.
  */
 
 #define _LGPL_SOURCE
 #include <lttng/tracepoint.h>
 #include "tracepoint-internal.h"
 #include <assert.h>
-#include <helper.h>
+#include <ust-helper.h>
 #include <ctype.h>
 
 #include "lttng-tracer-core.h"
 #include "jhash.h"
 #include "error.h"
+#include "ust-events-internal.h"
 
 /*
  * probe list is protected by ust_lock()/ust_unlock().
@@ -54,42 +41,40 @@ static CDS_LIST_HEAD(lazy_probe_init);
 static int lazy_nesting;
 
 /*
- * Called under ust lock.
+ * Validate that each event within the probe provider refers to the
+ * right probe, and that the resulting name is not too long.
  */
 static
-int check_event_provider(struct lttng_probe_desc *desc)
+bool check_event_provider(struct lttng_ust_probe_desc *probe_desc)
 {
        int i;
-       size_t provider_name_len;
-
-       provider_name_len = strnlen(desc->provider,
-                               LTTNG_UST_SYM_NAME_LEN - 1);
-       for (i = 0; i < desc->nr_events; i++) {
-               if (strncmp(desc->event_desc[i]->name,
-                               desc->provider,
-                               provider_name_len))
-                       return 0;       /* provider mismatch */
+
+       for (i = 0; i < probe_desc->nr_events; i++) {
+               const struct lttng_ust_event_desc *event_desc = probe_desc->event_desc[i];
+
+               if (event_desc->probe_desc != probe_desc) {
+                       ERR("Error registering probe provider '%s'. Event '%s:%s' refers to the wrong provider descriptor.",
+                               probe_desc->provider_name, probe_desc->provider_name, event_desc->event_name);
+                       return false;   /* provider mismatch */
+               }
+               if (!lttng_ust_validate_event_name(event_desc)) {
+                       ERR("Error registering probe provider '%s'. Event '%s:%s' name is too long.",
+                               probe_desc->provider_name, probe_desc->provider_name, event_desc->event_name);
+                       return false;   /* provider mismatch */
+               }
        }
-       return 1;
+       return true;
 }
 
 /*
  * Called under ust lock.
  */
 static
-void lttng_lazy_probe_register(struct lttng_probe_desc *desc)
+void lttng_lazy_probe_register(struct lttng_ust_probe_desc *desc)
 {
-       struct lttng_probe_desc *iter;
+       struct lttng_ust_probe_desc *iter;
        struct cds_list_head *probe_list;
 
-       /*
-        * Each provider enforce that every event name begins with the
-        * provider name. Check this in an assertion for extra
-        * carefulness. This ensures we cannot have duplicate event
-        * names across providers.
-        */
-       assert(check_event_provider(desc));
-
        /*
         * The provider ensures there are no duplicate event names.
         * Duplicated TRACEPOINT_EVENT event names would generate a
@@ -97,7 +82,7 @@ void lttng_lazy_probe_register(struct lttng_probe_desc *desc)
         */
 
        /*
-        * We sort the providers by struct lttng_probe_desc pointer
+        * We sort the providers by struct lttng_ust_probe_desc pointer
         * address.
         */
        probe_list = &_probe_list;
@@ -113,7 +98,7 @@ void lttng_lazy_probe_register(struct lttng_probe_desc *desc)
        cds_list_add(&desc->head, probe_list);
 desc_added:
        DBG("just registered probe %s containing %u events",
-               desc->provider, desc->nr_events);
+               desc->provider_name, desc->nr_events);
 }
 
 /*
@@ -122,7 +107,7 @@ desc_added:
 static
 void fixup_lazy_probes(void)
 {
-       struct lttng_probe_desc *iter, *tmp;
+       struct lttng_ust_probe_desc *iter, *tmp;
        int ret;
 
        lazy_nesting++;
@@ -148,7 +133,7 @@ struct cds_list_head *lttng_get_probe_list_head(void)
 }
 
 static
-int check_provider_version(struct lttng_probe_desc *desc)
+int check_provider_version(struct lttng_ust_probe_desc *desc)
 {
        /*
         * Check tracepoint provider version compatibility.
@@ -156,7 +141,7 @@ int check_provider_version(struct lttng_probe_desc *desc)
        if (desc->major <= LTTNG_UST_PROVIDER_MAJOR) {
                DBG("Provider \"%s\" accepted, version %u.%u is compatible "
                        "with LTTng UST provider version %u.%u.",
-                       desc->provider, desc->major, desc->minor,
+                       desc->provider_name, desc->major, desc->minor,
                        LTTNG_UST_PROVIDER_MAJOR,
                        LTTNG_UST_PROVIDER_MINOR);
                if (desc->major < LTTNG_UST_PROVIDER_MAJOR) {
@@ -169,7 +154,7 @@ int check_provider_version(struct lttng_probe_desc *desc)
                ERR("Provider \"%s\" rejected, version %u.%u is incompatible "
                        "with LTTng UST provider version %u.%u. Please upgrade "
                        "LTTng UST.",
-                       desc->provider, desc->major, desc->minor,
+                       desc->provider_name, desc->major, desc->minor,
                        LTTNG_UST_PROVIDER_MAJOR,
                        LTTNG_UST_PROVIDER_MINOR);
                return 0;               /* reject */
@@ -177,7 +162,7 @@ int check_provider_version(struct lttng_probe_desc *desc)
 }
 
 
-int lttng_probe_register(struct lttng_probe_desc *desc)
+int lttng_ust_probe_register(struct lttng_ust_probe_desc *desc)
 {
        int ret = 0;
 
@@ -189,13 +174,15 @@ int lttng_probe_register(struct lttng_probe_desc *desc)
         */
        if (!check_provider_version(desc))
                return 0;
+       if (!check_event_provider(desc))
+               return 0;
 
        ust_lock_nocheck();
 
        cds_list_add(&desc->lazy_init_head, &lazy_probe_init);
        desc->lazy = 1;
        DBG("adding probe %s containing %u events to lazy registration list",
-               desc->provider, desc->nr_events);
+               desc->provider_name, desc->nr_events);
        /*
         * If there is at least one active session, we need to register
         * the probe immediately, since we cannot delay event
@@ -204,17 +191,13 @@ int lttng_probe_register(struct lttng_probe_desc *desc)
        if (lttng_session_active())
                fixup_lazy_probes();
 
+       lttng_fix_pending_event_notifiers();
+
        ust_unlock();
        return ret;
 }
 
-/* Backward compatibility with UST 2.0 */
-int ltt_probe_register(struct lttng_probe_desc *desc)
-{
-       return lttng_probe_register(desc);
-}
-
-void lttng_probe_unregister(struct lttng_probe_desc *desc)
+void lttng_ust_probe_unregister(struct lttng_ust_probe_desc *desc)
 {
        lttng_ust_fixup_tls();
 
@@ -226,14 +209,11 @@ void lttng_probe_unregister(struct lttng_probe_desc *desc)
                cds_list_del(&desc->head);
        else
                cds_list_del(&desc->lazy_init_head);
-       DBG("just unregistered probe %s", desc->provider);
-       ust_unlock();
-}
 
-/* Backward compatibility with UST 2.0 */
-void ltt_probe_unregister(struct lttng_probe_desc *desc)
-{
-       lttng_probe_unregister(desc);
+       lttng_probe_provider_unregister_events(desc);
+       DBG("just unregistered probes of provider %s", desc->provider_name);
+
+       ust_unlock();
 }
 
 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list)
@@ -251,7 +231,7 @@ void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list)
  */
 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list)
 {
-       struct lttng_probe_desc *probe_desc;
+       struct lttng_ust_probe_desc *probe_desc;
        int i;
        struct cds_list_head *probe_list;
 
@@ -259,20 +239,22 @@ int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list)
        CDS_INIT_LIST_HEAD(&list->head);
        cds_list_for_each_entry(probe_desc, probe_list, head) {
                for (i = 0; i < probe_desc->nr_events; i++) {
+                       const struct lttng_ust_event_desc *event_desc =
+                               probe_desc->event_desc[i];
                        struct tp_list_entry *list_entry;
 
+                       /* Skip event if name is too long. */
+                       if (!lttng_ust_validate_event_name(event_desc))
+                               continue;
                        list_entry = zmalloc(sizeof(*list_entry));
                        if (!list_entry)
                                goto err_nomem;
                        cds_list_add(&list_entry->head, &list->head);
-                       strncpy(list_entry->tp.name,
-                               probe_desc->event_desc[i]->name,
-                               LTTNG_UST_SYM_NAME_LEN);
-                       list_entry->tp.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
-                       if (!probe_desc->event_desc[i]->loglevel) {
+                       lttng_ust_format_event_name(event_desc, list_entry->tp.name);
+                       if (!event_desc->loglevel) {
                                list_entry->tp.loglevel = TRACE_DEFAULT;
                        } else {
-                               list_entry->tp.loglevel = *(*probe_desc->event_desc[i]->loglevel);
+                               list_entry->tp.loglevel = *(*event_desc->loglevel);
                        }
                }
        }
@@ -292,7 +274,7 @@ err_nomem:
  * Return current iteration position, advance internal iterator to next.
  * Return NULL if end of list.
  */
-struct lttng_ust_tracepoint_iter *
+struct lttng_ust_abi_tracepoint_iter *
        lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list)
 {
        struct tp_list_entry *entry;
@@ -323,7 +305,7 @@ void lttng_probes_prune_field_list(struct lttng_ust_field_list *list)
  */
 int lttng_probes_get_field_list(struct lttng_ust_field_list *list)
 {
-       struct lttng_probe_desc *probe_desc;
+       struct lttng_ust_probe_desc *probe_desc;
        int i;
        struct cds_list_head *probe_list;
 
@@ -331,7 +313,7 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list)
        CDS_INIT_LIST_HEAD(&list->head);
        cds_list_for_each_entry(probe_desc, probe_list, head) {
                for (i = 0; i < probe_desc->nr_events; i++) {
-                       const struct lttng_event_desc *event_desc =
+                       const struct lttng_ust_event_desc *event_desc =
                                probe_desc->event_desc[i];
                        int j;
 
@@ -339,16 +321,16 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list)
                                /* Events without fields. */
                                struct tp_field_list_entry *list_entry;
 
+                               /* Skip event if name is too long. */
+                               if (!lttng_ust_validate_event_name(event_desc))
+                                       continue;
                                list_entry = zmalloc(sizeof(*list_entry));
                                if (!list_entry)
                                        goto err_nomem;
                                cds_list_add(&list_entry->head, &list->head);
-                               strncpy(list_entry->field.event_name,
-                                       event_desc->name,
-                                       LTTNG_UST_SYM_NAME_LEN);
-                               list_entry->field.event_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+                               lttng_ust_format_event_name(event_desc, list_entry->field.event_name);
                                list_entry->field.field_name[0] = '\0';
-                               list_entry->field.type = LTTNG_UST_FIELD_OTHER;
+                               list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER;
                                if (!event_desc->loglevel) {
                                        list_entry->field.loglevel = TRACE_DEFAULT;
                                } else {
@@ -358,51 +340,49 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list)
                        }
 
                        for (j = 0; j < event_desc->nr_fields; j++) {
-                               const struct lttng_event_field *event_field =
-                                       &event_desc->fields[j];
+                               const struct lttng_ust_event_field *event_field =
+                                       event_desc->fields[j];
                                struct tp_field_list_entry *list_entry;
 
+                               /* Skip event if name is too long. */
+                               if (!lttng_ust_validate_event_name(event_desc))
+                                       continue;
                                list_entry = zmalloc(sizeof(*list_entry));
                                if (!list_entry)
                                        goto err_nomem;
                                cds_list_add(&list_entry->head, &list->head);
-                               strncpy(list_entry->field.event_name,
-                                       event_desc->name,
-                                       LTTNG_UST_SYM_NAME_LEN);
-                               list_entry->field.event_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+                               lttng_ust_format_event_name(event_desc, list_entry->field.event_name);
                                strncpy(list_entry->field.field_name,
                                        event_field->name,
-                                       LTTNG_UST_SYM_NAME_LEN);
-                               list_entry->field.field_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
-                               switch (event_field->type.atype) {
-                               case atype_integer:
-                                       list_entry->field.type = LTTNG_UST_FIELD_INTEGER;
+                                       LTTNG_UST_ABI_SYM_NAME_LEN);
+                               list_entry->field.field_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
+                               switch (event_field->type->type) {
+                               case lttng_ust_type_integer:
+                                       list_entry->field.type = LTTNG_UST_ABI_FIELD_INTEGER;
                                        break;
-                               case atype_string:
-                                       list_entry->field.type = LTTNG_UST_FIELD_STRING;
+                               case lttng_ust_type_string:
+                                       list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING;
                                        break;
-                               case atype_array:
-                                       if (event_field->type.u.array.elem_type.atype != atype_integer
-                                               || event_field->type.u.array.elem_type.u.basic.integer.encoding == lttng_encode_none)
-                                               list_entry->field.type = LTTNG_UST_FIELD_OTHER;
+                               case lttng_ust_type_array:
+                                       if (lttng_ust_get_type_array(event_field->type)->encoding == lttng_ust_string_encoding_none)
+                                               list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER;
                                        else
-                                               list_entry->field.type = LTTNG_UST_FIELD_STRING;
+                                               list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING;
                                        break;
-                               case atype_sequence:
-                                       if (event_field->type.u.sequence.elem_type.atype != atype_integer
-                                               || event_field->type.u.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none)
-                                               list_entry->field.type = LTTNG_UST_FIELD_OTHER;
+                               case lttng_ust_type_sequence:
+                                       if (lttng_ust_get_type_sequence(event_field->type)->encoding == lttng_ust_string_encoding_none)
+                                               list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER;
                                        else
-                                               list_entry->field.type = LTTNG_UST_FIELD_STRING;
+                                               list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING;
                                        break;
-                               case atype_float:
-                                       list_entry->field.type = LTTNG_UST_FIELD_FLOAT;
+                               case lttng_ust_type_float:
+                                       list_entry->field.type = LTTNG_UST_ABI_FIELD_FLOAT;
                                        break;
-                               case atype_enum:
-                                       list_entry->field.type = LTTNG_UST_FIELD_ENUM;
+                               case lttng_ust_type_enum:
+                                       list_entry->field.type = LTTNG_UST_ABI_FIELD_ENUM;
                                        break;
                                default:
-                                       list_entry->field.type = LTTNG_UST_FIELD_OTHER;
+                                       list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER;
                                }
                                if (!event_desc->loglevel) {
                                        list_entry->field.loglevel = TRACE_DEFAULT;
@@ -430,7 +410,7 @@ err_nomem:
  * Return current iteration position, advance internal iterator to next.
  * Return NULL if end of list.
  */
-struct lttng_ust_field_iter *
+struct lttng_ust_abi_field_iter *
        lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list)
 {
        struct tp_field_list_entry *entry;
This page took 0.030008 seconds and 4 git commands to generate.