Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
9f36eaed | 2 | * |
886d51a3 | 3 | * lttng-context-procname.c |
25b2f99a | 4 | * |
c26fddc2 | 5 | * LTTng procname context. |
25b2f99a | 6 | * |
886d51a3 | 7 | * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
25b2f99a MD |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/sched.h> | |
241ae9a8 MD |
13 | #include <lttng-events.h> |
14 | #include <wrapper/ringbuffer/frontend_types.h> | |
241ae9a8 | 15 | #include <lttng-tracer.h> |
ceabb767 | 16 | #include <lttng-endian.h> |
25b2f99a MD |
17 | |
18 | static | |
c26fddc2 | 19 | size_t procname_get_size(size_t offset) |
25b2f99a MD |
20 | { |
21 | size_t size = 0; | |
22 | ||
23 | size += sizeof(current->comm); | |
24 | return size; | |
25 | } | |
26 | ||
27 | /* | |
c26fddc2 MD |
28 | * Racy read of procname. We simply copy its whole array size. |
29 | * Races with /proc/<task>/procname write only. | |
25b2f99a MD |
30 | * Otherwise having to take a mutex for each event is cumbersome and |
31 | * could lead to crash in IRQ context and deadlock of the lockdep tracer. | |
32 | */ | |
33 | static | |
c26fddc2 | 34 | void procname_record(struct lttng_ctx_field *field, |
25b2f99a | 35 | struct lib_ring_buffer_ctx *ctx, |
a90917c3 | 36 | struct lttng_channel *chan) |
25b2f99a MD |
37 | { |
38 | chan->ops->event_write(ctx, current->comm, sizeof(current->comm)); | |
39 | } | |
40 | ||
f127e61e MD |
41 | static |
42 | void procname_get_value(struct lttng_ctx_field *field, | |
79150a49 | 43 | struct lttng_probe_ctx *lttng_probe_ctx, |
f127e61e MD |
44 | union lttng_ctx_value *value) |
45 | { | |
46 | value->str = current->comm; | |
47 | } | |
48 | ||
ceabb767 MD |
49 | static const struct lttng_type procname_array_elem_type = |
50 | __type_integer(char, 0, 0, -1, __BYTE_ORDER, 10, UTF8); | |
51 | ||
c26fddc2 | 52 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) |
25b2f99a MD |
53 | { |
54 | struct lttng_ctx_field *field; | |
25b2f99a MD |
55 | |
56 | field = lttng_append_context(ctx); | |
57 | if (!field) | |
09fec6b4 | 58 | return -ENOMEM; |
c26fddc2 | 59 | if (lttng_find_context(*ctx, "procname")) { |
44252f0f MD |
60 | lttng_remove_context_field(ctx, field); |
61 | return -EEXIST; | |
62 | } | |
c26fddc2 | 63 | field->event_field.name = "procname"; |
ceabb767 MD |
64 | field->event_field.type.atype = atype_array_nestable; |
65 | field->event_field.type.u.array_nestable.elem_type = &procname_array_elem_type; | |
66 | field->event_field.type.u.array_nestable.length = sizeof(current->comm); | |
67 | field->event_field.type.u.array_nestable.alignment = 0; | |
25b2f99a | 68 | |
c26fddc2 MD |
69 | field->get_size = procname_get_size; |
70 | field->record = procname_record; | |
f127e61e | 71 | field->get_value = procname_get_value; |
a9dd15da | 72 | lttng_context_update(*ctx); |
25b2f99a MD |
73 | return 0; |
74 | } | |
c26fddc2 | 75 | EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx); |