aboutsummaryrefslogtreecommitdiffstats
path: root/src/inotify.c
diff options
context:
space:
mode:
authorJoakim Verona2013-07-14 11:04:49 +0200
committerJoakim Verona2013-07-14 11:04:49 +0200
commit0bb9bb0841d89fff09820a57369df4cb01b16b43 (patch)
tree832bf9fa8415eef0ce464d22b3ee1300cfa90bb1 /src/inotify.c
parent3718127221fbbc31f8ebd027ab7c95403dbe9118 (diff)
parent3af1c8684ed6e48fbc21481d129e9aa164752c6e (diff)
downloademacs-0bb9bb0841d89fff09820a57369df4cb01b16b43.tar.gz
emacs-0bb9bb0841d89fff09820a57369df4cb01b16b43.zip
Merge branch 'trunk' into xwidget
Conflicts: src/xdisp.c
Diffstat (limited to 'src/inotify.c')
-rw-r--r--src/inotify.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/inotify.c b/src/inotify.c
index 4efef9e55b7..f4f850bf180 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -71,9 +71,8 @@ static Lisp_Object Qunmount; /* IN_UNMOUNT */
71# define IN_ONLYDIR 0 71# define IN_ONLYDIR 0
72#endif 72#endif
73 73
74enum { uninitialized = -100 };
75/* File handle for inotify. */ 74/* File handle for inotify. */
76static int inotifyfd = uninitialized; 75static int inotifyfd = -1;
77 76
78/* Assoc list of files being watched. 77/* Assoc list of files being watched.
79 Format: 78 Format:
@@ -139,8 +138,8 @@ inotifyevent_to_event (Lisp_Object watch_object, struct inotify_event const *ev)
139 138
140 return list2 (list4 (make_watch_descriptor (ev->wd), 139 return list2 (list4 (make_watch_descriptor (ev->wd),
141 mask_to_aspects (ev->mask), 140 mask_to_aspects (ev->mask),
142 make_number (ev->cookie), 141 name,
143 name), 142 make_number (ev->cookie)),
144 XCDR (watch_object)); 143 XCDR (watch_object));
145} 144}
146 145
@@ -158,15 +157,17 @@ inotify_callback (int fd, void *_)
158 157
159 to_read = 0; 158 to_read = 0;
160 if (ioctl (fd, FIONREAD, &to_read) == -1) 159 if (ioctl (fd, FIONREAD, &to_read) == -1)
161 report_file_error ("Error while trying to retrieve file system events", 160 xsignal1
162 Qnil); 161 (Qfile_notify_error,
162 build_string ("Error while trying to retrieve file system events"));
163 buffer = xmalloc (to_read); 163 buffer = xmalloc (to_read);
164 n = read (fd, buffer, to_read); 164 n = read (fd, buffer, to_read);
165 if (n < 0) 165 if (n < 0)
166 { 166 {
167 xfree (buffer); 167 xfree (buffer);
168 report_file_error ("Error while trying to read file system events", 168 xsignal1
169 Qnil); 169 (Qfile_notify_error,
170 build_string ("Error while trying to read file system events"));
170 } 171 }
171 172
172 EVENT_INIT (event); 173 EVENT_INIT (event);
@@ -242,7 +243,7 @@ symbol_to_inotifymask (Lisp_Object symb)
242 else if (EQ (symb, Qt) || EQ (symb, Qall_events)) 243 else if (EQ (symb, Qt) || EQ (symb, Qall_events))
243 return IN_ALL_EVENTS; 244 return IN_ALL_EVENTS;
244 else 245 else
245 signal_error ("Unknown aspect", symb); 246 xsignal2 (Qfile_notify_error, build_string ("Unknown aspect"), symb);
246} 247}
247 248
248static uint32_t 249static uint32_t
@@ -266,8 +267,10 @@ aspect_to_inotifymask (Lisp_Object aspect)
266DEFUN ("inotify-add-watch", Finotify_add_watch, Sinotify_add_watch, 3, 3, 0, 267DEFUN ("inotify-add-watch", Finotify_add_watch, Sinotify_add_watch, 3, 3, 0,
267 doc: /* Add a watch for FILE-NAME to inotify. 268 doc: /* Add a watch for FILE-NAME to inotify.
268 269
269A WATCH-DESCRIPTOR is returned on success. ASPECT might be one of the following 270Return a watch descriptor. The watch will look for ASPECT events and
270symbols or a list of those symbols: 271invoke CALLBACK when an event occurs.
272
273ASPECT might be one of the following symbols or a list of those symbols:
271 274
272access 275access
273attrib 276attrib
@@ -286,7 +289,7 @@ all-events or t
286move 289move
287close 290close
288 291
289The following symbols can also be added to a list of aspects 292The following symbols can also be added to a list of aspects:
290 293
291dont-follow 294dont-follow
292excl-unlink 295excl-unlink
@@ -294,11 +297,10 @@ mask-add
294oneshot 297oneshot
295onlydir 298onlydir
296 299
297Watching a directory is not recursive. CALLBACK gets called in case of an 300Watching a directory is not recursive. CALLBACK is passed a single argument
298event. It gets passed a single argument EVENT which contains an event structure 301EVENT which contains an event structure of the format
299of the format
300 302
301(WATCH-DESCRIPTOR ASPECTS COOKIE NAME) 303(WATCH-DESCRIPTOR ASPECTS NAME COOKIE)
302 304
303WATCH-DESCRIPTOR is the same object that was returned by this function. It can 305WATCH-DESCRIPTOR is the same object that was returned by this function. It can
304be tested for equality using `equal'. ASPECTS describes the event. It is a 306be tested for equality using `equal'. ASPECTS describes the event. It is a
@@ -310,11 +312,11 @@ isdir
310q-overflow 312q-overflow
311unmount 313unmount
312 314
315If a directory is watched then NAME is the name of file that caused the event.
316
313COOKIE is an object that can be compared using `equal' to identify two matching 317COOKIE is an object that can be compared using `equal' to identify two matching
314renames (moved-from and moved-to). 318renames (moved-from and moved-to).
315 319
316If a directory is watched then NAME is the name of file that caused the event.
317
318See inotify(7) and inotify_add_watch(2) for further information. The inotify fd 320See inotify(7) and inotify_add_watch(2) for further information. The inotify fd
319is managed internally and there is no corresponding inotify_init. Use 321is managed internally and there is no corresponding inotify_init. Use
320`inotify-rm-watch' to remove a watch. 322`inotify-rm-watch' to remove a watch.
@@ -329,15 +331,13 @@ is managed internally and there is no corresponding inotify_init. Use
329 331
330 CHECK_STRING (file_name); 332 CHECK_STRING (file_name);
331 333
332 if (inotifyfd == uninitialized) 334 if (inotifyfd < 0)
333 { 335 {
334 inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC); 336 inotifyfd = inotify_init1 (IN_NONBLOCK|IN_CLOEXEC);
335 if (inotifyfd == -1) 337 if (inotifyfd < 0)
336 { 338 xsignal1
337 inotifyfd = uninitialized; 339 (Qfile_notify_error,
338 report_file_error ("File watching feature (inotify) is not available", 340 build_string ("File watching feature (inotify) is not available"));
339 Qnil);
340 }
341 watch_list = Qnil; 341 watch_list = Qnil;
342 add_read_fd (inotifyfd, &inotify_callback, NULL); 342 add_read_fd (inotifyfd, &inotify_callback, NULL);
343 } 343 }
@@ -346,7 +346,8 @@ is managed internally and there is no corresponding inotify_init. Use
346 encoded_file_name = ENCODE_FILE (file_name); 346 encoded_file_name = ENCODE_FILE (file_name);
347 watchdesc = inotify_add_watch (inotifyfd, SSDATA (encoded_file_name), mask); 347 watchdesc = inotify_add_watch (inotifyfd, SSDATA (encoded_file_name), mask);
348 if (watchdesc == -1) 348 if (watchdesc == -1)
349 report_file_error ("Could not add watch for file", Fcons (file_name, Qnil)); 349 xsignal2 (Qfile_notify_error,
350 build_string ("Could not add watch for file"), file_name);
350 351
351 watch_descriptor = make_watch_descriptor (watchdesc); 352 watch_descriptor = make_watch_descriptor (watchdesc);
352 353
@@ -375,8 +376,8 @@ See inotify_rm_watch(2) for more information.
375 int wd = XINT (watch_descriptor); 376 int wd = XINT (watch_descriptor);
376 377
377 if (inotify_rm_watch (inotifyfd, wd) == -1) 378 if (inotify_rm_watch (inotifyfd, wd) == -1)
378 report_file_error ("Could not rm watch", Fcons (watch_descriptor, 379 xsignal2 (Qfile_notify_error,
379 Qnil)); 380 build_string ("Could not rm watch"), watch_descriptor);
380 381
381 /* Remove watch descriptor from watch list. */ 382 /* Remove watch descriptor from watch list. */
382 watch_object = Fassoc (watch_descriptor, watch_list); 383 watch_object = Fassoc (watch_descriptor, watch_list);
@@ -386,9 +387,9 @@ See inotify_rm_watch(2) for more information.
386 /* Cleanup if no more files are watched. */ 387 /* Cleanup if no more files are watched. */
387 if (NILP (watch_list)) 388 if (NILP (watch_list))
388 { 389 {
389 close (inotifyfd); 390 emacs_close (inotifyfd);
390 delete_read_fd (inotifyfd); 391 delete_read_fd (inotifyfd);
391 inotifyfd = uninitialized; 392 inotifyfd = -1;
392 } 393 }
393 394
394 return Qt; 395 return Qt;