request to summarily disregard inotify_add_watch IN_UNMOUNT
According to the 14926 release notes inotify_add_watch() does not support IN_UNMOUNT, which is eminently reasonable. Unfortunately, existing code that tries using the flag results in a hard fail on the watch add, which is throwing out the baby with the bathwater. Request is to treat IN_UNMOUNT like IN_OPEN and IN_ACCESS is treated on DriveFS (message). That is, pretend it never happened.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/inotify.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
int inotify_fd = inotify_init1(IN_CLOEXEC);
int flags = IN_ALL_EVENTS;
// all is good without IN_UNMOUNT
flags |= IN_UNMOUNT;
printf("flags: %x\n", flags);
int wd = inotify_add_watch(inotify_fd, "foo", flags);
if (wd < 0) {
perror("inotify_add_watch():");
}
printf("watching wd: %d\n", wd);
for (;;) {
static const int INOTIFY_BUF_SZ = sizeof(struct inotify_event) + NAME_MAX + 1;
char inotify_buf[INOTIFY_BUF_SZ];
int nread = read(inotify_fd, inotify_buf, INOTIFY_BUF_SZ);
struct inotify_event *event = (struct inotify_event *)inotify_buf;
printf("read: %d event wd: %d mask: %x\n", nread, event->wd, event->mask);
}
return EXIT_SUCCESS;
}
The documentation seems to say that IN_UMOUNT is only an output flag, which means it is only set on output from read(). However, the implementation on Ubuntu allows these output flags to be set as input flags (most likely ignoring the flags). I will make the change to match the behavior, thanks for reporting this.
You're absolutely right; interesting. Appreciate you clarifying that. One could even make an academic case that's a Linux bug. At least a documentation bug. One would have to leave it to the API lawyers whether this is a 'may' or 'shall not' case (ugh). Of course no app layer programmer has ever even thought about it.
LGTM in 14959. Mark as fixed if you like.