Krolyxon
Commit 8bce80f

Branches

Refs →

nsxiv8bce80f

Revised error reporting in autoreload_inotify

No repeated error messages after failed initialization. No error messages on
failed inotify_rm_watch().
Author
Bert Münnich
Date
2017-05-17 20:13 +0200
Parent
9ac8fc6
Commit
8bce80fdae23d0747efc8547fd33edbd246b54b6

+11 −20

1 file changed

  1. M autoreload_inotify.c +11 −20
M autoreload_inotify.c View
@@ -27,20 +27,16 @@
2727
2828 CLEANUP void arl_cleanup(arl_t *arl)
2929 {
30− if (arl->fd != -1 && arl->wd != -1) {
31− if (inotify_rm_watch(arl->fd, arl->wd))
32− error(0, 0, "Failed to remove inotify watch.");
33− }
30+ if (arl->fd != -1 && arl->wd != -1)
31+ inotify_rm_watch(arl->fd, arl->wd);
3432 }
3533
3634 static void arl_setup_dir(arl_t *arl, const char *filepath)
3735 {
3836 char *dntmp, *dn;
3937
40− if (arl->fd == -1) {
41− error(0, 0, "Uninitialized, could not add inotify watch on directory.");
38+ if (arl->fd == -1)
4239 return;
43− }
4440
4541 /* get dirname */
4642 dntmp = (char*) strdup(filepath);
@@ -52,7 +48,7 @@ static void arl_setup_dir(arl_t *arl, const char *filepath)
5248 */
5349 arl->wd = inotify_add_watch(arl->fd, dn, IN_CREATE);
5450 if (arl->wd == -1)
55− error(0, 0, "Failed to add inotify watch on directory '%s'.", dn);
51+ error(0, 0, "%s: Error watching directory", dn);
5652 else
5753 arl->watching_dir = true;
5854
@@ -68,10 +64,9 @@ bool arl_handle(arl_t *arl, const char *filepath)
6864
6965 ssize_t len = read(arl->fd, buf, sizeof(buf));
7066
71− if (len == -1) {
72− error(0, 0, "Failed to read inotify events.");
67+ if (len == -1)
7368 return false;
74− }
69+
7570 for (ptr = buf; ptr < buf + len; ptr += sizeof(*event) + event->len) {
7671 event = (const struct inotify_event*) ptr;
7772
@@ -92,8 +87,7 @@ bool arl_handle(arl_t *arl, const char *filepath)
9287
9388 /* cleanup, this has not been one-shot */
9489 if (arl->watching_dir) {
95− if (inotify_rm_watch(arl->fd, arl->wd))
96− error(0, 0, "Failed to remove inotify watch.");
90+ inotify_rm_watch(arl->fd, arl->wd);
9791 arl->watching_dir = false;
9892 }
9993 reload = true;
@@ -110,26 +104,23 @@ void arl_init(arl_t *arl)
110104 arl->fd = inotify_init();
111105 arl->watching_dir = false;
112106 if (arl->fd == -1)
113− error(0, 0, "Could not initialize inotify.");
107+ error(0, 0, "Could not initialize inotify, no automatic image reloading");
114108 }
115109
116110 void arl_setup(arl_t *arl, const char *filepath)
117111 {
118− if (arl->fd == -1) {
119− error(0, 0, "Uninitialized, could not add inotify watch.");
112+ if (arl->fd == -1)
120113 return;
121− }
122114
123115 /* may have switched from a deleted to another image */
124116 if (arl->watching_dir) {
125− if (inotify_rm_watch(arl->fd, arl->wd))
126− error(0, 0, "Failed to remove inotify watch.");
117+ inotify_rm_watch(arl->fd, arl->wd);
127118 arl->watching_dir = false;
128119 }
129120
130121 arl->wd = inotify_add_watch(arl->fd, filepath,
131122 IN_ONESHOT | IN_CLOSE_WRITE | IN_DELETE_SELF);
132123 if (arl->wd == -1)
133− error(0, 0, "Failed to add inotify watch on file '%s'.", filepath);
124+ error(0, 0, "%s: Error watching file", filepath);
134125 }
135126