diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-09 12:40:39 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-09 12:52:07 +0100 |
commit | 3777940ab283d41d317d0efd69abe8b0498bef4b (patch) | |
tree | 91e33da89641b320c61b2c0a7eb4bdbead052cf6 | |
parent | 7a0895c2eb6c3e2573f246b93a61a6b4a2aa44d3 (diff) | |
download | systemd-3777940ab283d41d317d0efd69abe8b0498bef4b.tar.gz |
inotify-util: improve reported error codes when inotify_add_watch() fails
-rw-r--r-- | src/basic/inotify-util.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/basic/inotify-util.c b/src/basic/inotify-util.c index 848f8590fa..6da974dec0 100644 --- a/src/basic/inotify-util.c +++ b/src/basic/inotify-util.c @@ -2,14 +2,26 @@ #include "fd-util.h" #include "inotify-util.h" +#include "stat-util.h" int inotify_add_watch_fd(int fd, int what, uint32_t mask) { - int wd; + int wd, r; /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */ wd = inotify_add_watch(fd, FORMAT_PROC_FD_PATH(what), mask); - if (wd < 0) - return -errno; + if (wd < 0) { + if (errno != ENOENT) + return -errno; + + /* Didn't work with ENOENT? If so, then either /proc/ isn't mounted, or the fd is bad */ + r = proc_mounted(); + if (r == 0) + return -ENOSYS; + if (r > 0) + return -EBADF; + + return -ENOENT; /* OK, no clue, let's propagate the original error */ + } return wd; } |