-
Notifications
You must be signed in to change notification settings - Fork 4
/
probe.c
55 lines (45 loc) · 933 Bytes
/
probe.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
52
53
54
55
/*
* File: probe.c
* Program to load, attach and
* destroy eBPF probe
*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <sys/resource.h>
#include <bpf/libbpf.h>
#include "probe.skel.h"
int cleanup(struct probe_bpf *skel)
{
probe_bpf__destroy(skel);
return -1;
}
static int libbpf_print_fn(enum libbpf_print_level level,
const char *format, va_list args)
{
return vfprintf(stderr, format, args);
}
int main(int argc, char **argv)
{
struct probe_bpf *skel;
int ret;
libbpf_set_print(libbpf_print_fn);
skel = probe_bpf__open_and_load();
if (!skel) {
fprintf(stderr, "Failed to open BPF skeleton\n");
return -1;
}
ret = probe_bpf__attach(skel);
if (ret) {
fprintf(stderr, "Failed to attach BPF skeleton\n");
goto cleanup;
}
while(1) {
sleep(5);
}
cleanup:
cleanup(skel);
return 0;
}