diff options
| author | Michael Albinus | 2015-09-15 14:57:22 +0200 |
|---|---|---|
| committer | Michael Albinus | 2015-09-15 14:57:22 +0200 |
| commit | 67e515d346a32db16b5e7e0a2ec0b0a18b2fbe4e (patch) | |
| tree | 873bd87571a28945713ad777038c17f01cbfd647 /src | |
| parent | 20b177d54bb0fdc1b478f3c9db88c6afca55b069 (diff) | |
| download | emacs-67e515d346a32db16b5e7e0a2ec0b0a18b2fbe4e.tar.gz emacs-67e515d346a32db16b5e7e0a2ec0b0a18b2fbe4e.zip | |
Improve error reports in inotify.c
* src/inotify.c (report_inotify_error): New function. Clone of
report_w32notify_error.
(inotify_callback, symbol_to_inotifymask, Finotify_add_watch)
(Finotify_rm_watch): Use it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/inotify.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/inotify.c b/src/inotify.c index 2486563bf9b..525321b3b4f 100644 --- a/src/inotify.c +++ b/src/inotify.c | |||
| @@ -29,6 +29,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 29 | #include "frame.h" /* Required for termhooks.h. */ | 29 | #include "frame.h" /* Required for termhooks.h. */ |
| 30 | #include "termhooks.h" | 30 | #include "termhooks.h" |
| 31 | 31 | ||
| 32 | #include <errno.h> | ||
| 32 | #include <sys/inotify.h> | 33 | #include <sys/inotify.h> |
| 33 | #include <sys/ioctl.h> | 34 | #include <sys/ioctl.h> |
| 34 | 35 | ||
| @@ -115,6 +116,21 @@ inotifyevent_to_event (Lisp_Object watch_object, struct inotify_event const *ev) | |||
| 115 | XCDR (watch_object)); | 116 | XCDR (watch_object)); |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 119 | /* Like report_file_error, but reports a file-notify-error instead. */ | ||
| 120 | static void | ||
| 121 | report_inotify_error (const char *string, Lisp_Object name) | ||
| 122 | { | ||
| 123 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); | ||
| 124 | synchronize_system_messages_locale (); | ||
| 125 | char *str = strerror (errno); | ||
| 126 | Lisp_Object errstring | ||
| 127 | = code_convert_string_norecord (build_unibyte_string (str), | ||
| 128 | Vlocale_coding_system, 0); | ||
| 129 | Lisp_Object errdata = Fcons (errstring, data); | ||
| 130 | |||
| 131 | xsignal (Qfile_notify_error, Fcons (build_string (string), errdata)); | ||
| 132 | } | ||
| 133 | |||
| 118 | /* This callback is called when the FD is available for read. The inotify | 134 | /* This callback is called when the FD is available for read. The inotify |
| 119 | events are read from FD and converted into input_events. */ | 135 | events are read from FD and converted into input_events. */ |
| 120 | static void | 136 | static void |
| @@ -129,17 +145,15 @@ inotify_callback (int fd, void *_) | |||
| 129 | 145 | ||
| 130 | to_read = 0; | 146 | to_read = 0; |
| 131 | if (ioctl (fd, FIONREAD, &to_read) == -1) | 147 | if (ioctl (fd, FIONREAD, &to_read) == -1) |
| 132 | xsignal1 | 148 | report_inotify_error ("Error while trying to retrieve file system events", |
| 133 | (Qfile_notify_error, | 149 | Qnil); |
| 134 | build_string ("Error while trying to retrieve file system events")); | ||
| 135 | buffer = xmalloc (to_read); | 150 | buffer = xmalloc (to_read); |
| 136 | n = read (fd, buffer, to_read); | 151 | n = read (fd, buffer, to_read); |
| 137 | if (n < 0) | 152 | if (n < 0) |
| 138 | { | 153 | { |
| 139 | xfree (buffer); | 154 | xfree (buffer); |
| 140 | xsignal1 | 155 | report_inotify_error ("Error while trying to read file system events", |
| 141 | (Qfile_notify_error, | 156 | Qnil); |
| 142 | build_string ("Error while trying to read file system events")); | ||
| 143 | } | 157 | } |
| 144 | 158 | ||
| 145 | EVENT_INIT (event); | 159 | EVENT_INIT (event); |
| @@ -215,7 +229,10 @@ symbol_to_inotifymask (Lisp_Object symb) | |||
| 215 | else if (EQ (symb, Qt) || EQ (symb, Qall_events)) | 229 | else if (EQ (symb, Qt) || EQ (symb, Qall_events)) |
| 216 | return IN_ALL_EVENTS; | 230 | return IN_ALL_EVENTS; |
| 217 | else | 231 | else |
| 218 | xsignal2 (Qfile_notify_error, build_string ("Unknown aspect"), symb); | 232 | { |
| 233 | errno = EINVAL; | ||
| 234 | report_inotify_error ("Unknown aspect", symb); | ||
| 235 | } | ||
| 219 | } | 236 | } |
| 220 | 237 | ||
| 221 | static uint32_t | 238 | static uint32_t |
| @@ -307,9 +324,7 @@ is managed internally and there is no corresponding inotify_init. Use | |||
| 307 | { | 324 | { |
| 308 | inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC); | 325 | inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC); |
| 309 | if (inotifyfd < 0) | 326 | if (inotifyfd < 0) |
| 310 | xsignal1 | 327 | report_inotify_error ("File watching (inotify) is not available", Qnil); |
| 311 | (Qfile_notify_error, | ||
| 312 | build_string ("File watching feature (inotify) is not available")); | ||
| 313 | watch_list = Qnil; | 328 | watch_list = Qnil; |
| 314 | add_read_fd (inotifyfd, &inotify_callback, NULL); | 329 | add_read_fd (inotifyfd, &inotify_callback, NULL); |
| 315 | } | 330 | } |
| @@ -318,8 +333,7 @@ is managed internally and there is no corresponding inotify_init. Use | |||
| 318 | encoded_file_name = ENCODE_FILE (file_name); | 333 | encoded_file_name = ENCODE_FILE (file_name); |
| 319 | watchdesc = inotify_add_watch (inotifyfd, SSDATA (encoded_file_name), mask); | 334 | watchdesc = inotify_add_watch (inotifyfd, SSDATA (encoded_file_name), mask); |
| 320 | if (watchdesc == -1) | 335 | if (watchdesc == -1) |
| 321 | xsignal2 (Qfile_notify_error, | 336 | report_inotify_error ("Could not add watch for file", file_name); |
| 322 | build_string ("Could not add watch for file"), file_name); | ||
| 323 | 337 | ||
| 324 | watch_descriptor = make_watch_descriptor (watchdesc); | 338 | watch_descriptor = make_watch_descriptor (watchdesc); |
| 325 | 339 | ||
| @@ -348,8 +362,7 @@ See inotify_rm_watch(2) for more information. | |||
| 348 | int wd = XINT (watch_descriptor); | 362 | int wd = XINT (watch_descriptor); |
| 349 | 363 | ||
| 350 | if (inotify_rm_watch (inotifyfd, wd) == -1) | 364 | if (inotify_rm_watch (inotifyfd, wd) == -1) |
| 351 | xsignal2 (Qfile_notify_error, | 365 | report_inotify_error ("Could not rm watch", watch_descriptor); |
| 352 | build_string ("Could not rm watch"), watch_descriptor); | ||
| 353 | 366 | ||
| 354 | /* Remove watch descriptor from watch list. */ | 367 | /* Remove watch descriptor from watch list. */ |
| 355 | watch_object = Fassoc (watch_descriptor, watch_list); | 368 | watch_object = Fassoc (watch_descriptor, watch_list); |