I'm examining the source code of the current fatrace.
The main loop calling fanotify to obtain the value of data looks like:
res = read (fan_fd, buffer, 4096);
...
data = (struct fanotify_event_metadata *) buffer;
while (FAN_EVENT_OK (data, res)) {
...
data = FAN_EVENT_NEXT (data, res);
}
When it gets to extracting the filename associated with an event, the code looks like this:
snprintf (printbuf, sizeof (printbuf), "/proc/self/fd/%i", data->fd);
len = readlink (printbuf, pathname, sizeof (pathname));
I am confused why the filename is extracted from /proc/self/fd/"data->fd"
and not /proc/"data->pid"/fd/"data->fd"
?