commit 8bce80fdae23d0747efc8547fd33edbd246b54b6
Author: Bert Münnich <ber.t_AT_posteo.de>
AuthorDate: Wed May 17 20:13:32 2017 +0200
Commit: Bert Münnich <ber.t_AT_posteo.de>
CommitDate: Wed May 17 20:13:32 2017 +0200
Revised error reporting in autoreload_inotify
No repeated error messages after failed initialization. No error messages on
failed inotify_rm_watch().
diff --git a/autoreload_inotify.c b/autoreload_inotify.c
index b536c2a..e44c2f3 100644
--- a/autoreload_inotify.c
+++ b/autoreload_inotify.c
_AT_@ -27,20 +27,16 @@
CLEANUP void arl_cleanup(arl_t *arl)
{
- if (arl->fd != -1 && arl->wd != -1) {
- if (inotify_rm_watch(arl->fd, arl->wd))
- error(0, 0, "Failed to remove inotify watch.");
- }
+ if (arl->fd != -1 && arl->wd != -1)
+ inotify_rm_watch(arl->fd, arl->wd);
}
static void arl_setup_dir(arl_t *arl, const char *filepath)
{
char *dntmp, *dn;
- if (arl->fd == -1) {
- error(0, 0, "Uninitialized, could not add inotify watch on directory.");
+ if (arl->fd == -1)
return;
- }
/* get dirname */
dntmp = (char*) strdup(filepath);
_AT_@ -52,7 +48,7 @@ static void arl_setup_dir(arl_t *arl, const char *filepath)
*/
arl->wd = inotify_add_watch(arl->fd, dn, IN_CREATE);
if (arl->wd == -1)
- error(0, 0, "Failed to add inotify watch on directory '%s'.", dn);
+ error(0, 0, "%s: Error watching directory", dn);
else
arl->watching_dir = true;
_AT_@ -68,10 +64,9 @@ bool arl_handle(arl_t *arl, const char *filepath)
ssize_t len = read(arl->fd, buf, sizeof(buf));
- if (len == -1) {
- error(0, 0, "Failed to read inotify events.");
+ if (len == -1)
return false;
- }
+
for (ptr = buf; ptr < buf + len; ptr += sizeof(*event) + event->len) {
event = (const struct inotify_event*) ptr;
_AT_@ -92,8 +87,7 @@ bool arl_handle(arl_t *arl, const char *filepath)
/* cleanup, this has not been one-shot */
if (arl->watching_dir) {
- if (inotify_rm_watch(arl->fd, arl->wd))
- error(0, 0, "Failed to remove inotify watch.");
+ inotify_rm_watch(arl->fd, arl->wd);
arl->watching_dir = false;
}
reload = true;
_AT_@ -110,26 +104,23 @@ void arl_init(arl_t *arl)
arl->fd = inotify_init();
arl->watching_dir = false;
if (arl->fd == -1)
- error(0, 0, "Could not initialize inotify.");
+ error(0, 0, "Could not initialize inotify, no automatic image reloading");
}
void arl_setup(arl_t *arl, const char *filepath)
{
- if (arl->fd == -1) {
- error(0, 0, "Uninitialized, could not add inotify watch.");
+ if (arl->fd == -1)
return;
- }
/* may have switched from a deleted to another image */
if (arl->watching_dir) {
- if (inotify_rm_watch(arl->fd, arl->wd))
- error(0, 0, "Failed to remove inotify watch.");
+ inotify_rm_watch(arl->fd, arl->wd);
arl->watching_dir = false;
}
arl->wd = inotify_add_watch(arl->fd, filepath,
IN_ONESHOT | IN_CLOSE_WRITE | IN_DELETE_SELF);
if (arl->wd == -1)
- error(0, 0, "Failed to add inotify watch on file '%s'.", filepath);
+ error(0, 0, "%s: Error watching file", filepath);
}
Received on Wed May 17 2017 - 20:26:18 CEST
This archive was generated by hypermail 2.3.0
: Wed May 17 2017 - 20:36:44 CEST