From 44252f0fd51fd4bf28926dcef525355bceb08c5f Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 14 Jul 2011 13:46:21 -0400 Subject: [PATCH] Check for context name duplicata Signed-off-by: Mathieu Desnoyers --- ltt-context.c | 12 ++++++++++++ ltt-events.h | 1 + lttng-context-comm.c | 4 ++++ lttng-context-nice.c | 4 ++++ lttng-context-perf-counters.c | 5 +++++ lttng-context-pid.c | 4 ++++ lttng-context-ppid.c | 4 ++++ lttng-context-prio.c | 4 ++++ lttng-context-tid.c | 4 ++++ lttng-context-vpid.c | 4 ++++ lttng-context-vppid.c | 4 ++++ lttng-context-vtid.c | 4 ++++ 12 files changed, 54 insertions(+) diff --git a/ltt-context.c b/ltt-context.c index 634694b9..6c3890c3 100644 --- a/ltt-context.c +++ b/ltt-context.c @@ -16,6 +16,18 @@ #include "ltt-events.h" #include "ltt-tracer.h" +int lttng_find_context(struct lttng_ctx *ctx, const char *name) +{ + unsigned int i; + + for (i = 0; i < ctx->nr_fields; i++) { + if (!strcmp(ctx->fields[i].event_field.name, name)) + return 1; + } + return 0; +} +EXPORT_SYMBOL_GPL(lttng_find_context); + struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p) { struct lttng_ctx_field *field; diff --git a/ltt-events.h b/ltt-events.h index 10015ad6..1307c36b 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -284,6 +284,7 @@ void ltt_event_put(const struct lttng_event_desc *desc); int ltt_probes_init(void); void ltt_probes_exit(void); struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); +int lttng_find_context(struct lttng_ctx *ctx, const char *name); void lttng_remove_context_field(struct lttng_ctx **ctx, struct lttng_ctx_field *field); void lttng_destroy_context(struct lttng_ctx *ctx); diff --git a/lttng-context-comm.c b/lttng-context-comm.c index ede3f51a..beea83ff 100644 --- a/lttng-context-comm.c +++ b/lttng-context-comm.c @@ -45,6 +45,10 @@ int lttng_add_comm_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "comm")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "comm"; field->event_field.type.atype = atype_array; field->event_field.type.u.array.elem_type.atype = atype_integer; diff --git a/lttng-context-nice.c b/lttng-context-nice.c index bfe688ef..9b99b549 100644 --- a/lttng-context-nice.c +++ b/lttng-context-nice.c @@ -44,6 +44,10 @@ int lttng_add_nice_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "nice")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "nice"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT; diff --git a/lttng-context-perf-counters.c b/lttng-context-perf-counters.c index 5327e6ef..2f7132fb 100644 --- a/lttng-context-perf-counters.c +++ b/lttng-context-perf-counters.c @@ -170,6 +170,10 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, ret = -ENOMEM; goto append_context_error; } + if (lttng_find_context(*ctx, name_alloc)) { + ret = -EEXIST; + goto find_error; + } #ifdef CONFIG_HOTPLUG_CPU field->u.perf_counter.nb.notifier_call = @@ -217,6 +221,7 @@ counter_error: #ifdef CONFIG_HOTPLUG_CPU unregister_cpu_notifier(&field->u.perf_counter.nb); #endif +find_error: lttng_remove_context_field(ctx, field); append_context_error: kfree(name_alloc); diff --git a/lttng-context-pid.c b/lttng-context-pid.c index ee2c4f0f..698b2422 100644 --- a/lttng-context-pid.c +++ b/lttng-context-pid.c @@ -44,6 +44,10 @@ int lttng_add_pid_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "pid")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "pid"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; diff --git a/lttng-context-ppid.c b/lttng-context-ppid.c index 9f647ab1..738f7e68 100644 --- a/lttng-context-ppid.c +++ b/lttng-context-ppid.c @@ -47,6 +47,10 @@ int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "ppid")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "ppid"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; diff --git a/lttng-context-prio.c b/lttng-context-prio.c index 842717ca..ad1c42f4 100644 --- a/lttng-context-prio.c +++ b/lttng-context-prio.c @@ -64,6 +64,10 @@ int lttng_add_prio_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "prio")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "prio"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT; diff --git a/lttng-context-tid.c b/lttng-context-tid.c index f207d986..d5ccdb63 100644 --- a/lttng-context-tid.c +++ b/lttng-context-tid.c @@ -44,6 +44,10 @@ int lttng_add_tid_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "tid")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "tid"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; diff --git a/lttng-context-vpid.c b/lttng-context-vpid.c index c99010cf..f12eb97e 100644 --- a/lttng-context-vpid.c +++ b/lttng-context-vpid.c @@ -44,6 +44,10 @@ int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "vpid")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "vpid"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; diff --git a/lttng-context-vppid.c b/lttng-context-vppid.c index d55e12db..4abf7846 100644 --- a/lttng-context-vppid.c +++ b/lttng-context-vppid.c @@ -47,6 +47,10 @@ int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "vppid")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "vppid"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; diff --git a/lttng-context-vtid.c b/lttng-context-vtid.c index 522d2bd6..c428911e 100644 --- a/lttng-context-vtid.c +++ b/lttng-context-vtid.c @@ -44,6 +44,10 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) field = lttng_append_context(ctx); if (!field) return -ENOMEM; + if (lttng_find_context(*ctx, "vtid")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } field->event_field.name = "vtid"; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; -- 2.34.1