xref: /linux-tools/ebpf/libbpf-bootstrap/kprobe_ksysread.c (revision 1009c19dc94f77e7a7c049e186f796e4881717f9)
1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 /* Copyright (c) 2021 Sartura
3  * Based on minimal.c by Facebook */
4 
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <signal.h>
8 #include <string.h>
9 #include <errno.h>
10 #include <sys/resource.h>
11 #include <bpf/libbpf.h>
12 #include "kprobe_ksysread.skel.h"
13 
14 
15 static struct kprobe_ksysread_bpf *skel=NULL;
int_exit(int signo)16 static void int_exit(int signo) {
17     if (skel) {
18         kprobe_ksysread_bpf__destroy(skel);
19     }
20     exit(0);
21 }
22 
main(int argc,char ** argv)23 int main(int argc, char **argv) {
24 	int err;
25 
26 	/* Open load and verify BPF application */
27 	skel = kprobe_ksysread_bpf__open_and_load();
28 	if (!skel) {
29 		fprintf(stderr, "Failed to open BPF skeleton\n");
30 		return 1;
31 	}
32 
33 	/* Attach tracepoint handler */
34 	err = kprobe_ksysread_bpf__attach(skel);
35 	if (err) {
36 		fprintf(stderr, "Failed to attach BPF skeleton\n");
37 		goto cleanup;
38 	}
39     signal(SIGINT, int_exit);
40     signal(SIGTERM, int_exit);
41     while(1) sleep(3600);
42 
43 cleanup:
44     int_exit(0);
45 	return 0;
46 }
47