diff options
| author | Paul Eggert | 2017-03-30 11:08:23 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-03-30 11:08:42 -0700 |
| commit | 6ff870218dd4bc015cc4115ceb2febd8d807e57c (patch) | |
| tree | 67eaa089c0754194e75eea898e24c4a6bcfbe91a /test/src | |
| parent | 1be3330b31f9c0d0d0f7d25641e8b81c807ca616 (diff) | |
| download | emacs-6ff870218dd4bc015cc4115ceb2febd8d807e57c.tar.gz emacs-6ff870218dd4bc015cc4115ceb2febd8d807e57c.zip | |
Some inotify cleanup
This catches some problems with integer overflow and races
that I noticed in inotify.c after reviewing the changes
installed to fix Bug#26126.
* src/fns.c, src/lisp.h (equal_no_quit): Now extern.
* src/inotify.c (aspect_to_inotifymask):
Check for cycles and for improper lists.
(make_lispy_mask, lispy_mask_match_p): Remove.
All callers changed to use INTEGER_TO_CONS and CONS_TO_INTEGER.
(inotifyevent_to_event, add_watch):
Don’t assume watch descriptors and cookies fit in fixnums.
(add_watch): Use assoc_no_quit, not Fassoc.
Avoid integer overflow in (very!) long-running processes where
the Emacs watch ID could overflow. Avoid some duplicate code.
(find_descriptor): New function.
(remove_descriptor): First arg is now the returned value from
find_descriptor, rather than the descriptor. This way, the
value can be removed without calling Fdelete, which might quit.
Wait until the end (when watch_list is consistent) before signaling
any errors.
(remove_watch, inotify_callback):
Use find_descriptor to avoid the need for Fdelete.
(inotify_callback): Use simpler tests for ioctl failure.
Free temporary buffer if signaled, and put it on the stack if small.
Use ssize_t to index through read results, to avoid a cast.
(valid_watch_descriptor): New function, with a tighter check.
(Finotify_rm_watch, Finotify_valid_p): Use it.
(Finotify_valid_p): Use assoc_no_quit and ass_no_quit instead
of Fassoc. Do not assume the first assoc succeeds.
* test/src/inotify-tests.el (inotify-valid-p-simple):
Add inotify-valid-p tests, some of which dump core without
the fixes noted above.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/inotify-tests.el | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/src/inotify-tests.el b/test/src/inotify-tests.el index f30aecc9c4f..987e1fc0777 100644 --- a/test/src/inotify-tests.el +++ b/test/src/inotify-tests.el | |||
| @@ -28,6 +28,13 @@ | |||
| 28 | (declare-function inotify-add-watch "inotify.c" (file-name aspect callback)) | 28 | (declare-function inotify-add-watch "inotify.c" (file-name aspect callback)) |
| 29 | (declare-function inotify-rm-watch "inotify.c" (watch-descriptor)) | 29 | (declare-function inotify-rm-watch "inotify.c" (watch-descriptor)) |
| 30 | 30 | ||
| 31 | (ert-deftest inotify-valid-p-simple () | ||
| 32 | "Simple tests for `inotify-valid-p'." | ||
| 33 | (skip-unless (featurep 'inotify)) | ||
| 34 | (should-not (inotify-valid-p 0)) | ||
| 35 | (should-not (inotify-valid-p nil)) | ||
| 36 | (should-not (inotify-valid-p '(0 . 0)))) | ||
| 37 | |||
| 31 | ;; (ert-deftest filewatch-file-watch-aspects-check () | 38 | ;; (ert-deftest filewatch-file-watch-aspects-check () |
| 32 | ;; "Test whether `file-watch' properly checks the aspects." | 39 | ;; "Test whether `file-watch' properly checks the aspects." |
| 33 | ;; (let ((temp-file (make-temp-file "filewatch-aspects"))) | 40 | ;; (let ((temp-file (make-temp-file "filewatch-aspects"))) |
| @@ -56,7 +63,9 @@ | |||
| 56 | (insert "Foo\n")) | 63 | (insert "Foo\n")) |
| 57 | (read-event nil nil 5) | 64 | (read-event nil nil 5) |
| 58 | (should (> events 0))) | 65 | (should (> events 0))) |
| 66 | (should (inotify-valid-p wd)) | ||
| 59 | (inotify-rm-watch wd) | 67 | (inotify-rm-watch wd) |
| 68 | (should-not (inotify-valid-p wd)) | ||
| 60 | (delete-file temp-file))))) | 69 | (delete-file temp-file))))) |
| 61 | 70 | ||
| 62 | (provide 'inotify-tests) | 71 | (provide 'inotify-tests) |