generated from inspektor-gadget/gadget-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.bpf.c
51 lines (38 loc) · 1.17 KB
/
program.bpf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
/* Copyright (c) 2024 CHANGEME-Authors */
#include <vmlinux.h>
#include <bpf/bpf_core_read.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <gadget/buffer.h>
#include <gadget/macros.h>
#include <gadget/mntns_filter.h>
#include <gadget/types.h>
#ifndef TASK_COMM_LEN
#define TASK_COMM_LEN 16
#endif
struct event {
gadget_timestamp timestamp;
gadget_mntns_id mntns_id;
__u32 pid;
__u8 comm[TASK_COMM_LEN];
};
GADGET_TRACER_MAP(events, 1024 * 256);
GADGET_TRACER(changeme_mytracer, events, event);
SEC("tracepoint/syscalls/sys_enter_chdir")
int tracepoint__sys_enter_chdir(struct trace_event_raw_sys_enter *ctx) {
struct event *event;
__u64 pid_tgid = bpf_get_current_pid_tgid();
event = gadget_reserve_buf(&events, sizeof(*event));
if (!event)
return 0;
/* event data */
event->timestamp = bpf_ktime_get_boot_ns();
event->mntns_id = gadget_get_mntns_id();
event->pid = pid_tgid >> 32;
bpf_get_current_comm(&event->comm, sizeof(event->comm));
/* emit event */
gadget_submit_buf(ctx, &events, event, sizeof(*event));
return 0;
}
char LICENSE[] SEC("license") = "GPL";