I use libbpf write a bpf program to watch the file open action. I used BPF_MAP_TYPE_QUEUE to pass the pathname. It seem worked, but not normally.
libbpf: elf: skipping unrecognized data section(8) .rodata.str1.16
libbpf: elf: skipping unrecognized data section(22) .eh_frame
libbpf: elf: skipping relo section(23) .rel.eh_frame for section(22) .eh_frame
libbpf: Error in bpf_create_map_xattr(queue_map):Invalid argument(-22). Retrying without BTF.
******Loop times 0 ******
******Loop times 1 ******
pid=3478152 cmd=titan_monitor pathname=
pid=3478152 cmd=titan_monitor pathname=/
pid=3478152 cmd=titan_monitor pathname=uptime
pid=3478152 cmd=titan_monitor pathname=stat
pid=6311 cmd=python pathname=cmdline
pid=6311 cmd=python pathname=proc
pid=6311 cmd=python pathname=sem.1NGcnv
pid=6311 cmd=python pathname=sem.xW06WV
pid=6311 cmd=python pathname=sem.9GYRMO
pid=6311 cmd=python pathname=sem.a5psds
ç******Loop times 2 ******
pid=3478176 cmd=titanagent pathname=
pid=3478152 cmd=titan_monitor pathname=urandom
pid=3478152 cmd=titan_monitor pathname=/
pid=3478152 cmd=titan_monitor pathname=uptime
pid=3478152 cmd=titan_monitor pathname=stat
pid=3478152 cmd=titan_monitor pathname=cmdline
pid=3478152 cmd=titan_monitor pathname=/
pid=3478152 cmd=titan_monitor pathname=uptime
pid=3478152 cmd=titan_monitor pathname=stat
it loss the first value every time in the loop.
166 //print out
167 signal(SIGINT, do_quit);
168 int count = 0;
169 while (!quit) {
170 int key = 0;
171 unsigned long long val;
172 struct hash_key hkey = {}, nhkey= {};
173
174 printf("******Loop times %d ******\n", count);
175 count++;
176 memset(&nhkey, 0, sizeof(hkey));
177 while (bpf_map_lookup_and_delete_elem(queue_map_fd, 0, &nhkey) == 0) {
178 printf("pid=%d \t\t cmd=%s \t\t pathname=%s\n",
179 (__u32) nhkey.pid, nhkey.comm, hkey.pathname);
180 //print_stack(&nhkey, stack_map_fd);
181 hkey = nhkey;
182 //usleep(1000000);
183 }
184
185 usleep(1000000);
186 }
37 struct {
38 __uint(type, BPF_MAP_TYPE_QUEUE);
39 __type(value, struct hash_key);
40 __uint(max_entries, 10);
41 } queue_map SEC(".maps");
how to deal with this