From d2a8b1e8a549c958c3a22990c228518810014e34 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 13 Oct 2021 16:42:24 +0200 Subject: [PATCH] db/update/InotifySource: make errors non-fatal --- src/db/update/InotifySource.cxx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/db/update/InotifySource.cxx b/src/db/update/InotifySource.cxx index 02f0d38f0..827998e6b 100644 --- a/src/db/update/InotifySource.cxx +++ b/src/db/update/InotifySource.cxx @@ -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 */