diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-10-05 14:44:17 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-10-05 16:14:37 +0200 |
commit | 9e5fd717994a4935490a0a0b04599d0ccbc66855 (patch) | |
tree | fb5926f078d34f0f0b8c6b4bb1c8ea3e23c5175d /src/basic/inotify-util.c | |
parent | d8e32c471f6a52407184e421243b174f7480d180 (diff) | |
download | systemd-9e5fd717994a4935490a0a0b04599d0ccbc66855.tar.gz |
basic: split out inotify-related calls from fs-util.h → inotify-util.h
Diffstat (limited to 'src/basic/inotify-util.c')
-rw-r--r-- | src/basic/inotify-util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/basic/inotify-util.c b/src/basic/inotify-util.c new file mode 100644 index 0000000000..848f8590fa --- /dev/null +++ b/src/basic/inotify-util.c @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "fd-util.h" +#include "inotify-util.h" + +int inotify_add_watch_fd(int fd, int what, uint32_t mask) { + int wd; + + /* 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; + + return wd; +} + +int inotify_add_watch_and_warn(int fd, const char *pathname, uint32_t mask) { + int wd; + + wd = inotify_add_watch(fd, pathname, mask); + if (wd < 0) { + if (errno == ENOSPC) + return log_error_errno(errno, "Failed to add a watch for %s: inotify watch limit reached", pathname); + + return log_error_errno(errno, "Failed to add a watch for %s: %m", pathname); + } + + return wd; +} |