X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/67e515d346a32db16b5e7e0a2ec0b0a18b2fbe4e..1650d7102ae8ea943e4197b7d91198640f0e0ff6:/src/inotify.c diff --git a/src/inotify.c b/src/inotify.c index 525321b3b4..38c8df5a29 100644 --- a/src/inotify.c +++ b/src/inotify.c @@ -1,13 +1,13 @@ /* Inotify support for Emacs -Copyright (C) 2012-2015 Free Software Foundation, Inc. +Copyright (C) 2012-2016 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. +the Free Software Foundation, either version 3 of the License, or (at +your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,8 +25,6 @@ along with GNU Emacs. If not, see . */ #include "coding.h" #include "process.h" #include "keyboard.h" -#include "character.h" -#include "frame.h" /* Required for termhooks.h. */ #include "termhooks.h" #include @@ -48,8 +46,7 @@ along with GNU Emacs. If not, see . */ static int inotifyfd = -1; /* Assoc list of files being watched. - Format: - (watch-descriptor . callback) + Format: (watch-descriptor name callback) */ static Lisp_Object watch_list; @@ -108,27 +105,14 @@ inotifyevent_to_event (Lisp_Object watch_object, struct inotify_event const *ev) name = make_unibyte_string (ev->name, min (len, ev->len)); name = DECODE_FILE (name); } + else + name = XCAR (XCDR (watch_object)); return list2 (list4 (make_watch_descriptor (ev->wd), mask_to_aspects (ev->mask), name, make_number (ev->cookie)), - XCDR (watch_object)); -} - -/* Like report_file_error, but reports a file-notify-error instead. */ -static void -report_inotify_error (const char *string, Lisp_Object name) -{ - Lisp_Object data = CONSP (name) || NILP (name) ? name : list1 (name); - synchronize_system_messages_locale (); - char *str = strerror (errno); - Lisp_Object errstring - = code_convert_string_norecord (build_unibyte_string (str), - Vlocale_coding_system, 0); - Lisp_Object errdata = Fcons (errstring, data); - - xsignal (Qfile_notify_error, Fcons (build_string (string), errdata)); + Fnth (make_number (2), watch_object)); } /* This callback is called when the FD is available for read. The inotify @@ -145,15 +129,14 @@ inotify_callback (int fd, void *_) to_read = 0; if (ioctl (fd, FIONREAD, &to_read) == -1) - report_inotify_error ("Error while trying to retrieve file system events", - Qnil); + report_file_notify_error ("Error while retrieving file system events", + Qnil); buffer = xmalloc (to_read); n = read (fd, buffer, to_read); if (n < 0) { xfree (buffer); - report_inotify_error ("Error while trying to read file system events", - Qnil); + report_file_notify_error ("Error while reading file system events", Qnil); } EVENT_INIT (event); @@ -231,7 +214,7 @@ symbol_to_inotifymask (Lisp_Object symb) else { errno = EINVAL; - report_inotify_error ("Unknown aspect", symb); + report_file_notify_error ("Unknown aspect", symb); } } @@ -289,7 +272,7 @@ onlydir Watching a directory is not recursive. CALLBACK is passed a single argument EVENT which contains an event structure of the format -(WATCH-DESCRIPTOR ASPECTS NAME COOKIE) +\(WATCH-DESCRIPTOR ASPECTS NAME COOKIE) WATCH-DESCRIPTOR is the same object that was returned by this function. It can be tested for equality using `equal'. ASPECTS describes the event. It is a @@ -324,7 +307,7 @@ is managed internally and there is no corresponding inotify_init. Use { inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC); if (inotifyfd < 0) - report_inotify_error ("File watching (inotify) is not available", Qnil); + report_file_notify_error ("File watching is not available", Qnil); watch_list = Qnil; add_read_fd (inotifyfd, &inotify_callback, NULL); } @@ -333,7 +316,7 @@ is managed internally and there is no corresponding inotify_init. Use encoded_file_name = ENCODE_FILE (file_name); watchdesc = inotify_add_watch (inotifyfd, SSDATA (encoded_file_name), mask); if (watchdesc == -1) - report_inotify_error ("Could not add watch for file", file_name); + report_file_notify_error ("Could not add watch for file", file_name); watch_descriptor = make_watch_descriptor (watchdesc); @@ -343,7 +326,7 @@ is managed internally and there is no corresponding inotify_init. Use watch_list = Fdelete (watch_object, watch_list); /* Store watch object in watch list. */ - watch_object = Fcons (watch_descriptor, callback); + watch_object = list3 (watch_descriptor, encoded_file_name, callback); watch_list = Fcons (watch_object, watch_list); return watch_descriptor; @@ -362,7 +345,7 @@ See inotify_rm_watch(2) for more information. int wd = XINT (watch_descriptor); if (inotify_rm_watch (inotifyfd, wd) == -1) - report_inotify_error ("Could not rm watch", watch_descriptor); + report_file_notify_error ("Could not rm watch", watch_descriptor); /* Remove watch descriptor from watch list. */ watch_object = Fassoc (watch_descriptor, watch_list);