Skip to content

Commit

Permalink
push the write.c codestyle more better
Browse files Browse the repository at this point in the history
  • Loading branch information
sf1999817 committed May 17, 2024
1 parent 75034fb commit 22fb316
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 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;
}
14 changes: 6 additions & 8 deletions eBPF_Supermarket/Filesystem_Subsystem/fs_watcher/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ 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 */
/* Set up libbpf errors and debug info callback */
libbpf_set_print(libbpf_print_fn);


/* Cleaner handling of Ctrl-C */
signal(SIGINT, sig_handler);
Expand Down Expand Up @@ -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;
}

0 comments on commit 22fb316

Please sign in to comment.