4921ff4ad2e3c2d78ffa6e7c1709dc15923911b0
[lttng-modules.git] / lttng-context-egid.c
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-context-egid.c
4 *
5 * LTTng effective group ID context.
6 *
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * 2019 Michael Jeanson <mjeanson@efficios.com>
9 *
10 */
11
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <lttng-events.h>
15 #include <lttng-tracer.h>
16 #include <include/ringbuffer/frontend_types.h>
17 #include <wrapper/user_namespace.h>
18
19 static
20 size_t egid_get_size(size_t offset)
21 {
22 size_t size = 0;
23
24 size += lib_ring_buffer_align(offset, lttng_alignof(gid_t));
25 size += sizeof(gid_t);
26 return size;
27 }
28
29 static
30 void egid_record(struct lttng_ctx_field *field,
31 struct lib_ring_buffer_ctx *ctx,
32 struct lttng_channel *chan)
33 {
34 gid_t egid;
35
36 egid = lttng_current_egid();
37 lib_ring_buffer_align_ctx(ctx, lttng_alignof(egid));
38 chan->ops->event_write(ctx, &egid, sizeof(egid));
39 }
40
41 static
42 void egid_get_value(struct lttng_ctx_field *field,
43 struct lttng_probe_ctx *lttng_probe_ctx,
44 union lttng_ctx_value *value)
45 {
46 value->s64 = lttng_current_egid();
47 }
48
49 int lttng_add_egid_to_ctx(struct lttng_ctx **ctx)
50 {
51 struct lttng_ctx_field *field;
52
53 field = lttng_append_context(ctx);
54 if (!field)
55 return -ENOMEM;
56 if (lttng_find_context(*ctx, "egid")) {
57 lttng_remove_context_field(ctx, field);
58 return -EEXIST;
59 }
60 field->event_field.name = "egid";
61 field->event_field.type.atype = atype_integer;
62 field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT;
63 field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT;
64 field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t);
65 field->event_field.type.u.integer.reverse_byte_order = 0;
66 field->event_field.type.u.integer.base = 10;
67 field->event_field.type.u.integer.encoding = lttng_encode_none;
68 field->get_size = egid_get_size;
69 field->record = egid_record;
70 field->get_value = egid_get_value;
71 lttng_context_update(*ctx);
72 return 0;
73 }
74 EXPORT_SYMBOL_GPL(lttng_add_egid_to_ctx);
This page took 0.058867 seconds and 4 git commands to generate.