Skip to content

Commit

Permalink
Check for context name duplicata
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  • Loading branch information
compudj committed Jul 14, 2011
1 parent 96ba720 commit 44252f0
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ltt-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ltt-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-nice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lttng-context-perf-counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -217,6 +221,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
#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);
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-ppid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-prio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-tid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-vpid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-vppid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lttng-context-vtid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 44252f0

Please sign in to comment.