db/update/InotifySource: make errors non-fatal

This commit is contained in:
Max Kellermann 2021-10-13 16:42:24 +02:00
parent 184e8eca7c
commit d2a8b1e8a5

View File

@ -20,7 +20,6 @@
#include "InotifySource.hxx"
#include "InotifyDomain.hxx"
#include "io/FileDescriptor.hxx"
#include "system/FatalError.hxx"
#include "system/Error.hxx"
#include "Log.hxx"
@ -39,10 +38,17 @@ InotifySource::OnSocketReady([[maybe_unused]] unsigned flags) noexcept
auto ifd = socket_event.GetFileDescriptor();
ssize_t nbytes = ifd.Read(buffer, sizeof(buffer));
if (nbytes < 0)
FatalSystemError("Failed to read from inotify");
if (nbytes == 0)
FatalError("end of file from inotify");
if (nbytes <= 0) {
if (nbytes < 0)
FmtError(inotify_domain,
"Failed to read from inotify: {}",
strerror(errno));
else
LogError(inotify_domain,
"end of file from inotify");
socket_event.Cancel();
return;
}
const uint8_t *p = buffer, *const end = p + nbytes;
@ -101,7 +107,8 @@ InotifySource::Remove(unsigned wd) noexcept
auto ifd = socket_event.GetFileDescriptor();
int ret = inotify_rm_watch(ifd.Get(), wd);
if (ret < 0 && errno != EINVAL)
LogErrno(inotify_domain, "inotify_rm_watch() has failed");
FmtError(inotify_domain, "inotify_rm_watch() has failed: {}",
strerror(errno));
/* EINVAL may happen here when the file has been deleted; the
kernel seems to auto-unregister deleted files */