X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-context-provider.c;h=c3f50e80c0d3bd7177d7816addb8fa109921d6cc;hb=60864af02c63fdaaf9264b4f14bfbc9f9fba64bd;hp=50f73c6253cf340d90485540ce154dfdafd24d72;hpb=fb31eb73d8a4a6d9784ed5c335b7fa3b9684108c;p=lttng-ust.git diff --git a/liblttng-ust/lttng-context-provider.c b/liblttng-ust/lttng-context-provider.c index 50f73c62..c3f50e80 100644 --- a/liblttng-ust/lttng-context-provider.c +++ b/liblttng-ust/lttng-context-provider.c @@ -1,23 +1,9 @@ /* - * lttng-context-provider.c - * - * LTTng UST application context provider. + * SPDX-License-Identifier: LGPL-2.1-only * * Copyright (C) 2016 Mathieu Desnoyers * - * 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 + * LTTng UST application context provider. */ #define _LGPL_SOURCE @@ -26,10 +12,13 @@ #include #include -#include +#include + +#include "context-internal.h" #include "lttng-tracer-core.h" #include "jhash.h" -#include +#include "context-provider-internal.h" +#include #define CONTEXT_PROVIDER_HT_BITS 12 #define CONTEXT_PROVIDER_HT_SIZE (1U << CONTEXT_PROVIDER_HT_BITS) @@ -90,9 +79,14 @@ int lttng_ust_context_provider_register(struct lttng_ust_context_provider *provi hash = jhash(provider->name, name_len, 0); head = &context_provider_ht.table[hash & (CONTEXT_PROVIDER_HT_SIZE - 1)]; cds_hlist_add_head(&provider->node, head); + lttng_ust_context_set_session_provider(provider->name, provider->get_size, provider->record, provider->get_value); + + lttng_ust_context_set_event_notifier_group_provider(provider->name, + provider->get_size, provider->record, + provider->get_value); end: ust_unlock(); return ret; @@ -107,6 +101,11 @@ void lttng_ust_context_provider_unregister(struct lttng_ust_context_provider *pr lttng_ust_context_set_session_provider(provider->name, lttng_ust_dummy_get_size, lttng_ust_dummy_record, lttng_ust_dummy_get_value); + + lttng_ust_context_set_event_notifier_group_provider(provider->name, + lttng_ust_dummy_get_size, lttng_ust_dummy_record, + lttng_ust_dummy_get_value); + cds_hlist_del(&provider->node); end: ust_unlock(); @@ -121,42 +120,71 @@ end: * metadata describing the context. */ int lttng_ust_add_app_context_to_ctx_rcu(const char *name, - struct lttng_ctx **ctx) + struct lttng_ust_ctx **ctx) { struct lttng_ust_context_provider *provider; - struct lttng_ctx_field new_field; + struct lttng_ust_ctx_field *new_field = NULL; int ret; if (*ctx && lttng_find_context(*ctx, name)) return -EEXIST; - /* - * For application context, add it by expanding - * ctx array. - */ - memset(&new_field, 0, sizeof(new_field)); - new_field.field_name = strdup(name); - if (!new_field.field_name) - return -ENOMEM; - new_field.event_field.name = new_field.field_name; - new_field.event_field.type.atype = atype_dynamic; + new_field = zmalloc(sizeof(struct lttng_ust_ctx_field)); + if (!new_field) { + ret = -ENOMEM; + goto error_field_alloc; + } + new_field->struct_size = sizeof(struct lttng_ust_ctx_field); + new_field->event_field = zmalloc(sizeof(struct lttng_ust_event_field)); + if (!new_field->event_field) { + ret = -ENOMEM; + goto error_event_field_alloc; + } + new_field->event_field->name = strdup(name); + if (!new_field->event_field->name) { + ret = -ENOMEM; + goto error_field_name_alloc; + } + new_field->event_field->type = zmalloc(sizeof(struct lttng_ust_type_common)); + if (!new_field->event_field->type) { + ret = -ENOMEM; + goto error_field_type_alloc; + } + new_field->event_field->type->type = lttng_ust_type_dynamic; /* * If provider is not found, we add the context anyway, but * it will provide a dummy context. */ provider = lookup_provider_by_name(name); if (provider) { - new_field.get_size = provider->get_size; - new_field.record = provider->record; - new_field.get_value = provider->get_value; + new_field->get_size = provider->get_size; + new_field->record = provider->record; + new_field->get_value = provider->get_value; } else { - new_field.get_size = lttng_ust_dummy_get_size; - new_field.record = lttng_ust_dummy_record; - new_field.get_value = lttng_ust_dummy_get_value; + new_field->get_size = lttng_ust_dummy_get_size; + new_field->record = lttng_ust_dummy_record; + new_field->get_value = lttng_ust_dummy_get_value; } - ret = lttng_context_add_rcu(ctx, &new_field); + /* + * For application context, add it by expanding + * ctx array. Ownership of new_field is passed to the callee on + * success. + */ + ret = lttng_context_add_rcu(ctx, new_field); if (ret) { - free(new_field.field_name); + free(new_field->event_field->type); + free((char *) new_field->event_field->name); + free(new_field->event_field); + free(new_field); return ret; } return 0; + +error_field_type_alloc: + free((char *) new_field->event_field->name); +error_field_name_alloc: + free(new_field->event_field); +error_event_field_alloc: + free(new_field); +error_field_alloc: + return ret; }