GOAL: print Hello every time a system call is executed.
CODE:
_kern.c
#include <linux/bpf.h>
#include "bpf_helpers.h"
SEC("tracepoint/syscalls/sys_enter")
int bpf_sys(struct syscalls_enter_open_args *ctx)
{
char fmt[] = "Hello\n";
bpf_trace_printk(fmt, sizeof(fmt));
return 0;
}
char _license[] SEC("license") = "GPL";
_user.c
#include <linux/bpf.h>
#include "libbpf.h"
#include <unistd.h>
#include <fcntl.h>
int main(int ac, char **argv)
{
int prog_fd, fd;
struct bpf_object *obj;
if (bpf_prog_load("tracesys_kern.o", BPF_PROG_TYPE_TRACEPOINT,
&obj, &prog_fd))
return 1;
fd = open("mine_user.c", O_RDONLY);
close(fd);
//fork();
return 0;
}
PROBLEM: when I run the program it just terminates without print "Hello" also if open system call is invoked.
QUESTION: what am I missing? I've tried also sys_enter_open instead of sys_enter