nsxiv8bce80f
Revised error reporting in autoreload_inotify
No repeated error messages after failed initialization. No error messages on failed inotify_rm_watch().
+11 −20
1 file changed
- M autoreload_inotify.c +11 −20
| @@ -27,20 +27,16 @@ | |||
| 27 | 27 | ||
| 28 | 28 | CLEANUP void arl_cleanup(arl_t *arl) | |
| 29 | 29 | { | |
| 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); | |
| 34 | 32 | } | |
| 35 | 33 | ||
| 36 | 34 | static void arl_setup_dir(arl_t *arl, const char *filepath) | |
| 37 | 35 | { | |
| 38 | 36 | char *dntmp, *dn; | |
| 39 | 37 | ||
| 40 | − | if (arl->fd == -1) { | |
| 41 | − | error(0, 0, "Uninitialized, could not add inotify watch on directory."); | |
| 38 | + | if (arl->fd == -1) | |
| 42 | 39 | return; | |
| 43 | − | } | |
| 44 | 40 | ||
| 45 | 41 | /* get dirname */ | |
| 46 | 42 | dntmp = (char*) strdup(filepath); | |
| @@ -52,7 +48,7 @@ static void arl_setup_dir(arl_t *arl, const char *filepath) | |||
| 52 | 48 | */ | |
| 53 | 49 | arl->wd = inotify_add_watch(arl->fd, dn, IN_CREATE); | |
| 54 | 50 | 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); | |
| 56 | 52 | else | |
| 57 | 53 | arl->watching_dir = true; | |
| 58 | 54 | ||
| @@ -68,10 +64,9 @@ bool arl_handle(arl_t *arl, const char *filepath) | |||
| 68 | 64 | ||
| 69 | 65 | ssize_t len = read(arl->fd, buf, sizeof(buf)); | |
| 70 | 66 | ||
| 71 | − | if (len == -1) { | |
| 72 | − | error(0, 0, "Failed to read inotify events."); | |
| 67 | + | if (len == -1) | |
| 73 | 68 | return false; | |
| 74 | − | } | |
| 69 | + | ||
| 75 | 70 | for (ptr = buf; ptr < buf + len; ptr += sizeof(*event) + event->len) { | |
| 76 | 71 | event = (const struct inotify_event*) ptr; | |
| 77 | 72 | ||
| @@ -92,8 +87,7 @@ bool arl_handle(arl_t *arl, const char *filepath) | |||
| 92 | 87 | ||
| 93 | 88 | /* cleanup, this has not been one-shot */ | |
| 94 | 89 | 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); | |
| 97 | 91 | arl->watching_dir = false; | |
| 98 | 92 | } | |
| 99 | 93 | reload = true; | |
| @@ -110,26 +104,23 @@ void arl_init(arl_t *arl) | |||
| 110 | 104 | arl->fd = inotify_init(); | |
| 111 | 105 | arl->watching_dir = false; | |
| 112 | 106 | if (arl->fd == -1) | |
| 113 | − | error(0, 0, "Could not initialize inotify."); | |
| 107 | + | error(0, 0, "Could not initialize inotify, no automatic image reloading"); | |
| 114 | 108 | } | |
| 115 | 109 | ||
| 116 | 110 | void arl_setup(arl_t *arl, const char *filepath) | |
| 117 | 111 | { | |
| 118 | − | if (arl->fd == -1) { | |
| 119 | − | error(0, 0, "Uninitialized, could not add inotify watch."); | |
| 112 | + | if (arl->fd == -1) | |
| 120 | 113 | return; | |
| 121 | − | } | |
| 122 | 114 | ||
| 123 | 115 | /* may have switched from a deleted to another image */ | |
| 124 | 116 | 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); | |
| 127 | 118 | arl->watching_dir = false; | |
| 128 | 119 | } | |
| 129 | 120 | ||
| 130 | 121 | arl->wd = inotify_add_watch(arl->fd, filepath, | |
| 131 | 122 | IN_ONESHOT | IN_CLOSE_WRITE | IN_DELETE_SELF); | |
| 132 | 123 | 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); | |
| 134 | 125 | } | |
| 135 | 126 | ||