Skip to content

Commit

Permalink
youhua
Browse files Browse the repository at this point in the history
  • Loading branch information
sf1999817 committed May 17, 2024
1 parent 75034fb commit 992cd21
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 1 addition & 5 deletions eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -54,5 +49,6 @@ int BPF_KPROBE(vfs_write)
e->pid = pid;
}
bpf_ringbuf_submit(e,0);

return 0;
}
7 changes: 3 additions & 4 deletions eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ 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;
}

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 */
libbpf_set_print(libbpf_print_fn);

Expand Down Expand Up @@ -95,6 +95,5 @@ int main(int argc, char **argv)
/* Clean up */
ring_buffer__free(rb);
write_bpf__destroy(skel);

return err < 0 ? -err : 0;
}

0 comments on commit 992cd21

Please sign in to comment.