-
Notifications
You must be signed in to change notification settings - Fork 104
/
hello.c
48 lines (40 loc) · 952 Bytes
/
hello.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
#include <stdio.h>
#include <unistd.h>
#include <sys/resource.h>
#include <bpf/libbpf.h>
#include "hello.skel.h"
int main(int argc, char **argv)
{
struct hello_bpf *obj;
int err = 0;
struct rlimit rlim_new = {
.rlim_cur = RLIM_INFINITY,
.rlim_max = RLIM_INFINITY,
};
err = setrlimit(RLIMIT_MEMLOCK, &rlim_new);
if (err) {
fprintf(stderr, "failed to change rlimit\n");
return 1;
}
obj = hello_bpf__open();
if (!obj) {
fprintf(stderr, "failed to open and/or load BPF object\n");
return 1;
}
err = hello_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object %d\n", err);
goto cleanup;
}
err = hello_bpf__attach(obj);
if (err) {
fprintf(stderr, "failed to attach BPF programs\n");
goto cleanup;
}
printf
("Successfully started! Tracing /sys/kernel/debug/tracing/trace_pipe...\n");
system("cat /sys/kernel/debug/tracing/trace_pipe");
cleanup:
hello_bpf__destroy(obj);
return err != 0;
}