diff --git a/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.bpf.c b/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.bpf.c index afd1ad244..74be2bedf 100644 --- a/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.bpf.c +++ b/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.bpf.c @@ -24,13 +24,8 @@ int BPF_KRETPROBE(do_sys_openat2_exit,long fd) pid_t pid; pid = bpf_get_current_pid_tgid() >> 32; - - e = bpf_ringbuf_reserve(&rb,sizeof(*e),0); - if(!e) - return 0; bpf_map_update_elem(&data,&pid,&fd,BPF_ANY); - bpf_ringbuf_submit(e,0); } SEC("kprobe/vfs_write") @@ -54,5 +49,6 @@ int BPF_KPROBE(vfs_write) e->pid = pid; } bpf_ringbuf_submit(e,0); + return 0; } diff --git a/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.c b/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.c index cfda09d1a..a9e2ff331 100644 --- a/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.c +++ b/eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.c @@ -28,7 +28,8 @@ static int write_event(void *ctx, void *data, size_t data_sz) time(&t); tm = localtime(&t); strftime(ts, sizeof(ts), "%H:%M:%S", tm); - printf("%-8s %-7ld %-7ld\n", ts, e->pid,e->fd); + //打印 + printf("%-8s %-7ld %-7ld\n", ts, e->pid,e->fd); return 0; } @@ -36,11 +37,10 @@ int main(int argc, char **argv) { struct ring_buffer *rb = NULL; struct write_bpf *skel; - int err; + int err; - /* Set up libbpf errors and debug info callback */ + /* Set up libbpf errors and debug info callback */ libbpf_set_print(libbpf_print_fn); - /* Cleaner handling of Ctrl-C */ signal(SIGINT, sig_handler); @@ -83,18 +83,16 @@ int main(int argc, char **argv) err = 0; break; } - if (err < 0) { printf("Error polling perf buffer: %d\n", err); break; } } - - -cleanup: + + cleanup: /* Clean up */ ring_buffer__free(rb); write_bpf__destroy(skel); - + return err < 0 ? -err : 0; } \ No newline at end of file