diff options
| author | Michael Albinus | 2015-09-16 15:50:37 +0200 |
|---|---|---|
| committer | Michael Albinus | 2015-09-16 15:50:37 +0200 |
| commit | c762d3305cbd429606ef9f51f62b9bb3f36d00f2 (patch) | |
| tree | 309e869d65abc2fd0398d7656c30d820bf94d6c9 /src | |
| parent | 1636e8c75a0d4576e6ac7a246bd7a484a79ecbc2 (diff) | |
| download | emacs-c762d3305cbd429606ef9f51f62b9bb3f36d00f2.tar.gz emacs-c762d3305cbd429606ef9f51f62b9bb3f36d00f2.zip | |
Use common report_file_notify_error function
* src/fileio.c (report_file_notify_error): New function.
* src/inotify.c (report_inotify_error): Remove function.
(inotify_callback, symbol_to_inotifymask, Finotify_add_watch)
(Finotify_rm_watch): Use report_file_notify_error.
* src/lisp.h (report_file_notify_error): Declare external function.
* src/w32notify.c (report_w32notify_error): Remove function.
(Fw32notify_add_watch, Fw32notify_rm_watch):
Use report_file_notify_error.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 16 | ||||
| -rw-r--r-- | src/inotify.c | 30 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/w32notify.c | 29 |
4 files changed, 31 insertions, 45 deletions
diff --git a/src/fileio.c b/src/fileio.c index d4341f8fa59..69933ccd40b 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -210,6 +210,22 @@ report_file_error (char const *string, Lisp_Object name) | |||
| 210 | report_file_errno (string, name, errno); | 210 | report_file_errno (string, name, errno); |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | /* Like report_file_error, but reports a file-notify-error instead. */ | ||
| 214 | |||
| 215 | void | ||
| 216 | report_file_notify_error (const char *string, Lisp_Object name) | ||
| 217 | { | ||
| 218 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); | ||
| 219 | synchronize_system_messages_locale (); | ||
| 220 | char *str = strerror (errno); | ||
| 221 | Lisp_Object errstring | ||
| 222 | = code_convert_string_norecord (build_unibyte_string (str), | ||
| 223 | Vlocale_coding_system, 0); | ||
| 224 | Lisp_Object errdata = Fcons (errstring, data); | ||
| 225 | |||
| 226 | xsignal (Qfile_notify_error, Fcons (build_string (string), errdata)); | ||
| 227 | } | ||
| 228 | |||
| 213 | void | 229 | void |
| 214 | close_file_unwind (int fd) | 230 | close_file_unwind (int fd) |
| 215 | { | 231 | { |
diff --git a/src/inotify.c b/src/inotify.c index 3eda877975f..be8c1dd7553 100644 --- a/src/inotify.c +++ b/src/inotify.c | |||
| @@ -116,21 +116,6 @@ inotifyevent_to_event (Lisp_Object watch_object, struct inotify_event const *ev) | |||
| 116 | XCDR (watch_object)); | 116 | XCDR (watch_object)); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | /* Like report_file_error, but reports a file-notify-error instead. */ | ||
| 120 | static _Noreturn 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 | |||
| 134 | /* This callback is called when the FD is available for read. The inotify | 119 | /* This callback is called when the FD is available for read. The inotify |
| 135 | events are read from FD and converted into input_events. */ | 120 | events are read from FD and converted into input_events. */ |
| 136 | static void | 121 | static void |
| @@ -145,15 +130,14 @@ inotify_callback (int fd, void *_) | |||
| 145 | 130 | ||
| 146 | to_read = 0; | 131 | to_read = 0; |
| 147 | if (ioctl (fd, FIONREAD, &to_read) == -1) | 132 | if (ioctl (fd, FIONREAD, &to_read) == -1) |
| 148 | report_inotify_error ("Error while trying to retrieve file system events", | 133 | report_file_notify_error ("Error while retrieving file system events", |
| 149 | Qnil); | 134 | Qnil); |
| 150 | buffer = xmalloc (to_read); | 135 | buffer = xmalloc (to_read); |
| 151 | n = read (fd, buffer, to_read); | 136 | n = read (fd, buffer, to_read); |
| 152 | if (n < 0) | 137 | if (n < 0) |
| 153 | { | 138 | { |
| 154 | xfree (buffer); | 139 | xfree (buffer); |
| 155 | report_inotify_error ("Error while trying to read file system events", | 140 | report_file_notify_error ("Error while reading file system events", Qnil); |
| 156 | Qnil); | ||
| 157 | } | 141 | } |
| 158 | 142 | ||
| 159 | EVENT_INIT (event); | 143 | EVENT_INIT (event); |
| @@ -231,7 +215,7 @@ symbol_to_inotifymask (Lisp_Object symb) | |||
| 231 | else | 215 | else |
| 232 | { | 216 | { |
| 233 | errno = EINVAL; | 217 | errno = EINVAL; |
| 234 | report_inotify_error ("Unknown aspect", symb); | 218 | report_file_notify_error ("Unknown aspect", symb); |
| 235 | } | 219 | } |
| 236 | } | 220 | } |
| 237 | 221 | ||
| @@ -324,7 +308,7 @@ is managed internally and there is no corresponding inotify_init. Use | |||
| 324 | { | 308 | { |
| 325 | inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC); | 309 | inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC); |
| 326 | if (inotifyfd < 0) | 310 | if (inotifyfd < 0) |
| 327 | report_inotify_error ("File watching (inotify) is not available", Qnil); | 311 | report_file_notify_error ("File watching is not available", Qnil); |
| 328 | watch_list = Qnil; | 312 | watch_list = Qnil; |
| 329 | add_read_fd (inotifyfd, &inotify_callback, NULL); | 313 | add_read_fd (inotifyfd, &inotify_callback, NULL); |
| 330 | } | 314 | } |
| @@ -333,7 +317,7 @@ is managed internally and there is no corresponding inotify_init. Use | |||
| 333 | encoded_file_name = ENCODE_FILE (file_name); | 317 | encoded_file_name = ENCODE_FILE (file_name); |
| 334 | watchdesc = inotify_add_watch (inotifyfd, SSDATA (encoded_file_name), mask); | 318 | watchdesc = inotify_add_watch (inotifyfd, SSDATA (encoded_file_name), mask); |
| 335 | if (watchdesc == -1) | 319 | if (watchdesc == -1) |
| 336 | report_inotify_error ("Could not add watch for file", file_name); | 320 | report_file_notify_error ("Could not add watch for file", file_name); |
| 337 | 321 | ||
| 338 | watch_descriptor = make_watch_descriptor (watchdesc); | 322 | watch_descriptor = make_watch_descriptor (watchdesc); |
| 339 | 323 | ||
| @@ -362,7 +346,7 @@ See inotify_rm_watch(2) for more information. | |||
| 362 | int wd = XINT (watch_descriptor); | 346 | int wd = XINT (watch_descriptor); |
| 363 | 347 | ||
| 364 | if (inotify_rm_watch (inotifyfd, wd) == -1) | 348 | if (inotify_rm_watch (inotifyfd, wd) == -1) |
| 365 | report_inotify_error ("Could not rm watch", watch_descriptor); | 349 | report_file_notify_error ("Could not rm watch", watch_descriptor); |
| 366 | 350 | ||
| 367 | /* Remove watch descriptor from watch list. */ | 351 | /* Remove watch descriptor from watch list. */ |
| 368 | watch_object = Fassoc (watch_descriptor, watch_list); | 352 | watch_object = Fassoc (watch_descriptor, watch_list); |
diff --git a/src/lisp.h b/src/lisp.h index 71630edd0c8..acbd679b44b 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3840,6 +3840,7 @@ extern void fclose_unwind (void *); | |||
| 3840 | extern void restore_point_unwind (Lisp_Object); | 3840 | extern void restore_point_unwind (Lisp_Object); |
| 3841 | extern _Noreturn void report_file_errno (const char *, Lisp_Object, int); | 3841 | extern _Noreturn void report_file_errno (const char *, Lisp_Object, int); |
| 3842 | extern _Noreturn void report_file_error (const char *, Lisp_Object); | 3842 | extern _Noreturn void report_file_error (const char *, Lisp_Object); |
| 3843 | extern _Noreturn void report_file_notify_error (const char *, Lisp_Object); | ||
| 3843 | extern bool internal_delete_file (Lisp_Object); | 3844 | extern bool internal_delete_file (Lisp_Object); |
| 3844 | extern Lisp_Object emacs_readlinkat (int, const char *); | 3845 | extern Lisp_Object emacs_readlinkat (int, const char *); |
| 3845 | extern bool file_directory_p (const char *); | 3846 | extern bool file_directory_p (const char *); |
diff --git a/src/w32notify.c b/src/w32notify.c index a6b5c1908a1..e822d950263 100644 --- a/src/w32notify.c +++ b/src/w32notify.c | |||
| @@ -464,21 +464,6 @@ filter_list_to_flags (Lisp_Object filter_list) | |||
| 464 | return flags; | 464 | return flags; |
| 465 | } | 465 | } |
| 466 | 466 | ||
| 467 | /* Like report_file_error, but reports a file-notify-error instead. */ | ||
| 468 | static void | ||
| 469 | report_w32notify_error (const char *string, Lisp_Object name) | ||
| 470 | { | ||
| 471 | Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); | ||
| 472 | synchronize_system_messages_locale (); | ||
| 473 | char *str = strerror (errno); | ||
| 474 | Lisp_Object errstring | ||
| 475 | = code_convert_string_norecord (build_unibyte_string (str), | ||
| 476 | Vlocale_coding_system, 0); | ||
| 477 | Lisp_Object errdata = Fcons (errstring, data); | ||
| 478 | |||
| 479 | xsignal (Qfile_notify_error, Fcons (build_string (string), errdata)); | ||
| 480 | } | ||
| 481 | |||
| 482 | DEFUN ("w32notify-add-watch", Fw32notify_add_watch, | 467 | DEFUN ("w32notify-add-watch", Fw32notify_add_watch, |
| 483 | Sw32notify_add_watch, 3, 3, 0, | 468 | Sw32notify_add_watch, 3, 3, 0, |
| 484 | doc: /* Add a watch for filesystem events pertaining to FILE. | 469 | doc: /* Add a watch for filesystem events pertaining to FILE. |
| @@ -543,8 +528,8 @@ generate notifications correctly, though. */) | |||
| 543 | || (w32_major_version == 5 && w32_major_version < 1)) | 528 | || (w32_major_version == 5 && w32_major_version < 1)) |
| 544 | { | 529 | { |
| 545 | errno = ENOSYS; | 530 | errno = ENOSYS; |
| 546 | report_w32notify_error ("Watching filesystem events is not supported", | 531 | report_file_notify_error ("Watching filesystem events is not supported", |
| 547 | Qnil); | 532 | Qnil); |
| 548 | } | 533 | } |
| 549 | 534 | ||
| 550 | /* filenotify.el always passes us a directory, either the parent | 535 | /* filenotify.el always passes us a directory, either the parent |
| @@ -588,11 +573,11 @@ generate notifications correctly, though. */) | |||
| 588 | Vlocale_coding_system, 0); | 573 | Vlocale_coding_system, 0); |
| 589 | else | 574 | else |
| 590 | lisp_errstr = build_string (errstr); | 575 | lisp_errstr = build_string (errstr); |
| 591 | report_w32notify_error ("Cannot watch file", | 576 | report_file_notify_error ("Cannot watch file", |
| 592 | Fcons (lisp_errstr, Fcons (file, Qnil))); | 577 | Fcons (lisp_errstr, Fcons (file, Qnil))); |
| 593 | } | 578 | } |
| 594 | else | 579 | else |
| 595 | report_w32notify_error ("Cannot watch file", Fcons (file, Qnil)); | 580 | report_file_notify_error ("Cannot watch file", Fcons (file, Qnil)); |
| 596 | } | 581 | } |
| 597 | /* Store watch object in watch list. */ | 582 | /* Store watch object in watch list. */ |
| 598 | watch_descriptor = make_pointer_integer (dirwatch); | 583 | watch_descriptor = make_pointer_integer (dirwatch); |
| @@ -626,8 +611,8 @@ WATCH-DESCRIPTOR should be an object returned by `w32notify-add-watch'. */) | |||
| 626 | } | 611 | } |
| 627 | 612 | ||
| 628 | if (status == -1) | 613 | if (status == -1) |
| 629 | report_w32notify_error ("Invalid watch descriptor", Fcons (watch_descriptor, | 614 | report_file_notify_error ("Invalid watch descriptor", |
| 630 | Qnil)); | 615 | Fcons (watch_descriptor, Qnil)); |
| 631 | 616 | ||
| 632 | return Qnil; | 617 | return Qnil; |
| 633 | } | 618 | } |