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