]>
Commit | Line | Data |
---|---|---|
4d2b74dd | 1 | '\" t |
415f63be | 2 | .\" Copyright (C) 2006, 2014 Michael Kerrisk <mtk.manpages@gmail.com> |
ecd96f7c | 3 | .\" Copyright (C) 2014 Heinrich Schuchardt <xypron.glpk@gmx.de> |
4d2b74dd | 4 | .\" |
93015253 | 5 | .\" %%%LICENSE_START(VERBATIM) |
4d2b74dd MK |
6 | .\" Permission is granted to make and distribute verbatim copies of this |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
4d2b74dd MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
10d76543 MK |
18 | .\" the use of the information contained herein. The author(s) may not |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
4d2b74dd MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 25 | .\" %%%LICENSE_END |
4d2b74dd | 26 | .\" |
6b621d05 | 27 | .TH INOTIFY 7 2020-02-09 "Linux" "Linux Programmer's Manual" |
4d2b74dd | 28 | .SH NAME |
9ee4a2b6 | 29 | inotify \- monitoring filesystem events |
4d2b74dd MK |
30 | .SH DESCRIPTION |
31 | The | |
c13182ef | 32 | .I inotify |
9ee4a2b6 | 33 | API provides a mechanism for monitoring filesystem events. |
4d2b74dd MK |
34 | Inotify can be used to monitor individual files, |
35 | or to monitor directories. | |
36 | When a directory is monitored, inotify will return events | |
37 | for the directory itself, and for files inside the directory. | |
a721e8b2 | 38 | .PP |
c13182ef | 39 | The following system calls are used with this API: |
356911f6 | 40 | .IP * 3 |
4d2b74dd | 41 | .BR inotify_init (2) |
c13182ef | 42 | creates an inotify instance and returns a file descriptor |
a2cc46ca | 43 | referring to the inotify instance. |
43bb5faf MK |
44 | The more recent |
45 | .BR inotify_init1 (2) | |
46 | is like | |
47 | .BR inotify_init (2), | |
356911f6 MK |
48 | but has a |
49 | .IR flags | |
50 | argument that provides access to some extra functionality. | |
51 | .IP * | |
4d2b74dd | 52 | .BR inotify_add_watch (2) |
a2cc46ca | 53 | manipulates the "watch list" associated with an inotify instance. |
3a065ac0 | 54 | Each item ("watch") in the watch list specifies the pathname of |
c13182ef | 55 | a file or directory, |
4d2b74dd MK |
56 | along with some set of events that the kernel should monitor for the |
57 | file referred to by that pathname. | |
63f6a20a | 58 | .BR inotify_add_watch (2) |
4d2b74dd MK |
59 | either creates a new watch item, or modifies an existing watch. |
60 | Each watch has a unique "watch descriptor", an integer | |
61 | returned by | |
63f6a20a | 62 | .BR inotify_add_watch (2) |
4d2b74dd | 63 | when the watch is created. |
356911f6 MK |
64 | .IP * |
65 | When events occur for monitored files and directories, | |
66 | those events are made available to the application as structured data that | |
67 | can be read from the inotify file descriptor using | |
68 | .BR read (2) | |
69 | (see below). | |
70 | .IP * | |
4d2b74dd MK |
71 | .BR inotify_rm_watch (2) |
72 | removes an item from an inotify watch list. | |
356911f6 | 73 | .IP * |
c13182ef | 74 | When all file descriptors referring to an inotify |
356911f6 MK |
75 | instance have been closed (using |
76 | .BR close (2)), | |
c13182ef | 77 | the underlying object and its resources are |
3b777aff | 78 | freed for reuse by the kernel; |
4d2b74dd | 79 | all associated watches are automatically freed. |
f070e954 | 80 | .PP |
6b1cc2c9 MK |
81 | With careful programming, |
82 | an application can use inotify to efficiently monitor and cache | |
83 | the state of a set of filesystem objects. | |
84 | However, robust applications should allow for the fact that bugs | |
85 | in the monitoring logic or races of the kind described below | |
86 | may leave the cache inconsistent with the filesystem state. | |
e3a0ac0e | 87 | It is probably wise to do some consistency checking, |
6b1cc2c9 | 88 | and rebuild the cache when inconsistencies are detected. |
ff6e2397 | 89 | .SS Reading events from an inotify file descriptor |
4d2b74dd MK |
90 | To determine what events have occurred, an application |
91 | .BR read (2)s | |
92 | from the inotify file descriptor. | |
c13182ef | 93 | If no events have so far occurred, then, |
11da88fb | 94 | assuming a blocking file descriptor, |
63f6a20a | 95 | .BR read (2) |
01538d0d MK |
96 | will block until at least one event occurs |
97 | (unless interrupted by a signal, | |
98 | in which case the call fails with the error | |
99 | .BR EINTR ; | |
100 | see | |
101 | .BR signal (7)). | |
a721e8b2 | 102 | .PP |
4d2b74dd | 103 | Each successful |
63f6a20a | 104 | .BR read (2) |
4d2b74dd | 105 | returns a buffer containing one or more of the following structures: |
e646a1ba | 106 | .PP |
a08ea57c | 107 | .in +4n |
e646a1ba | 108 | .EX |
4d2b74dd MK |
109 | struct inotify_event { |
110 | int wd; /* Watch descriptor */ | |
24bbe02c MK |
111 | .\" FIXME . The type of the 'wd' field should probably be "int32_t". |
112 | .\" I submitted a patch to fix this. See the LKML thread | |
113 | .\" "[patch] Fix type errors in inotify interfaces", 18 Nov 2008 | |
6e6231c1 | 114 | .\" Glibc bug filed: http://sources.redhat.com/bugzilla/show_bug.cgi?id=7040 |
425ad621 | 115 | uint32_t mask; /* Mask describing event */ |
c13182ef | 116 | uint32_t cookie; /* Unique cookie associating related |
4d2b74dd | 117 | events (for rename(2)) */ |
84c517a4 | 118 | uint32_t len; /* Size of \fIname\fP field */ |
4d2b74dd MK |
119 | char name[]; /* Optional null-terminated name */ |
120 | }; | |
b8302363 | 121 | .EE |
a08ea57c | 122 | .in |
a721e8b2 | 123 | .PP |
4d2b74dd MK |
124 | .I wd |
125 | identifies the watch for which this event occurs. | |
c13182ef | 126 | It is one of the watch descriptors returned by a previous call to |
63f6a20a | 127 | .BR inotify_add_watch (2). |
a721e8b2 | 128 | .PP |
4d2b74dd MK |
129 | .I mask |
130 | contains bits that describe the event that occurred (see below). | |
a721e8b2 | 131 | .PP |
4d2b74dd MK |
132 | .I cookie |
133 | is a unique integer that connects related events. | |
34d4e61d | 134 | Currently, this is used only for rename events, and |
4d2b74dd | 135 | allows the resulting pair of |
bc636d8a | 136 | .B IN_MOVED_FROM |
c13182ef | 137 | and |
bc636d8a | 138 | .B IN_MOVED_TO |
4d2b74dd | 139 | events to be connected by the application. |
591b7a5f MK |
140 | For all other event types, |
141 | .I cookie | |
142 | is set to 0. | |
a721e8b2 | 143 | .PP |
c13182ef | 144 | The |
4d2b74dd | 145 | .I name |
33a0ccb2 | 146 | field is present only when an event is returned |
c13182ef | 147 | for a file inside a watched directory; |
d1203f45 | 148 | it identifies the filename within the watched directory. |
454ab872 | 149 | This filename is null-terminated, |
d1a71985 | 150 | and may include further null bytes (\(aq\e0\(aq) to align subsequent reads to a |
4d2b74dd | 151 | suitable address boundary. |
a721e8b2 | 152 | .PP |
4d2b74dd MK |
153 | The |
154 | .I len | |
c13182ef | 155 | field counts all of the bytes in |
4d2b74dd | 156 | .IR name , |
c13182ef | 157 | including the null bytes; |
4d2b74dd MK |
158 | the length of each |
159 | .I inotify_event | |
160 | structure is thus | |
655684a9 | 161 | .IR "sizeof(struct inotify_event)+len" . |
a721e8b2 | 162 | .PP |
988db661 | 163 | The behavior when the buffer given to |
c7e3ee6f | 164 | .BR read (2) |
988db661 | 165 | is too small to return information about the next event depends |
c7e3ee6f MK |
166 | on the kernel version: in kernels before 2.6.21, |
167 | .BR read (2) | |
168 | returns 0; since kernel 2.6.21, | |
169 | .BR read (2) | |
170 | fails with the error | |
171 | .BR EINVAL . | |
4ba272b3 | 172 | Specifying a buffer of size |
a721e8b2 | 173 | .PP |
4ba272b3 | 174 | sizeof(struct inotify_event) + NAME_MAX + 1 |
a721e8b2 | 175 | .PP |
4ba272b3 | 176 | will be sufficient to read at least one event. |
4d2b74dd | 177 | .SS inotify events |
c13182ef | 178 | The |
4d2b74dd MK |
179 | .BR inotify_add_watch (2) |
180 | .I mask | |
c13182ef | 181 | argument and the |
4d2b74dd MK |
182 | .I mask |
183 | field of the | |
184 | .I inotify_event | |
185 | structure returned when | |
186 | .BR read (2)ing | |
187 | an inotify file descriptor are both bit masks identifying | |
188 | inotify events. | |
189 | The following bits can be specified in | |
190 | .I mask | |
191 | when calling | |
63f6a20a | 192 | .BR inotify_add_watch (2) |
c13182ef | 193 | and may be returned in the |
4d2b74dd MK |
194 | .I mask |
195 | field returned by | |
63f6a20a | 196 | .BR read (2): |
64aa9bcb | 197 | .RS 4 |
c577b95c | 198 | .TP |
f279ad49 | 199 | .BR IN_ACCESS " (+)" |
70f70c9d MK |
200 | File was accessed (e.g., |
201 | .BR read (2), | |
f23fc716 | 202 | .BR execve (2)). |
3f174f7d | 203 | .TP |
f23fc716 | 204 | .BR IN_ATTRIB " (*)" |
b0e1ac43 MK |
205 | Metadata changed\(emfor example, permissions (e.g., |
206 | .BR chmod (2)), | |
207 | timestamps (e.g., | |
208 | .BR utimensat (2)), | |
209 | extended attributes | |
210 | .RB ( setxattr (2)), | |
211 | link count (since Linux 2.6.25; e.g., | |
a4439a50 MK |
212 | .\" FIXME . |
213 | .\" Events do not occur for link count changes on a file inside a monitored | |
214 | .\" directory. This differs from other metadata changes for files inside | |
215 | .\" a monitored directory. | |
b0e1ac43 MK |
216 | for the target of |
217 | .BR link (2) | |
218 | and for | |
219 | .BR unlink (2)), | |
220 | and user/group ID (e.g., | |
221 | .BR chown (2)). | |
3f174f7d | 222 | .TP |
858bbaaa | 223 | .BR IN_CLOSE_WRITE " (+)" |
f23fc716 | 224 | File opened for writing was closed. |
3f174f7d | 225 | .TP |
f23fc716 | 226 | .BR IN_CLOSE_NOWRITE " (*)" |
7465ffa6 | 227 | File or directory not opened for writing was closed. |
3f174f7d | 228 | .TP |
e95b1911 | 229 | .BR IN_CREATE " (+)" |
7a64793b MK |
230 | File/directory created in watched directory (e.g., |
231 | .BR open (2) | |
232 | .BR O_CREAT , | |
233 | .BR mkdir (2), | |
234 | .BR link (2), | |
1a737afd | 235 | .BR symlink (2), |
7a64793b MK |
236 | .BR bind (2) |
237 | on a UNIX domain socket). | |
3f174f7d | 238 | .TP |
e95b1911 | 239 | .BR IN_DELETE " (+)" |
f23fc716 | 240 | File/directory deleted from watched directory. |
3f174f7d MK |
241 | .TP |
242 | .B IN_DELETE_SELF | |
243 | Watched file/directory was itself deleted. | |
4a1e4cca MK |
244 | (This event also occurs if an object is moved to another filesystem, |
245 | since | |
246 | .BR mv (1) | |
247 | in effect copies the file to the other filesystem and | |
49b07b8f | 248 | then deletes it from the original filesystem.) |
39f43968 MK |
249 | In addition, an |
250 | .B IN_IGNORED | |
251 | event will subsequently be generated for the watch descriptor. | |
3f174f7d | 252 | .TP |
e06fc20c | 253 | .BR IN_MODIFY " (+)" |
f54a1255 MK |
254 | File was modified (e.g., |
255 | .BR write (2), | |
256 | .BR truncate (2)). | |
3f174f7d MK |
257 | .TP |
258 | .B IN_MOVE_SELF | |
259 | Watched file/directory was itself moved. | |
260 | .TP | |
e95b1911 | 261 | .BR IN_MOVED_FROM " (+)" |
107375cf | 262 | Generated for the directory containing the old filename |
f23fc716 | 263 | when a file is renamed. |
3f174f7d | 264 | .TP |
e95b1911 | 265 | .BR IN_MOVED_TO " (+)" |
107375cf | 266 | Generated for the directory containing the new filename |
f23fc716 | 267 | when a file is renamed. |
3f174f7d | 268 | .TP |
f23fc716 | 269 | .BR IN_OPEN " (*)" |
7465ffa6 | 270 | File or directory was opened. |
64aa9bcb | 271 | .RE |
4d2b74dd | 272 | .PP |
7954e552 MK |
273 | Inotify monitoring is inode-based: when monitoring a file |
274 | (but not when monitoring the directory containing a file), | |
275 | an event can be generated for activity on any link to the file | |
276 | (in the same or a different directory). | |
a721e8b2 | 277 | .PP |
e95b1911 MK |
278 | When monitoring a directory: |
279 | .IP * 3 | |
280 | the events marked above with an asterisk (*) can occur both | |
281 | for the directory itself and for objects inside the directory; and | |
282 | .IP * | |
283 | the events marked with a plus sign (+) occur only for objects | |
284 | inside the directory (not for the directory itself). | |
285 | .PP | |
705bb673 MK |
286 | .IR Note : |
287 | when monitoring a directory, | |
288 | events are not generated for the files inside the directory | |
289 | when the events are performed via a pathname (i.e., a link) | |
290 | that lies outside the monitored directory. | |
a721e8b2 | 291 | .PP |
e95b1911 | 292 | When events are generated for objects inside a watched directory, the |
4d2b74dd MK |
293 | .I name |
294 | field in the returned | |
295 | .I inotify_event | |
296 | structure identifies the name of the file within the directory. | |
297 | .PP | |
298 | The | |
299 | .B IN_ALL_EVENTS | |
300 | macro is defined as a bit mask of all of the above events. | |
301 | This macro can be used as the | |
302 | .I mask | |
303 | argument when calling | |
63f6a20a | 304 | .BR inotify_add_watch (2). |
a721e8b2 | 305 | .PP |
dede00fe | 306 | Two additional convenience macros are defined: |
64aa9bcb | 307 | .RS 4 |
dede00fe MK |
308 | .TP |
309 | .BR IN_MOVE | |
310 | Equates to | |
311 | .BR "IN_MOVED_FROM | IN_MOVED_TO" . | |
312 | .TP | |
313 | .BR IN_CLOSE | |
314 | Equates to | |
315 | .BR "IN_CLOSE_WRITE | IN_CLOSE_NOWRITE" . | |
64aa9bcb | 316 | .RE |
4d2b74dd | 317 | .PP |
c13182ef | 318 | The following further bits can be specified in |
4d2b74dd MK |
319 | .I mask |
320 | when calling | |
63f6a20a | 321 | .BR inotify_add_watch (2): |
64aa9bcb | 322 | .RS 4 |
c577b95c | 323 | .TP |
31daf529 | 324 | .BR IN_DONT_FOLLOW " (since Linux 2.6.15)" |
aeb9b6a6 MK |
325 | Don't dereference |
326 | .I pathname | |
327 | if it is a symbolic link. | |
dda869a4 | 328 | .TP |
0ff2cc88 | 329 | .BR IN_EXCL_UNLINK " (since Linux 2.6.36)" |
b3ad7609 MK |
330 | .\" commit 8c1934c8d70b22ca8333b216aec6c7d09fdbd6a6 |
331 | By default, when watching events on the children of a directory, | |
332 | events are generated for children even after they have been unlinked | |
333 | from the directory. | |
334 | This can result in large numbers of uninteresting events for | |
335 | some applications (e.g., if watching | |
336 | .IR /tmp , | |
337 | in which many applications create temporary files whose | |
338 | names are immediately unlinked). | |
339 | Specifying | |
340 | .B IN_EXCL_UNLINK | |
341 | changes the default behavior, | |
342 | so that events are not generated for children after | |
343 | they have been unlinked from the watched directory. | |
344 | .TP | |
dda869a4 | 345 | .B IN_MASK_ADD |
7747b84b MK |
346 | If a watch instance already exists for the filesystem object corresponding to |
347 | .IR pathname , | |
348 | add (OR) the events in | |
349 | .I mask | |
381b7a91 HW |
350 | to the watch mask (instead of replacing the mask); |
351 | the error | |
352 | .B EINVAL | |
353 | results if | |
354 | .B IN_MASK_CREATE | |
355 | is also specified. | |
dda869a4 MK |
356 | .TP |
357 | .B IN_ONESHOT | |
dcaff23c | 358 | Monitor the filesystem object corresponding to |
aeb9b6a6 MK |
359 | .I pathname |
360 | for one event, then remove from | |
dda869a4 MK |
361 | watch list. |
362 | .TP | |
31daf529 | 363 | .BR IN_ONLYDIR " (since Linux 2.6.15)" |
4e9362fe | 364 | Watch |
aeb9b6a6 | 365 | .I pathname |
390795d7 MK |
366 | only if it is a directory; |
367 | the error | |
368 | .B ENOTDIR | |
369 | results if | |
370 | .I pathname | |
371 | is not a directory. | |
18d92a14 | 372 | Using this flag provides an application with a race-free way of |
9dcdfde4 | 373 | ensuring that the monitored object is a directory. |
381b7a91 | 374 | .TP |
859758b6 | 375 | .BR IN_MASK_CREATE " (since Linux 4.18)" |
381b7a91 HW |
376 | Watch |
377 | .I pathname | |
378 | only if it does not already have a watch associated with it; | |
379 | the error | |
380 | .B EEXIST | |
381 | results if | |
382 | .I pathname | |
859758b6 | 383 | is already being watched. |
5ef4a59d | 384 | .IP |
381b7a91 | 385 | Using this flag provides an application with a way of ensuring |
859758b6 | 386 | that new watches do not modify existing ones. |
5ef4a59d MK |
387 | This is useful because multiple paths may refer to the same inode, |
388 | and multiple calls to | |
859758b6 | 389 | .BR inotify_add_watch (2) |
381b7a91 | 390 | without this flag may clobber existing watch masks. |
64aa9bcb | 391 | .RE |
4d2b74dd MK |
392 | .PP |
393 | The following bits may be set in the | |
394 | .I mask | |
395 | field returned by | |
63f6a20a | 396 | .BR read (2): |
64aa9bcb | 397 | .RS 4 |
c577b95c | 398 | .TP |
dda869a4 | 399 | .B IN_IGNORED |
aeb9b6a6 MK |
400 | Watch was removed explicitly |
401 | .RB ( inotify_rm_watch (2)) | |
9ee4a2b6 | 402 | or automatically (file was deleted, or filesystem was unmounted). |
7b5151b7 | 403 | See also BUGS. |
dda869a4 MK |
404 | .TP |
405 | .B IN_ISDIR | |
406 | Subject of this event is a directory. | |
407 | .TP | |
408 | .B IN_Q_OVERFLOW | |
aeb9b6a6 MK |
409 | Event queue overflowed |
410 | .RI ( wd | |
411 | is \-1 for this event). | |
dda869a4 MK |
412 | .TP |
413 | .B IN_UNMOUNT | |
9ee4a2b6 | 414 | Filesystem containing watched object was unmounted. |
b01c936e MK |
415 | In addition, an |
416 | .B IN_IGNORED | |
417 | event will subsequently be generated for the watch descriptor. | |
64aa9bcb | 418 | .RE |
415f63be MK |
419 | .SS Examples |
420 | Suppose an application is watching the directory | |
421 | .I dir | |
422 | and the file | |
423 | .IR dir/myfile | |
424 | for all events. | |
425 | The examples below show some events that will be generated | |
426 | for these two objects. | |
427 | .RS 4 | |
428 | .TP | |
429 | fd = open("dir/myfile", O_RDWR); | |
430 | Generates | |
431 | .B IN_OPEN | |
432 | events for both | |
433 | .I dir | |
434 | and | |
435 | .IR dir/myfile . | |
436 | .TP | |
437 | read(fd, buf, count); | |
438 | Generates | |
439 | .B IN_ACCESS | |
440 | events for both | |
441 | .I dir | |
442 | and | |
443 | .IR dir/myfile . | |
444 | .TP | |
445 | write(fd, buf, count); | |
446 | Generates | |
447 | .B IN_MODIFY | |
448 | events for both | |
449 | .I dir | |
450 | and | |
451 | .IR dir/myfile . | |
452 | .TP | |
453 | fchmod(fd, mode); | |
454 | Generates | |
455 | .B IN_ATTRIB | |
456 | events for both | |
457 | .I dir | |
458 | and | |
459 | .IR dir/myfile . | |
460 | .TP | |
461 | close(fd); | |
462 | Generates | |
463 | .B IN_CLOSE_WRITE | |
464 | events for both | |
465 | .I dir | |
466 | and | |
467 | .IR dir/myfile . | |
468 | .RE | |
469 | .PP | |
470 | Suppose an application is watching the directories | |
471 | .I dir1 | |
472 | and | |
d2c3d8a8 | 473 | .IR dir2 , |
415f63be MK |
474 | and the file |
475 | .IR dir1/myfile . | |
476 | The following examples show some events that may be generated. | |
477 | .RS 4 | |
478 | .TP | |
d2c3d8a8 | 479 | link("dir1/myfile", "dir2/new"); |
415f63be MK |
480 | Generates an |
481 | .B IN_ATTRIB | |
482 | event for | |
483 | .IR myfile | |
484 | and an | |
485 | .B IN_CREATE | |
486 | event for | |
487 | .IR dir2 . | |
488 | .TP | |
489 | rename("dir1/myfile", "dir2/myfile"); | |
490 | Generates an | |
491 | .B IN_MOVED_FROM | |
492 | event for | |
493 | .IR dir1 , | |
494 | an | |
495 | .B IN_MOVED_TO | |
496 | event for | |
497 | .IR dir2 , | |
498 | and an | |
499 | .B IN_MOVE_SELF | |
500 | event for | |
501 | .IR myfile . | |
502 | The | |
503 | .B IN_MOVED_FROM | |
504 | and | |
505 | .B IN_MOVED_TO | |
506 | events will have the same | |
507 | .I cookie | |
508 | value. | |
509 | .RE | |
510 | .PP | |
511 | Suppose that | |
512 | .IR dir1/xx | |
513 | and | |
514 | .IR dir2/yy | |
515 | are (the only) links to the same file, and an application is watching | |
516 | .IR dir1 , | |
517 | .IR dir2 , | |
518 | .IR dir1/xx , | |
519 | and | |
520 | .IR dir2/yy . | |
521 | Executing the following calls in the order given below will generate | |
522 | the following events: | |
523 | .RS 4 | |
524 | .TP | |
525 | unlink("dir2/yy"); | |
d2c3d8a8 | 526 | Generates an |
415f63be MK |
527 | .BR IN_ATTRIB |
528 | event for | |
529 | .IR xx | |
530 | (because its link count changes) | |
531 | and an | |
532 | .B IN_DELETE | |
533 | event for | |
534 | .IR dir2 . | |
535 | .TP | |
536 | unlink("dir1/xx"); | |
537 | Generates | |
538 | .BR IN_ATTRIB , | |
539 | .BR IN_DELETE_SELF , | |
540 | and | |
541 | .BR IN_IGNORED | |
542 | events for | |
543 | .IR xx , | |
544 | and an | |
545 | .BR IN_DELETE | |
d2c3d8a8 | 546 | event for |
415f63be MK |
547 | .IR dir1 . |
548 | .RE | |
549 | .PP | |
550 | Suppose an application is watching the directory | |
551 | .IR dir | |
552 | and (the empty) directory | |
553 | .IR dir/subdir . | |
554 | The following examples show some events that may be generated. | |
555 | .RS 4 | |
556 | .TP | |
557 | mkdir("dir/new", mode); | |
558 | Generates an | |
559 | .B "IN_CREATE | IN_ISDIR" | |
560 | event for | |
561 | .IR dir . | |
562 | .TP | |
d2c3d8a8 | 563 | rmdir("dir/subdir"); |
415f63be MK |
564 | Generates |
565 | .B IN_DELETE_SELF | |
566 | and | |
567 | .B IN_IGNORED | |
568 | events for | |
569 | .IR subdir , | |
570 | and an | |
571 | .B "IN_DELETE | IN_ISDIR" | |
572 | event for | |
573 | .IR dir . | |
574 | .RE | |
4d2b74dd | 575 | .SS /proc interfaces |
c13182ef | 576 | The following interfaces can be used to limit the amount of |
4d2b74dd MK |
577 | kernel memory consumed by inotify: |
578 | .TP | |
0daa9e92 | 579 | .I /proc/sys/fs/inotify/max_queued_events |
4d2b74dd MK |
580 | The value in this file is used when an application calls |
581 | .BR inotify_init (2) | |
c13182ef | 582 | to set an upper limit on the number of events that can be |
4d2b74dd MK |
583 | queued to the corresponding inotify instance. |
584 | Events in excess of this limit are dropped, but an | |
585 | .B IN_Q_OVERFLOW | |
586 | event is always generated. | |
587 | .TP | |
0daa9e92 | 588 | .I /proc/sys/fs/inotify/max_user_instances |
c13182ef | 589 | This specifies an upper limit on the number of inotify instances |
4d2b74dd MK |
590 | that can be created per real user ID. |
591 | .TP | |
0daa9e92 | 592 | .I /proc/sys/fs/inotify/max_user_watches |
31546b46 VN |
593 | This specifies an upper limit on the number of watches |
594 | that can be created per real user ID. | |
47297adb | 595 | .SH VERSIONS |
2b2581ee MK |
596 | Inotify was merged into the 2.6.13 Linux kernel. |
597 | The required library interfaces were added to glibc in version 2.4. | |
598 | .RB ( IN_DONT_FOLLOW , | |
599 | .BR IN_MASK_ADD , | |
600 | and | |
601 | .B IN_ONLYDIR | |
64aa9bcb | 602 | were added in glibc version 2.5.) |
47297adb | 603 | .SH CONFORMING TO |
8382f16d | 604 | The inotify API is Linux-specific. |
47297adb | 605 | .SH NOTES |
4d2b74dd MK |
606 | Inotify file descriptors can be monitored using |
607 | .BR select (2), | |
608 | .BR poll (2), | |
c13182ef | 609 | and |
2315114c | 610 | .BR epoll (7). |
0000daa5 | 611 | When an event is available, the file descriptor indicates as readable. |
a721e8b2 | 612 | .PP |
0000daa5 MK |
613 | Since Linux 2.6.25, |
614 | signal-driven I/O notification is available for inotify file descriptors; | |
615 | see the discussion of | |
616 | .B F_SETFL | |
617 | (for setting the | |
618 | .B O_ASYNC | |
619 | flag), | |
620 | .BR F_SETOWN , | |
621 | and | |
622 | .B F_SETSIG | |
623 | in | |
624 | .BR fcntl (2). | |
625 | The | |
626 | .I siginfo_t | |
627 | structure (described in | |
628 | .BR sigaction (2)) | |
629 | that is passed to the signal handler has the following fields set: | |
630 | .IR si_fd | |
631 | is set to the inotify file descriptor number; | |
632 | .IR si_signo | |
633 | is set to the signal number; | |
634 | .IR si_code | |
635 | is set to | |
636 | .BR POLL_IN ; | |
637 | and | |
638 | .B POLLIN | |
639 | is set in | |
640 | .IR si_band . | |
a721e8b2 | 641 | .PP |
c13182ef MK |
642 | If successive output inotify events produced on the |
643 | inotify file descriptor are identical (same | |
644 | .IR wd , | |
645 | .IR mask , | |
4d2b74dd MK |
646 | .IR cookie , |
647 | and | |
3f3698d8 | 648 | .IR name ), |
6f0ab035 MK |
649 | then they are coalesced into a single event if the |
650 | older event has not yet been read (but see BUGS). | |
8856aab8 MK |
651 | This reduces the amount of kernel memory required for the event queue, |
652 | but also means that an application can't use inotify to reliably count | |
653 | file events. | |
a721e8b2 | 654 | .PP |
c13182ef MK |
655 | The events returned by reading from an inotify file descriptor |
656 | form an ordered queue. | |
657 | Thus, for example, it is guaranteed that when renaming from | |
658 | one directory to another, events will be produced in the | |
4d2b74dd | 659 | correct order on the inotify file descriptor. |
a721e8b2 | 660 | .PP |
d742465f MK |
661 | The set of watch descriptors that is being monitored via |
662 | an inotify file descriptor can be viewed via the entry for | |
663 | the inotify file descriptor in the process's | |
664 | .IR /proc/[pid]/fdinfo | |
665 | directory. | |
666 | See | |
667 | .BR proc (5) | |
668 | for further details. | |
4d2b74dd MK |
669 | The |
670 | .B FIONREAD | |
63f6a20a | 671 | .BR ioctl (2) |
c13182ef | 672 | returns the number of bytes available to read from an |
4d2b74dd | 673 | inotify file descriptor. |
613836aa | 674 | .SS Limitations and caveats |
67898fdf MK |
675 | The inotify API provides no information about the user or process that |
676 | triggered the inotify event. | |
677 | In particular, there is no easy | |
678 | way for a process that is monitoring events via inotify | |
679 | to distinguish events that it triggers | |
680 | itself from those that are triggered by other processes. | |
a721e8b2 | 681 | .PP |
e226bed7 MK |
682 | Inotify reports only events that a user-space program triggers through |
683 | the filesystem API. | |
684 | As a result, it does not catch remote events that occur | |
685 | on network filesystems. | |
686 | (Applications must fall back to polling the filesystem | |
687 | to catch such events.) | |
fa1d49a6 | 688 | Furthermore, various pseudo-filesystems such as |
e226bed7 MK |
689 | .IR /proc , |
690 | .IR /sys , | |
691 | and | |
692 | .IR /dev/pts | |
693 | are not monitorable with inotify. | |
a721e8b2 | 694 | .PP |
e449e5f1 MK |
695 | The inotify API does not report file accesses and modifications that |
696 | may occur because of | |
7a8110f6 HS |
697 | .BR mmap (2), |
698 | .BR msync (2), | |
e449e5f1 | 699 | and |
7a8110f6 | 700 | .BR munmap (2). |
a721e8b2 | 701 | .PP |
67898fdf MK |
702 | The inotify API identifies affected files by filename. |
703 | However, by the time an application processes an inotify event, | |
704 | the filename may already have been deleted or renamed. | |
a721e8b2 | 705 | .PP |
da977073 | 706 | The inotify API identifies events via watch descriptors. |
264276c6 MK |
707 | It is the application's responsibility to cache a mapping |
708 | (if one is needed) between watch descriptors and pathnames. | |
709 | Be aware that directory renamings may affect multiple cached pathnames. | |
a721e8b2 | 710 | .PP |
4d2b74dd MK |
711 | Inotify monitoring of directories is not recursive: |
712 | to monitor subdirectories under a directory, | |
713 | additional watches must be created. | |
613836aa | 714 | This can take a significant amount time for large directory trees. |
a721e8b2 | 715 | .PP |
a79d28b2 MK |
716 | If monitoring an entire directory subtree, |
717 | and a new subdirectory is created in that tree or an existing directory | |
718 | is renamed into that tree, | |
719 | be aware that by the time you create a watch for the new subdirectory, | |
720 | new files (and subdirectories) may already exist inside the subdirectory. | |
721 | Therefore, you may want to scan the contents of the subdirectory | |
722 | immediately after adding the watch (and, if desired, | |
723 | recursively add watches for any subdirectories that it contains). | |
a721e8b2 | 724 | .PP |
613836aa MK |
725 | Note that the event queue can overflow. |
726 | In this case, events are lost. | |
09fa72fa | 727 | Robust applications should handle the possibility of |
613836aa | 728 | lost events gracefully. |
94d52c15 MK |
729 | For example, it may be necessary to rebuild part or all of |
730 | the application cache. | |
731 | (One simple, but possibly expensive, | |
732 | approach is to close the inotify file descriptor, empty the cache, | |
85e179c5 | 733 | create a new inotify file descriptor, |
94d52c15 MK |
734 | and then re-create watches and cache entries |
735 | for the objects to be monitored.) | |
a721e8b2 | 736 | .PP |
c659c68e MK |
737 | If a filesystem is mounted on top of a monitored directory, |
738 | no event is generated, and no events are generated | |
739 | for objects immediately under the new mount point. | |
740 | If the filesystem is subsequently unmounted, | |
741 | events will subsequently be generated for the directory and | |
742 | the objects it contains. | |
743 | .\" | |
85e179c5 | 744 | .SS Dealing with rename() events |
fa51f4d9 | 745 | As noted above, the |
85e179c5 MK |
746 | .B IN_MOVED_FROM |
747 | and | |
748 | .B IN_MOVED_TO | |
fa51f4d9 | 749 | event pair that is generated by |
85e179c5 | 750 | .BR rename (2) |
fa51f4d9 MK |
751 | can be matched up via their shared cookie value. |
752 | However, the task of matching has some challenges. | |
a721e8b2 | 753 | .PP |
fa51f4d9 MK |
754 | These two events are usually consecutive in the event stream available |
755 | when reading from the inotify file descriptor. | |
85e179c5 MK |
756 | However, this is not guaranteed. |
757 | If multiple processes are triggering events for monitored objects, | |
758 | then (on rare occasions) an arbitrary number of | |
759 | other events may appear between the | |
760 | .B IN_MOVED_FROM | |
761 | and | |
762 | .B IN_MOVED_TO | |
763 | events. | |
003798c7 MK |
764 | Furthermore, it is not guaranteed that the event pair is atomically |
765 | inserted into the queue: there may be a brief interval where the | |
766 | .B IN_MOVED_FROM | |
767 | has appeared, but the | |
768 | .B IN_MOVED_TO | |
769 | has not. | |
a721e8b2 | 770 | .PP |
85e179c5 MK |
771 | Matching up the |
772 | .B IN_MOVED_FROM | |
773 | and | |
774 | .B IN_MOVED_TO | |
775 | event pair generated by | |
776 | .BR rename (2) | |
777 | is thus inherently racy. | |
778 | (Don't forget that if an object is renamed outside of a monitored directory, | |
779 | there may not even be an | |
780 | .BR IN_MOVED_TO | |
781 | event.) | |
782 | Heuristic approaches (e.g., assume the events are always consecutive) | |
783 | can be used to ensure a match in most cases, | |
784 | but will inevitably miss some cases, | |
785 | causing the application to perceive the | |
786 | .B IN_MOVED_FROM | |
787 | and | |
788 | .B IN_MOVED_TO | |
789 | events as being unrelated. | |
790 | If watch descriptors are destroyed and re-created as a result, | |
791 | then those watch descriptors will be inconsistent with | |
792 | the watch descriptors in any pending events. | |
6f1a4954 | 793 | (Re-creating the inotify file descriptor and rebuilding the cache may |
85e179c5 | 794 | be useful to deal with this scenario.) |
a721e8b2 | 795 | .PP |
85e179c5 MK |
796 | Applications should also allow for the possibility that the |
797 | .B IN_MOVED_FROM | |
798 | event was the last event that could fit in the buffer | |
799 | returned by the current call to | |
800 | .BR read (2), | |
801 | and the accompanying | |
802 | .B IN_MOVED_TO | |
803 | event might be fetched only on the next | |
3da91159 MK |
804 | .BR read (2), |
805 | which should be done with a (small) timeout to allow for the fact that | |
806 | insertion of the | |
807 | .BR IN_MOVED_FROM - IN_MOVED_TO | |
808 | event pair is not atomic, | |
809 | and also the possibility that there may not be any | |
810 | .B IN_MOVED_TO | |
811 | event. | |
47297adb | 812 | .SH BUGS |
f9bfa911 | 813 | Before Linux 3.19, |
360d3116 | 814 | .BR fallocate (2) |
f9bfa911 MK |
815 | did not create any inotify events. |
816 | Since Linux 3.19, | |
817 | .\" commit 820c12d5d6c0890bc93dd63893924a13041fdc35 | |
818 | calls to | |
819 | .BR fallocate (2) | |
820 | generate | |
821 | .B IN_MODIFY | |
822 | events. | |
a721e8b2 | 823 | .PP |
bea08fec | 824 | .\" FIXME . kernel commit 611da04f7a31b2208e838be55a42c7a1310ae321 |
a15ead5e MK |
825 | .\" implies that unmount events were buggy 2.6.11 to 2.6.36 |
826 | .\" | |
ed7b0235 MK |
827 | In kernels before 2.6.16, the |
828 | .B IN_ONESHOT | |
c13182ef | 829 | .I mask |
ed7b0235 | 830 | flag does not work. |
a721e8b2 | 831 | .PP |
7b5151b7 MK |
832 | As originally designed and implemented, the |
833 | .B IN_ONESHOT | |
834 | flag did not cause an | |
835 | .B IN_IGNORED | |
836 | event to be generated when the watch was dropped after one event. | |
837 | However, as an unintended effect of other changes, | |
838 | since Linux 2.6.36, an | |
839 | .B IN_IGNORED | |
840 | event is generated in this case. | |
a721e8b2 | 841 | .PP |
6f0ab035 | 842 | Before kernel 2.6.25, |
22129aa9 | 843 | .\" commit 1c17d18e3775485bf1e0ce79575eb637a94494a2 |
9ed6b517 | 844 | the kernel code that was intended to coalesce successive identical events |
6f0ab035 MK |
845 | (i.e., the two most recent events could potentially be coalesced |
846 | if the older had not yet been read) | |
847 | instead checked if the most recent event could be coalesced with the | |
848 | .I oldest | |
849 | unread event. | |
a721e8b2 | 850 | .PP |
ec976a53 | 851 | When a watch descriptor is removed by calling |
e530e367 MK |
852 | .BR inotify_rm_watch (2) |
853 | (or because a watch file is deleted or the filesystem | |
854 | that contains it is unmounted), | |
ec976a53 HS |
855 | any pending unread events for that watch descriptor remain available to read. |
856 | As watch descriptors are subsequently allocated with | |
857 | .BR inotify_add_watch (2), | |
858 | the kernel cycles through the range of possible watch descriptors (0 to | |
859 | .BR INT_MAX ) | |
860 | incrementally. | |
861 | When allocating a free watch descriptor, no check is made to see whether that | |
862 | watch descriptor number has any pending unread events in the inotify queue. | |
863 | Thus, it can happen that a watch descriptor is reallocated even | |
864 | when pending unread events exist for a previous incarnation of | |
865 | that watch descriptor number, with the result that the application | |
cbe0e644 | 866 | might then read those events and interpret them as belonging to |
ec976a53 | 867 | the file associated with the newly recycled watch descriptor. |
2bbf2299 MK |
868 | In practice, the likelihood of hitting this bug may be extremely low, |
869 | since it requires that an application cycle through | |
870 | .B INT_MAX | |
871 | watch descriptors, | |
872 | release a watch descriptor while leaving unread events for that | |
08063d8f | 873 | watch descriptor in the queue, |
2bbf2299 MK |
874 | and then recycle that watch descriptor. |
875 | For this reason, and because there have been no reports | |
876 | of the bug occurring in real-world applications, | |
877 | as of Linux 3.15, | |
bea08fec | 878 | .\" FIXME . https://bugzilla.kernel.org/show_bug.cgi?id=77111 |
2bbf2299 | 879 | no kernel changes have yet been made to eliminate this possible bug. |
ecd96f7c HS |
880 | .SH EXAMPLE |
881 | The following program demonstrates the usage of the inotify API. | |
882 | It marks the directories passed as a command-line arguments | |
883 | and waits for events of type | |
884 | .BR IN_OPEN , | |
2ef6778b | 885 | .BR IN_CLOSE_NOWRITE |
ecd96f7c HS |
886 | and |
887 | .BR IN_CLOSE_WRITE . | |
888 | .PP | |
889 | The following output was recorded while editing the file | |
890 | .I /home/user/temp/foo | |
891 | and listing directory | |
892 | .IR /tmp . | |
893 | Before the file and the directory were opened, | |
894 | .B IN_OPEN | |
895 | events occurred. | |
896 | After the file was closed, an | |
897 | .B IN_CLOSE_WRITE | |
898 | event occurred. | |
899 | After the directory was closed, an | |
900 | .B IN_CLOSE_NOWRITE | |
901 | event occurred. | |
902 | Execution of the program ended when the user pressed the ENTER key. | |
903 | .SS Example output | |
904 | .in +4n | |
b8302363 | 905 | .EX |
2483209a | 906 | $ \fB./a.out /tmp /home/user/temp\fP |
ecd96f7c HS |
907 | Press enter key to terminate. |
908 | Listening for events. | |
909 | IN_OPEN: /home/user/temp/foo [file] | |
910 | IN_CLOSE_WRITE: /home/user/temp/foo [file] | |
911 | IN_OPEN: /tmp/ [directory] | |
912 | IN_CLOSE_NOWRITE: /tmp/ [directory] | |
913 | ||
914 | Listening for events stopped. | |
b8302363 | 915 | .EE |
ecd96f7c HS |
916 | .in |
917 | .SS Program source | |
c7885256 | 918 | \& |
e7d0bb47 | 919 | .EX |
ecd96f7c HS |
920 | #include <errno.h> |
921 | #include <poll.h> | |
922 | #include <stdio.h> | |
923 | #include <stdlib.h> | |
924 | #include <sys/inotify.h> | |
925 | #include <unistd.h> | |
113a073b | 926 | #include <string.h> |
ecd96f7c HS |
927 | |
928 | /* Read all available inotify events from the file descriptor 'fd'. | |
929 | wd is the table of watch descriptors for the directories in argv. | |
930 | argc is the length of wd and argv. | |
931 | argv is the list of watched directories. | |
932 | Entry 0 of wd and argv is unused. */ | |
933 | ||
934 | static void | |
935 | handle_events(int fd, int *wd, int argc, char* argv[]) | |
936 | { | |
2483209a MK |
937 | /* Some systems cannot read integer variables if they are not |
938 | properly aligned. On other systems, incorrect alignment may | |
939 | decrease performance. Hence, the buffer used for reading from | |
940 | the inotify file descriptor should have the same alignment as | |
ecd96f7c | 941 | struct inotify_event. */ |
2483209a | 942 | |
ecd96f7c | 943 | char buf[4096] |
2483209a | 944 | __attribute__ ((aligned(__alignof__(struct inotify_event)))); |
ecd96f7c HS |
945 | const struct inotify_event *event; |
946 | int i; | |
947 | ssize_t len; | |
948 | char *ptr; | |
949 | ||
950 | /* Loop while events can be read from inotify file descriptor. */ | |
951 | ||
952 | for (;;) { | |
953 | ||
954 | /* Read some events. */ | |
955 | ||
956 | len = read(fd, buf, sizeof buf); | |
957 | if (len == \-1 && errno != EAGAIN) { | |
958 | perror("read"); | |
959 | exit(EXIT_FAILURE); | |
960 | } | |
961 | ||
962 | /* If the nonblocking read() found no events to read, then | |
963 | it returns \-1 with errno set to EAGAIN. In that case, | |
964 | we exit the loop. */ | |
965 | ||
966 | if (len <= 0) | |
967 | break; | |
968 | ||
969 | /* Loop over all events in the buffer */ | |
970 | ||
971 | for (ptr = buf; ptr < buf + len; | |
2483209a | 972 | ptr += sizeof(struct inotify_event) + event\->len) { |
ecd96f7c HS |
973 | |
974 | event = (const struct inotify_event *) ptr; | |
975 | ||
976 | /* Print event type */ | |
977 | ||
978 | if (event\->mask & IN_OPEN) | |
979 | printf("IN_OPEN: "); | |
980 | if (event\->mask & IN_CLOSE_NOWRITE) | |
981 | printf("IN_CLOSE_NOWRITE: "); | |
982 | if (event\->mask & IN_CLOSE_WRITE) | |
983 | printf("IN_CLOSE_WRITE: "); | |
984 | ||
985 | /* Print the name of the watched directory */ | |
986 | ||
987 | for (i = 1; i < argc; ++i) { | |
988 | if (wd[i] == event\->wd) { | |
989 | printf("%s/", argv[i]); | |
990 | break; | |
991 | } | |
992 | } | |
993 | ||
994 | /* Print the name of the file */ | |
995 | ||
996 | if (event\->len) | |
997 | printf("%s", event\->name); | |
998 | ||
999 | /* Print type of filesystem object */ | |
1000 | ||
1001 | if (event\->mask & IN_ISDIR) | |
d1a71985 | 1002 | printf(" [directory]\en"); |
ecd96f7c | 1003 | else |
d1a71985 | 1004 | printf(" [file]\en"); |
ecd96f7c HS |
1005 | } |
1006 | } | |
1007 | } | |
1008 | ||
1009 | int | |
1010 | main(int argc, char* argv[]) | |
1011 | { | |
1012 | char buf; | |
1013 | int fd, i, poll_num; | |
1014 | int *wd; | |
1015 | nfds_t nfds; | |
1016 | struct pollfd fds[2]; | |
1017 | ||
1018 | if (argc < 2) { | |
d1a71985 | 1019 | printf("Usage: %s PATH [PATH ...]\en", argv[0]); |
ecd96f7c HS |
1020 | exit(EXIT_FAILURE); |
1021 | } | |
1022 | ||
d1a71985 | 1023 | printf("Press ENTER key to terminate.\en"); |
ecd96f7c HS |
1024 | |
1025 | /* Create the file descriptor for accessing the inotify API */ | |
1026 | ||
1027 | fd = inotify_init1(IN_NONBLOCK); | |
1028 | if (fd == \-1) { | |
1029 | perror("inotify_init1"); | |
1030 | exit(EXIT_FAILURE); | |
1031 | } | |
1032 | ||
1033 | /* Allocate memory for watch descriptors */ | |
1034 | ||
1035 | wd = calloc(argc, sizeof(int)); | |
1036 | if (wd == NULL) { | |
1037 | perror("calloc"); | |
1038 | exit(EXIT_FAILURE); | |
1039 | } | |
1040 | ||
1041 | /* Mark directories for events | |
1042 | \- file was opened | |
1043 | \- file was closed */ | |
1044 | ||
1045 | for (i = 1; i < argc; i++) { | |
1046 | wd[i] = inotify_add_watch(fd, argv[i], | |
1047 | IN_OPEN | IN_CLOSE); | |
1048 | if (wd[i] == \-1) { | |
5687d86f NS |
1049 | fprintf(stderr, "Cannot watch '%s': %s\en", |
1050 | argv[i], strerror(errno)); | |
ecd96f7c HS |
1051 | exit(EXIT_FAILURE); |
1052 | } | |
1053 | } | |
1054 | ||
1055 | /* Prepare for polling */ | |
1056 | ||
1057 | nfds = 2; | |
1058 | ||
1059 | /* Console input */ | |
1060 | ||
1061 | fds[0].fd = STDIN_FILENO; | |
1062 | fds[0].events = POLLIN; | |
1063 | ||
1064 | /* Inotify input */ | |
1065 | ||
1066 | fds[1].fd = fd; | |
1067 | fds[1].events = POLLIN; | |
1068 | ||
1069 | /* Wait for events and/or terminal input */ | |
1070 | ||
d1a71985 | 1071 | printf("Listening for events.\en"); |
ecd96f7c HS |
1072 | while (1) { |
1073 | poll_num = poll(fds, nfds, \-1); | |
1074 | if (poll_num == \-1) { | |
1075 | if (errno == EINTR) | |
1076 | continue; | |
1077 | perror("poll"); | |
1078 | exit(EXIT_FAILURE); | |
1079 | } | |
2483209a | 1080 | |
ecd96f7c HS |
1081 | if (poll_num > 0) { |
1082 | ||
1083 | if (fds[0].revents & POLLIN) { | |
1084 | ||
1085 | /* Console input is available. Empty stdin and quit */ | |
1086 | ||
d1a71985 | 1087 | while (read(STDIN_FILENO, &buf, 1) > 0 && buf != '\en') |
ecd96f7c HS |
1088 | continue; |
1089 | break; | |
1090 | } | |
2483209a | 1091 | |
ecd96f7c HS |
1092 | if (fds[1].revents & POLLIN) { |
1093 | ||
1094 | /* Inotify events are available */ | |
2483209a | 1095 | |
ecd96f7c HS |
1096 | handle_events(fd, wd, argc, argv); |
1097 | } | |
1098 | } | |
1099 | } | |
1100 | ||
d1a71985 | 1101 | printf("Listening for events stopped.\en"); |
2483209a | 1102 | |
ecd96f7c HS |
1103 | /* Close inotify file descriptor */ |
1104 | ||
1105 | close(fd); | |
2483209a | 1106 | |
ecd96f7c | 1107 | free(wd); |
ecd96f7c HS |
1108 | exit(EXIT_SUCCESS); |
1109 | } | |
e7d0bb47 | 1110 | .EE |
47297adb | 1111 | .SH SEE ALSO |
f0afb16a MK |
1112 | .BR inotifywait (1), |
1113 | .BR inotifywatch (1), | |
4d2b74dd MK |
1114 | .BR inotify_add_watch (2), |
1115 | .BR inotify_init (2), | |
43bb5faf | 1116 | .BR inotify_init1 (2), |
4d2b74dd MK |
1117 | .BR inotify_rm_watch (2), |
1118 | .BR read (2), | |
f75d27e6 HS |
1119 | .BR stat (2), |
1120 | .BR fanotify (7) | |
a721e8b2 | 1121 | .PP |
173fe7e7 DP |
1122 | .IR Documentation/filesystems/inotify.txt |
1123 | in the Linux kernel source tree |