hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/samples/bpf/bpf_load.c
....@@ -16,7 +16,6 @@
1616 #include <linux/netlink.h>
1717 #include <linux/rtnetlink.h>
1818 #include <linux/types.h>
19
-#include <sys/types.h>
2019 #include <sys/socket.h>
2120 #include <sys/syscall.h>
2221 #include <sys/ioctl.h>
....@@ -41,7 +40,7 @@
4140 int prog_array_fd = -1;
4241
4342 struct bpf_map_data map_data[MAX_MAPS];
44
-int map_data_count = 0;
43
+int map_data_count;
4544
4645 static int populate_prog_array(const char *event, int prog_fd)
4746 {
....@@ -66,7 +65,7 @@
6665 else
6766 flags = O_WRONLY | O_APPEND;
6867
69
- fd = open("/sys/kernel/debug/tracing/kprobe_events", flags);
68
+ fd = open(DEBUGFS "kprobe_events", flags);
7069
7170 ret = write(fd, val, strlen(val));
7271 close(fd);
....@@ -302,8 +301,8 @@
302301 numa_node);
303302 }
304303 if (map_fd[i] < 0) {
305
- printf("failed to create a map: %d %s\n",
306
- errno, strerror(errno));
304
+ printf("failed to create map %d (%s): %d %s\n",
305
+ i, maps[i].name, errno, strerror(errno));
307306 return 1;
308307 }
309308 maps[i].fd = map_fd[i];
....@@ -491,8 +490,8 @@
491490
492491 /* Verify no newer features were requested */
493492 if (validate_zero) {
494
- addr = (unsigned char*) def + map_sz_copy;
495
- end = (unsigned char*) def + map_sz_elf;
493
+ addr = (unsigned char *) def + map_sz_copy;
494
+ end = (unsigned char *) def + map_sz_elf;
496495 for (; addr < end; addr++) {
497496 if (*addr != 0) {
498497 free(sym);
....@@ -665,24 +664,4 @@
665664 int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map)
666665 {
667666 return do_load_bpf_file(path, fixup_map);
668
-}
669
-
670
-void read_trace_pipe(void)
671
-{
672
- int trace_fd;
673
-
674
- trace_fd = open(DEBUGFS "trace_pipe", O_RDONLY, 0);
675
- if (trace_fd < 0)
676
- return;
677
-
678
- while (1) {
679
- static char buf[4096];
680
- ssize_t sz;
681
-
682
- sz = read(trace_fd, buf, sizeof(buf) - 1);
683
- if (sz > 0) {
684
- buf[sz] = 0;
685
- puts(buf);
686
- }
687
- }
688667 }