fix: use timespec64 on kernels that have it
[lttng-modules.git] / lttng-context-procname.c
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
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>
15#include <wrapper/vmalloc.h>
16#include <lttng-tracer.h>
25b2f99a
MD
17
18static
c26fddc2 19size_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 */
33static
c26fddc2 34void 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
41static
42void 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
c26fddc2 49int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
25b2f99a
MD
50{
51 struct lttng_ctx_field *field;
25b2f99a
MD
52
53 field = lttng_append_context(ctx);
54 if (!field)
09fec6b4 55 return -ENOMEM;
c26fddc2 56 if (lttng_find_context(*ctx, "procname")) {
44252f0f
MD
57 lttng_remove_context_field(ctx, field);
58 return -EEXIST;
59 }
c26fddc2 60 field->event_field.name = "procname";
25b2f99a
MD
61 field->event_field.type.atype = atype_array;
62 field->event_field.type.u.array.elem_type.atype = atype_integer;
63 field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
a90917c3 64 field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT;
06254b0f 65 field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char);
25b2f99a
MD
66 field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
67 field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
68 field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
69 field->event_field.type.u.array.length = sizeof(current->comm);
70
c26fddc2
MD
71 field->get_size = procname_get_size;
72 field->record = procname_record;
f127e61e 73 field->get_value = procname_get_value;
a9dd15da 74 lttng_context_update(*ctx);
25b2f99a
MD
75 wrapper_vmalloc_sync_all();
76 return 0;
77}
c26fddc2 78EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx);
This page took 0.039527 seconds and 4 git commands to generate.