Debian Codegraph @

templates/man7/inotify.7.pot

raw
1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 #
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2026-06-05 06:27+0200\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <[email protected]>\n"
14 "Language: \n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
18
19 #. type: TH
20 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
21 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
22 #, no-wrap
23 msgid "inotify"
24 msgstr ""
25
26 #. type: TH
27 #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed
28 #, no-wrap
29 msgid "2026-02-14"
30 msgstr ""
31
32 #. type: TH
33 #: archlinux debian-unstable
34 #, no-wrap
35 msgid "Linux man-pages 6.18"
36 msgstr ""
37
38 #. type: SH
39 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
40 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
41 #, no-wrap
42 msgid "NAME"
43 msgstr ""
44
45 #. type: Plain text
46 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
47 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
48 msgid "inotify - monitoring filesystem events"
49 msgstr ""
50
51 #. type: SH
52 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
53 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
54 #, no-wrap
55 msgid "DESCRIPTION"
56 msgstr ""
57
58 #. type: Plain text
59 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
60 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
61 msgid ""
62 "The I<inotify> API provides a mechanism for monitoring filesystem events. "
63 "Inotify can be used to monitor individual files, or to monitor directories. "
64 "When a directory is monitored, inotify will return events for the directory "
65 "itself, and for files inside the directory."
66 msgstr ""
67
68 #. type: Plain text
69 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
70 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
71 msgid "The following system calls are used with this API:"
72 msgstr ""
73
74 #. type: IP
75 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
76 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
77 #, no-wrap
78 msgid "\\[bu]"
79 msgstr ""
80
81 #. type: Plain text
82 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
83 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
84 msgid ""
85 "B<inotify_init>(2) creates an inotify instance and returns a file "
86 "descriptor referring to the inotify instance. The more recent "
87 "B<inotify_init1>(2) is like B<inotify_init>(2), but has a I<flags> argument "
88 "that provides access to some extra functionality."
89 msgstr ""
90
91 #. type: Plain text
92 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
93 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
94 msgid ""
95 "B<inotify_add_watch>(2) manipulates the \"watch list\" associated with an "
96 "inotify instance. Each item (\"watch\") in the watch list specifies the "
97 "pathname of a file or directory, along with some set of events that the "
98 "kernel should monitor for the file referred to by that pathname. "
99 "B<inotify_add_watch>(2) either creates a new watch item, or modifies an "
100 "existing watch. Each watch has a unique \"watch descriptor\", an integer "
101 "returned by B<inotify_add_watch>(2) when the watch is created."
102 msgstr ""
103
104 #. type: Plain text
105 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
106 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
107 msgid ""
108 "When events occur for monitored files and directories, those events are made "
109 "available to the application as structured data that can be read from the "
110 "inotify file descriptor using B<read>(2) (see below)."
111 msgstr ""
112
113 #. type: Plain text
114 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
115 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
116 msgid "B<inotify_rm_watch>(2) removes an item from an inotify watch list."
117 msgstr ""
118
119 #. type: Plain text
120 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
121 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
122 msgid ""
123 "When all file descriptors referring to an inotify instance have been closed "
124 "(using B<close>(2)), the underlying object and its resources are freed for "
125 "reuse by the kernel; all associated watches are automatically freed."
126 msgstr ""
127
128 #. type: Plain text
129 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
130 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
131 msgid ""
132 "With careful programming, an application can use inotify to efficiently "
133 "monitor and cache the state of a set of filesystem objects. However, robust "
134 "applications should allow for the fact that bugs in the monitoring logic or "
135 "races of the kind described below may leave the cache inconsistent with the "
136 "filesystem state. It is probably wise to do some consistency checking, and "
137 "rebuild the cache when inconsistencies are detected."
138 msgstr ""
139
140 #. type: SS
141 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
142 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
143 #, no-wrap
144 msgid "Reading events from an inotify file descriptor"
145 msgstr ""
146
147 #. type: Plain text
148 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
149 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
150 msgid ""
151 "To determine what events have occurred, an application B<read>(2)s from the "
152 "inotify file descriptor. If no events have so far occurred, then, assuming "
153 "a blocking file descriptor, B<read>(2) will block until at least one event "
154 "occurs (unless interrupted by a signal, in which case the call fails with "
155 "the error B<EINTR>; see B<signal>(7))."
156 msgstr ""
157
158 #. type: Plain text
159 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
160 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
161 msgid ""
162 "Each successful B<read>(2) returns a buffer containing one or more of the "
163 "following structures:"
164 msgstr ""
165
166 #. FIXME . The type of the 'wd' field should probably be "int32_t".
167 #. I submitted a patch to fix this. See the LKML thread
168 #. "[patch] Fix type errors in inotify interfaces", 18 Nov 2008
169 #. glibc bug filed: https://www.sourceware.org/bugzilla/show_bug.cgi?id=7040
170 #. type: Plain text
171 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
172 #: opensuse-tumbleweed
173 #, no-wrap
174 msgid ""
175 "struct inotify_event {\n"
176 " int wd; /* Watch descriptor */\n"
177 " uint32_t mask; /* Mask describing event */\n"
178 " uint32_t cookie; /* Unique cookie associating related\n"
179 " events (for rename(2)) */\n"
180 " uint32_t len; /* Size of \\f[I]name\\fR field */\n"
181 " char name[]; /* Optional null-terminated name */\n"
182 "};\n"
183 msgstr ""
184
185 #. type: Plain text
186 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
187 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
188 msgid ""
189 "I<wd> identifies the watch for which this event occurs. It is one of the "
190 "watch descriptors returned by a previous call to B<inotify_add_watch>(2)."
191 msgstr ""
192
193 #. type: Plain text
194 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
195 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
196 msgid ""
197 "I<mask> contains bits that describe the event that occurred (see below)."
198 msgstr ""
199
200 #. type: Plain text
201 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
202 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
203 msgid ""
204 "I<cookie> is a unique integer that connects related events. Currently, this "
205 "is used only for rename events, and allows the resulting pair of "
206 "B<IN_MOVED_FROM> and B<IN_MOVED_TO> events to be connected by the "
207 "application. For all other event types, I<cookie> is set to 0."
208 msgstr ""
209
210 #. type: Plain text
211 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
212 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
213 msgid ""
214 "The I<name> field is present only when an event is returned for a file "
215 "inside a watched directory; it identifies the filename within the watched "
216 "directory. This filename is null-terminated, and may include further null "
217 "bytes (\\[aq]\\[rs]0\\[aq]) to align subsequent reads to a suitable address "
218 "boundary."
219 msgstr ""
220
221 #. type: Plain text
222 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
223 #: opensuse-leap-16-1 opensuse-tumbleweed
224 msgid ""
225 "The I<len> field counts all of the bytes in I<name>, including the null "
226 "bytes; the size of each I<inotify_event> structure is thus I<sizeof(struct "
227 "inotify_event)+size>."
228 msgstr ""
229
230 #. type: Plain text
231 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
232 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
233 msgid ""
234 "The behavior when the buffer given to B<read>(2) is too small to return "
235 "information about the next event depends on the kernel version: before Linux "
236 "2.6.21, B<read>(2) returns 0; since Linux 2.6.21, B<read>(2) fails with "
237 "the error B<EINVAL>. Specifying a buffer of size"
238 msgstr ""
239
240 #. type: Plain text
241 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
242 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
243 #, no-wrap
244 msgid "sizeof(struct inotify_event) + NAME_MAX + 1\n"
245 msgstr ""
246
247 #. type: Plain text
248 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
249 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
250 msgid "will be sufficient to read at least one event."
251 msgstr ""
252
253 #. type: SS
254 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
255 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
256 #, no-wrap
257 msgid "inotify events"
258 msgstr ""
259
260 #. type: Plain text
261 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
262 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
263 msgid ""
264 "The B<inotify_add_watch>(2) I<mask> argument and the I<mask> field of the "
265 "I<inotify_event> structure returned when B<read>(2)ing an inotify file "
266 "descriptor are both bit masks identifying inotify events. The following "
267 "bits can be specified in I<mask> when calling B<inotify_add_watch>(2) and "
268 "may be returned in the I<mask> field returned by B<read>(2):"
269 msgstr ""
270
271 #. type: TP
272 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
273 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
274 #, no-wrap
275 msgid "B<IN_ACCESS> (+)"
276 msgstr ""
277
278 #. type: Plain text
279 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
280 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
281 msgid "File was accessed (e.g., B<read>(2), B<execve>(2))."
282 msgstr ""
283
284 #. type: TP
285 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
286 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
287 #, no-wrap
288 msgid "B<IN_ATTRIB> (*)"
289 msgstr ""
290
291 #. #-#-#-#-# archlinux: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
292 #. FIXME .
293 #. Events do not occur for link count changes on a file inside a monitored
294 #. directory. This differs from other metadata changes for files inside
295 #. a monitored directory.
296 #. type: Plain text
297 #. #-#-#-#-# debian-trixie: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
298 #. FIXME .
299 #. Events do not occur for link count changes on a file inside a monitored
300 #. directory. This differs from other metadata changes for files inside
301 #. a monitored directory.
302 #. type: Plain text
303 #. #-#-#-#-# debian-unstable: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
304 #. FIXME .
305 #. Events do not occur for link count changes on a file inside a monitored
306 #. directory. This differs from other metadata changes for files inside
307 #. a monitored directory.
308 #. type: Plain text
309 #. #-#-#-#-# fedora-44: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
310 #. FIXME .
311 #. Events do not occur for link count changes on a file inside a monitored
312 #. directory. This differs from other metadata changes for files inside
313 #. a monitored directory.
314 #. type: Plain text
315 #. #-#-#-#-# fedora-rawhide: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
316 #. FIXME .
317 #. Events do not occur for link count changes on a file inside a monitored
318 #. directory. This differs from other metadata changes for files inside
319 #. a monitored directory.
320 #. type: Plain text
321 #. #-#-#-#-# mageia-cauldron: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
322 #. FIXME .
323 #. Events do not occur for link count changes on a file inside a monitored
324 #. directory. This differs from other metadata changes for files inside
325 #. a monitored directory.
326 #. type: Plain text
327 #. #-#-#-#-# opensuse-leap-16-1: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
328 #. FIXME .
329 #. Events do not occur for link count changes on a file inside a monitored
330 #. directory. This differs from other metadata changes for files inside
331 #. a monitored directory.
332 #. type: Plain text
333 #. #-#-#-#-# opensuse-tumbleweed: inotify.7.pot (PACKAGE VERSION) #-#-#-#-#
334 #. FIXME .
335 #. Events do not occur for link count changes on a file inside a monitored
336 #. directory. This differs from other metadata changes for files inside
337 #. a monitored directory.
338 #. type: Plain text
339 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
340 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
341 msgid ""
342 "Metadata changed\\[em]for example, permissions (e.g., B<chmod>(2)), "
343 "timestamps (e.g., B<utimensat>(2)), extended attributes (B<setxattr>(2)), "
344 "link count (since Linux 2.6.25; e.g., for the target of B<link>(2) and for "
345 "B<unlink>(2)), and user/group ID (e.g., B<chown>(2))."
346 msgstr ""
347
348 #. type: TP
349 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
350 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
351 #, no-wrap
352 msgid "B<IN_CLOSE_WRITE> (+)"
353 msgstr ""
354
355 #. type: Plain text
356 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
357 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
358 msgid "File opened for writing was closed."
359 msgstr ""
360
361 #. type: TP
362 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
363 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
364 #, no-wrap
365 msgid "B<IN_CLOSE_NOWRITE> (*)"
366 msgstr ""
367
368 #. type: Plain text
369 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
370 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
371 msgid "File or directory not opened for writing was closed."
372 msgstr ""
373
374 #. type: TP
375 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
376 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
377 #, no-wrap
378 msgid "B<IN_CREATE> (+)"
379 msgstr ""
380
381 #. type: Plain text
382 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
383 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
384 msgid ""
385 "File/directory created in watched directory (e.g., B<open>(2) B<O_CREAT>, "
386 "B<mkdir>(2), B<link>(2), B<symlink>(2), B<bind>(2) on a UNIX domain socket)."
387 msgstr ""
388
389 #. type: TP
390 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
391 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
392 #, no-wrap
393 msgid "B<IN_DELETE> (+)"
394 msgstr ""
395
396 #. type: Plain text
397 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
398 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
399 msgid "File/directory deleted from watched directory."
400 msgstr ""
401
402 #. type: TP
403 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
404 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
405 #, no-wrap
406 msgid "B<IN_DELETE_SELF>"
407 msgstr ""
408
409 #. type: Plain text
410 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
411 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
412 msgid ""
413 "Watched file/directory was itself deleted. (This event also occurs if an "
414 "object is moved to another filesystem, since B<mv>(1) in effect copies the "
415 "file to the other filesystem and then deletes it from the original "
416 "filesystem.) In addition, an B<IN_IGNORED> event will subsequently be "
417 "generated for the watch descriptor."
418 msgstr ""
419
420 #. type: TP
421 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
422 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
423 #, no-wrap
424 msgid "B<IN_MODIFY> (+)"
425 msgstr ""
426
427 #. type: Plain text
428 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
429 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
430 msgid "File was modified (e.g., B<write>(2), B<truncate>(2))."
431 msgstr ""
432
433 #. type: TP
434 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
435 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
436 #, no-wrap
437 msgid "B<IN_MOVE_SELF>"
438 msgstr ""
439
440 #. type: Plain text
441 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
442 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
443 msgid "Watched file/directory was itself moved."
444 msgstr ""
445
446 #. type: TP
447 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
448 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
449 #, no-wrap
450 msgid "B<IN_MOVED_FROM> (+)"
451 msgstr ""
452
453 #. type: Plain text
454 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
455 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
456 msgid ""
457 "Generated for the directory containing the old filename when a file is "
458 "renamed."
459 msgstr ""
460
461 #. type: TP
462 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
463 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
464 #, no-wrap
465 msgid "B<IN_MOVED_TO> (+)"
466 msgstr ""
467
468 #. type: Plain text
469 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
470 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
471 msgid ""
472 "Generated for the directory containing the new filename when a file is "
473 "renamed."
474 msgstr ""
475
476 #. type: TP
477 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
478 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
479 #, no-wrap
480 msgid "B<IN_OPEN> (*)"
481 msgstr ""
482
483 #. type: Plain text
484 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
485 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
486 msgid "File or directory was opened."
487 msgstr ""
488
489 #. type: Plain text
490 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
491 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
492 msgid ""
493 "Inotify monitoring is inode-based: when monitoring a file (but not when "
494 "monitoring the directory containing a file), an event can be generated for "
495 "activity on any link to the file (in the same or a different directory)."
496 msgstr ""
497
498 #. type: Plain text
499 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
500 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
501 msgid "When monitoring a directory:"
502 msgstr ""
503
504 #. type: Plain text
505 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
506 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
507 msgid ""
508 "the events marked above with an asterisk (*) can occur both for the "
509 "directory itself and for objects inside the directory; and"
510 msgstr ""
511
512 #. type: Plain text
513 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
514 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
515 msgid ""
516 "the events marked with a plus sign (+) occur only for objects inside the "
517 "directory (not for the directory itself)."
518 msgstr ""
519
520 #. type: Plain text
521 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
522 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
523 msgid ""
524 "I<Note>: when monitoring a directory, events are not generated for the files "
525 "inside the directory when the events are performed via a pathname (i.e., a "
526 "link) that lies outside the monitored directory."
527 msgstr ""
528
529 #. type: Plain text
530 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
531 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
532 msgid ""
533 "When events are generated for objects inside a watched directory, the "
534 "I<name> field in the returned I<inotify_event> structure identifies the name "
535 "of the file within the directory."
536 msgstr ""
537
538 #. type: Plain text
539 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
540 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
541 msgid ""
542 "The B<IN_ALL_EVENTS> macro is defined as a bit mask of all of the above "
543 "events. This macro can be used as the I<mask> argument when calling "
544 "B<inotify_add_watch>(2)."
545 msgstr ""
546
547 #. type: Plain text
548 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
549 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
550 msgid "Two additional convenience macros are defined:"
551 msgstr ""
552
553 #. type: TP
554 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
555 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
556 #, no-wrap
557 msgid "B<IN_MOVE>"
558 msgstr ""
559
560 #. type: Plain text
561 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
562 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
563 msgid "Equates to B<IN_MOVED_FROM | IN_MOVED_TO>."
564 msgstr ""
565
566 #. type: TP
567 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
568 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
569 #, no-wrap
570 msgid "B<IN_CLOSE>"
571 msgstr ""
572
573 #. type: Plain text
574 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
575 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
576 msgid "Equates to B<IN_CLOSE_WRITE | IN_CLOSE_NOWRITE>."
577 msgstr ""
578
579 #. type: Plain text
580 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
581 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
582 msgid ""
583 "The following further bits can be specified in I<mask> when calling "
584 "B<inotify_add_watch>(2):"
585 msgstr ""
586
587 #. type: TP
588 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
589 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
590 #, no-wrap
591 msgid "B<IN_DONT_FOLLOW> (since Linux 2.6.15)"
592 msgstr ""
593
594 #. type: Plain text
595 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
596 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
597 msgid "Don't dereference I<pathname> if it is a symbolic link."
598 msgstr ""
599
600 #. type: TP
601 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
602 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
603 #, no-wrap
604 msgid "B<IN_EXCL_UNLINK> (since Linux 2.6.36)"
605 msgstr ""
606
607 #. commit 8c1934c8d70b22ca8333b216aec6c7d09fdbd6a6
608 #. type: Plain text
609 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
610 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
611 msgid ""
612 "By default, when watching events on the children of a directory, events are "
613 "generated for children even after they have been unlinked from the "
614 "directory. This can result in large numbers of uninteresting events for "
615 "some applications (e.g., if watching I</tmp>, in which many applications "
616 "create temporary files whose names are immediately unlinked). Specifying "
617 "B<IN_EXCL_UNLINK> changes the default behavior, so that events are not "
618 "generated for children after they have been unlinked from the watched "
619 "directory."
620 msgstr ""
621
622 #. type: TP
623 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
624 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
625 #, no-wrap
626 msgid "B<IN_MASK_ADD>"
627 msgstr ""
628
629 #. type: Plain text
630 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
631 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
632 msgid ""
633 "If a watch instance already exists for the filesystem object corresponding "
634 "to I<pathname>, add (OR) the events in I<mask> to the watch mask (instead of "
635 "replacing the mask); the error B<EINVAL> results if B<IN_MASK_CREATE> is "
636 "also specified."
637 msgstr ""
638
639 #. type: TP
640 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
641 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
642 #, no-wrap
643 msgid "B<IN_ONESHOT>"
644 msgstr ""
645
646 #. type: Plain text
647 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
648 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
649 msgid ""
650 "Monitor the filesystem object corresponding to I<pathname> for one event, "
651 "then remove from watch list."
652 msgstr ""
653
654 #. type: TP
655 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
656 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
657 #, no-wrap
658 msgid "B<IN_ONLYDIR> (since Linux 2.6.15)"
659 msgstr ""
660
661 #. type: Plain text
662 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
663 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
664 msgid ""
665 "Watch I<pathname> only if it is a directory; the error B<ENOTDIR> results if "
666 "I<pathname> is not a directory. Using this flag provides an application "
667 "with a race-free way of ensuring that the monitored object is a directory."
668 msgstr ""
669
670 #. type: TP
671 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
672 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
673 #, no-wrap
674 msgid "B<IN_MASK_CREATE> (since Linux 4.18)"
675 msgstr ""
676
677 #. type: Plain text
678 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
679 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
680 msgid ""
681 "Watch I<pathname> only if it does not already have a watch associated with "
682 "it; the error B<EEXIST> results if I<pathname> is already being watched."
683 msgstr ""
684
685 #. type: Plain text
686 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
687 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
688 msgid ""
689 "Using this flag provides an application with a way of ensuring that new "
690 "watches do not modify existing ones. This is useful because multiple paths "
691 "may refer to the same inode, and multiple calls to B<inotify_add_watch>(2) "
692 "without this flag may clobber existing watch masks."
693 msgstr ""
694
695 #. type: Plain text
696 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
697 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
698 msgid ""
699 "The following bits may be set in the I<mask> field returned by B<read>(2):"
700 msgstr ""
701
702 #. type: TP
703 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
704 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
705 #, no-wrap
706 msgid "B<IN_IGNORED>"
707 msgstr ""
708
709 #. type: Plain text
710 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
711 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
712 msgid ""
713 "Watch was removed explicitly (B<inotify_rm_watch>(2)) or automatically "
714 "(file was deleted, or filesystem was unmounted). See also BUGS."
715 msgstr ""
716
717 #. type: TP
718 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
719 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
720 #, no-wrap
721 msgid "B<IN_ISDIR>"
722 msgstr ""
723
724 #. type: Plain text
725 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
726 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
727 msgid "Subject of this event is a directory."
728 msgstr ""
729
730 #. type: TP
731 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
732 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
733 #, no-wrap
734 msgid "B<IN_Q_OVERFLOW>"
735 msgstr ""
736
737 #. type: Plain text
738 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
739 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
740 msgid "Event queue overflowed (I<wd> is -1 for this event)."
741 msgstr ""
742
743 #. type: TP
744 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
745 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
746 #, no-wrap
747 msgid "B<IN_UNMOUNT>"
748 msgstr ""
749
750 #. type: Plain text
751 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
752 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
753 msgid ""
754 "Filesystem containing watched object was unmounted. In addition, an "
755 "B<IN_IGNORED> event will subsequently be generated for the watch descriptor."
756 msgstr ""
757
758 #. type: SS
759 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
760 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
761 #, no-wrap
762 msgid "Examples"
763 msgstr ""
764
765 #. type: Plain text
766 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
767 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
768 msgid ""
769 "Suppose an application is watching the directory I<dir> and the file I<dir/"
770 "myfile> for all events. The examples below show some events that will be "
771 "generated for these two objects."
772 msgstr ""
773
774 #. type: TP
775 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
776 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
777 #, no-wrap
778 msgid "fd = open(\"dir/myfile\", O_RDWR);"
779 msgstr ""
780
781 #. type: Plain text
782 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
783 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
784 msgid "Generates B<IN_OPEN> events for both I<dir> and I<dir/myfile>."
785 msgstr ""
786
787 #. type: TP
788 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
789 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
790 #, no-wrap
791 msgid "read(fd, buf, count);"
792 msgstr ""
793
794 #. type: Plain text
795 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
796 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
797 msgid "Generates B<IN_ACCESS> events for both I<dir> and I<dir/myfile>."
798 msgstr ""
799
800 #. type: TP
801 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
802 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
803 #, no-wrap
804 msgid "write(fd, buf, count);"
805 msgstr ""
806
807 #. type: Plain text
808 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
809 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
810 msgid "Generates B<IN_MODIFY> events for both I<dir> and I<dir/myfile>."
811 msgstr ""
812
813 #. type: TP
814 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
815 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
816 #, no-wrap
817 msgid "fchmod(fd, mode);"
818 msgstr ""
819
820 #. type: Plain text
821 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
822 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
823 msgid "Generates B<IN_ATTRIB> events for both I<dir> and I<dir/myfile>."
824 msgstr ""
825
826 #. type: TP
827 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
828 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
829 #, no-wrap
830 msgid "close(fd);"
831 msgstr ""
832
833 #. type: Plain text
834 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
835 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
836 msgid "Generates B<IN_CLOSE_WRITE> events for both I<dir> and I<dir/myfile>."
837 msgstr ""
838
839 #. type: Plain text
840 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
841 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
842 msgid ""
843 "Suppose an application is watching the directories I<dir1> and I<dir2>, and "
844 "the file I<dir1/myfile>. The following examples show some events that may "
845 "be generated."
846 msgstr ""
847
848 #. type: TP
849 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
850 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
851 #, no-wrap
852 msgid "link(\"dir1/myfile\", \"dir2/new\");"
853 msgstr ""
854
855 #. type: Plain text
856 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
857 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
858 msgid ""
859 "Generates an B<IN_ATTRIB> event for I<myfile> and an B<IN_CREATE> event for "
860 "I<dir2>."
861 msgstr ""
862
863 #. type: TP
864 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
865 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
866 #, no-wrap
867 msgid "rename(\"dir1/myfile\", \"dir2/myfile\");"
868 msgstr ""
869
870 #. type: Plain text
871 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
872 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
873 msgid ""
874 "Generates an B<IN_MOVED_FROM> event for I<dir1>, an B<IN_MOVED_TO> event for "
875 "I<dir2>, and an B<IN_MOVE_SELF> event for I<myfile>. The B<IN_MOVED_FROM> "
876 "and B<IN_MOVED_TO> events will have the same I<cookie> value."
877 msgstr ""
878
879 #. type: Plain text
880 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
881 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
882 msgid ""
883 "Suppose that I<dir1/xx> and I<dir2/yy> are (the only) links to the same "
884 "file, and an application is watching I<dir1>, I<dir2>, I<dir1/xx>, and "
885 "I<dir2/yy>. Executing the following calls in the order given below will "
886 "generate the following events:"
887 msgstr ""
888
889 #. type: TP
890 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
891 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
892 #, no-wrap
893 msgid "unlink(\"dir2/yy\");"
894 msgstr ""
895
896 #. type: Plain text
897 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
898 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
899 msgid ""
900 "Generates an B<IN_ATTRIB> event for I<xx> (because its link count changes) "
901 "and an B<IN_DELETE> event for I<dir2>."
902 msgstr ""
903
904 #. type: TP
905 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
906 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
907 #, no-wrap
908 msgid "unlink(\"dir1/xx\");"
909 msgstr ""
910
911 #. type: Plain text
912 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
913 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
914 msgid ""
915 "Generates B<IN_ATTRIB>, B<IN_DELETE_SELF>, and B<IN_IGNORED> events for "
916 "I<xx>, and an B<IN_DELETE> event for I<dir1>."
917 msgstr ""
918
919 #. type: Plain text
920 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
921 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
922 msgid ""
923 "Suppose an application is watching the directory I<dir> and (the empty) "
924 "directory I<dir/subdir>. The following examples show some events that may "
925 "be generated."
926 msgstr ""
927
928 #. type: TP
929 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
930 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
931 #, no-wrap
932 msgid "mkdir(\"dir/new\", mode);"
933 msgstr ""
934
935 #. type: Plain text
936 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
937 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
938 msgid "Generates an B<IN_CREATE | IN_ISDIR> event for I<dir>."
939 msgstr ""
940
941 #. type: TP
942 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
943 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
944 #, no-wrap
945 msgid "rmdir(\"dir/subdir\");"
946 msgstr ""
947
948 #. type: Plain text
949 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
950 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
951 msgid ""
952 "Generates B<IN_DELETE_SELF> and B<IN_IGNORED> events for I<subdir>, and an "
953 "B<IN_DELETE | IN_ISDIR> event for I<dir>."
954 msgstr ""
955
956 #. type: SS
957 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
958 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
959 #, no-wrap
960 msgid "/proc interfaces"
961 msgstr ""
962
963 #. type: Plain text
964 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
965 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
966 msgid ""
967 "The following interfaces can be used to limit the amount of kernel memory "
968 "consumed by inotify:"
969 msgstr ""
970
971 #. type: TP
972 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
973 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
974 #, no-wrap
975 msgid "I</proc/sys/fs/inotify/max_queued_events>"
976 msgstr ""
977
978 #. type: Plain text
979 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
980 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
981 msgid ""
982 "The value in this file is used when an application calls B<inotify_init>(2) "
983 "to set an upper limit on the number of events that can be queued to the "
984 "corresponding inotify instance. Events in excess of this limit are dropped, "
985 "but an B<IN_Q_OVERFLOW> event is always generated."
986 msgstr ""
987
988 #. type: TP
989 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
990 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
991 #, no-wrap
992 msgid "I</proc/sys/fs/inotify/max_user_instances>"
993 msgstr ""
994
995 #. type: Plain text
996 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
997 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
998 msgid ""
999 "This specifies an upper limit on the number of inotify instances that can be "
1000 "created per real user ID."
1001 msgstr ""
1002
1003 #. type: TP
1004 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1005 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1006 #, no-wrap
1007 msgid "I</proc/sys/fs/inotify/max_user_watches>"
1008 msgstr ""
1009
1010 #. type: Plain text
1011 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1012 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1013 msgid ""
1014 "This specifies an upper limit on the number of watches that can be created "
1015 "per real user ID."
1016 msgstr ""
1017
1018 #. type: SH
1019 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1020 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1021 #, no-wrap
1022 msgid "STANDARDS"
1023 msgstr ""
1024
1025 #. type: Plain text
1026 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1027 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1028 msgid "Linux."
1029 msgstr ""
1030
1031 #. type: SH
1032 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1033 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1034 #, no-wrap
1035 msgid "HISTORY"
1036 msgstr ""
1037
1038 #. type: Plain text
1039 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1040 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1041 msgid ""
1042 "Inotify was merged into Linux 2.6.13. The required library interfaces were "
1043 "added in glibc 2.4. (B<IN_DONT_FOLLOW>, B<IN_MASK_ADD>, and B<IN_ONLYDIR> "
1044 "were added in glibc 2.5.)"
1045 msgstr ""
1046
1047 #. type: SH
1048 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1049 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1050 #, no-wrap
1051 msgid "NOTES"
1052 msgstr ""
1053
1054 #. type: Plain text
1055 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1056 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1057 msgid ""
1058 "Inotify file descriptors can be monitored using B<select>(2), B<poll>(2), "
1059 "and B<epoll>(7). When an event is available, the file descriptor indicates "
1060 "as readable."
1061 msgstr ""
1062
1063 #. type: Plain text
1064 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1065 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1066 msgid ""
1067 "Since Linux 2.6.25, signal-driven I/O notification is available for inotify "
1068 "file descriptors; see the discussion of B<F_SETFL> (for setting the "
1069 "B<O_ASYNC> flag), B<F_SETOWN>, and B<F_SETSIG> in B<fcntl>(2). The "
1070 "I<siginfo_t> structure (described in B<sigaction>(2)) that is passed to the "
1071 "signal handler has the following fields set: I<si_fd> is set to the inotify "
1072 "file descriptor number; I<si_signo> is set to the signal number; I<si_code> "
1073 "is set to B<POLL_IN>; and B<POLLIN> is set in I<si_band>."
1074 msgstr ""
1075
1076 #. type: Plain text
1077 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1078 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1079 msgid ""
1080 "If successive output inotify events produced on the inotify file descriptor "
1081 "are identical (same I<wd>, I<mask>, I<cookie>, and I<name>), then they are "
1082 "coalesced into a single event if the older event has not yet been read (but "
1083 "see BUGS). This reduces the amount of kernel memory required for the event "
1084 "queue, but also means that an application can't use inotify to reliably "
1085 "count file events."
1086 msgstr ""
1087
1088 #. type: Plain text
1089 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1090 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1091 msgid ""
1092 "The events returned by reading from an inotify file descriptor form an "
1093 "ordered queue. Thus, for example, it is guaranteed that when renaming from "
1094 "one directory to another, events will be produced in the correct order on "
1095 "the inotify file descriptor."
1096 msgstr ""
1097
1098 #. type: Plain text
1099 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1100 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1101 msgid ""
1102 "The set of watch descriptors that is being monitored via an inotify file "
1103 "descriptor can be viewed via the entry for the inotify file descriptor in "
1104 "the process's I</proc/>pidI</fdinfo> directory. See B<proc>(5) for further "
1105 "details. The B<FIONREAD> B<ioctl>(2) returns the number of bytes available "
1106 "to read from an inotify file descriptor."
1107 msgstr ""
1108
1109 #. type: SS
1110 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1111 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1112 #, no-wrap
1113 msgid "Limitations and caveats"
1114 msgstr ""
1115
1116 #. type: Plain text
1117 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1118 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1119 msgid ""
1120 "The inotify API provides no information about the user or process that "
1121 "triggered the inotify event. In particular, there is no easy way for a "
1122 "process that is monitoring events via inotify to distinguish events that it "
1123 "triggers itself from those that are triggered by other processes."
1124 msgstr ""
1125
1126 #. type: Plain text
1127 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1128 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1129 msgid ""
1130 "Inotify reports only events that a user-space program triggers through the "
1131 "filesystem API. As a result, it does not catch remote events that occur on "
1132 "network filesystems. (Applications must fall back to polling the filesystem "
1133 "to catch such events.) Furthermore, various pseudo-filesystems such as I</"
1134 "proc>, I</sys>, and I</dev/pts> are not monitorable with inotify."
1135 msgstr ""
1136
1137 #. type: Plain text
1138 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1139 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1140 msgid ""
1141 "The inotify API does not report file accesses and modifications that may "
1142 "occur because of B<mmap>(2), B<msync>(2), and B<munmap>(2)."
1143 msgstr ""
1144
1145 #. type: Plain text
1146 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1147 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1148 msgid ""
1149 "The inotify API identifies affected files by filename. However, by the time "
1150 "an application processes an inotify event, the filename may already have "
1151 "been deleted or renamed."
1152 msgstr ""
1153
1154 #. type: Plain text
1155 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1156 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1157 msgid ""
1158 "The inotify API identifies events via watch descriptors. It is the "
1159 "application's responsibility to cache a mapping (if one is needed) between "
1160 "watch descriptors and pathnames. Be aware that directory renamings may "
1161 "affect multiple cached pathnames."
1162 msgstr ""
1163
1164 #. type: Plain text
1165 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1166 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1167 msgid ""
1168 "Inotify monitoring of directories is not recursive: to monitor "
1169 "subdirectories under a directory, additional watches must be created. This "
1170 "can take a significant amount time for large directory trees."
1171 msgstr ""
1172
1173 #. type: Plain text
1174 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1175 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1176 msgid ""
1177 "If monitoring an entire directory subtree, and a new subdirectory is created "
1178 "in that tree or an existing directory is renamed into that tree, be aware "
1179 "that by the time you create a watch for the new subdirectory, new files (and "
1180 "subdirectories) may already exist inside the subdirectory. Therefore, you "
1181 "may want to scan the contents of the subdirectory immediately after adding "
1182 "the watch (and, if desired, recursively add watches for any subdirectories "
1183 "that it contains)."
1184 msgstr ""
1185
1186 #. type: Plain text
1187 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1188 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1189 msgid ""
1190 "Note that the event queue can overflow. In this case, events are lost. "
1191 "Robust applications should handle the possibility of lost events "
1192 "gracefully. For example, it may be necessary to rebuild part or all of the "
1193 "application cache. (One simple, but possibly expensive, approach is to "
1194 "close the inotify file descriptor, empty the cache, create a new inotify "
1195 "file descriptor, and then re-create watches and cache entries for the "
1196 "objects to be monitored.)"
1197 msgstr ""
1198
1199 #. type: Plain text
1200 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1201 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1202 msgid ""
1203 "If a filesystem is mounted on top of a monitored directory, no event is "
1204 "generated, and no events are generated for objects immediately under the new "
1205 "mount point. If the filesystem is subsequently unmounted, events will "
1206 "subsequently be generated for the directory and the objects it contains."
1207 msgstr ""
1208
1209 #. type: SS
1210 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1211 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1212 #, no-wrap
1213 msgid "Dealing with rename() events"
1214 msgstr ""
1215
1216 #. type: Plain text
1217 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1218 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1219 msgid ""
1220 "As noted above, the B<IN_MOVED_FROM> and B<IN_MOVED_TO> event pair that is "
1221 "generated by B<rename>(2) can be matched up via their shared cookie value. "
1222 "However, the task of matching has some challenges."
1223 msgstr ""
1224
1225 #. type: Plain text
1226 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1227 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1228 msgid ""
1229 "These two events are usually consecutive in the event stream available when "
1230 "reading from the inotify file descriptor. However, this is not guaranteed. "
1231 "If multiple processes are triggering events for monitored objects, then (on "
1232 "rare occasions) an arbitrary number of other events may appear between the "
1233 "B<IN_MOVED_FROM> and B<IN_MOVED_TO> events. Furthermore, it is not "
1234 "guaranteed that the event pair is atomically inserted into the queue: there "
1235 "may be a brief interval where the B<IN_MOVED_FROM> has appeared, but the "
1236 "B<IN_MOVED_TO> has not."
1237 msgstr ""
1238
1239 #. type: Plain text
1240 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1241 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1242 msgid ""
1243 "Matching up the B<IN_MOVED_FROM> and B<IN_MOVED_TO> event pair generated by "
1244 "B<rename>(2) is thus inherently racy. (Don't forget that if an object is "
1245 "renamed outside of a monitored directory, there may not even be an "
1246 "B<IN_MOVED_TO> event.) Heuristic approaches (e.g., assume the events are "
1247 "always consecutive) can be used to ensure a match in most cases, but will "
1248 "inevitably miss some cases, causing the application to perceive the "
1249 "B<IN_MOVED_FROM> and B<IN_MOVED_TO> events as being unrelated. If watch "
1250 "descriptors are destroyed and re-created as a result, then those watch "
1251 "descriptors will be inconsistent with the watch descriptors in any pending "
1252 "events. (Re-creating the inotify file descriptor and rebuilding the cache "
1253 "may be useful to deal with this scenario.)"
1254 msgstr ""
1255
1256 #. type: Plain text
1257 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1258 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1259 msgid ""
1260 "Applications should also allow for the possibility that the B<IN_MOVED_FROM> "
1261 "event was the last event that could fit in the buffer returned by the "
1262 "current call to B<read>(2), and the accompanying B<IN_MOVED_TO> event might "
1263 "be fetched only on the next B<read>(2), which should be done with a (small) "
1264 "timeout to allow for the fact that insertion of the "
1265 "B<IN_MOVED_FROM>+B<IN_MOVED_TO> event pair is not atomic, and also the "
1266 "possibility that there may not be any B<IN_MOVED_TO> event."
1267 msgstr ""
1268
1269 #. type: SH
1270 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1271 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1272 #, no-wrap
1273 msgid "BUGS"
1274 msgstr ""
1275
1276 #. commit 820c12d5d6c0890bc93dd63893924a13041fdc35
1277 #. type: Plain text
1278 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1279 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1280 msgid ""
1281 "Before Linux 3.19, B<fallocate>(2) did not create any inotify events. "
1282 "Since Linux 3.19, calls to B<fallocate>(2) generate B<IN_MODIFY> events."
1283 msgstr ""
1284
1285 #. FIXME . kernel commit 611da04f7a31b2208e838be55a42c7a1310ae321
1286 #. implies that unmount events were buggy since Linux 2.6.11 to Linux 2.6.36
1287 #. type: Plain text
1288 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1289 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1290 msgid "Before Linux 2.6.16, the B<IN_ONESHOT> I<mask> flag does not work."
1291 msgstr ""
1292
1293 #. type: Plain text
1294 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1295 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1296 msgid ""
1297 "As originally designed and implemented, the B<IN_ONESHOT> flag did not cause "
1298 "an B<IN_IGNORED> event to be generated when the watch was dropped after one "
1299 "event. However, as an unintended effect of other changes, since Linux "
1300 "2.6.36, an B<IN_IGNORED> event is generated in this case."
1301 msgstr ""
1302
1303 #. commit 1c17d18e3775485bf1e0ce79575eb637a94494a2
1304 #. type: Plain text
1305 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1306 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1307 msgid ""
1308 "Before Linux 2.6.25, the kernel code that was intended to coalesce "
1309 "successive identical events (i.e., the two most recent events could "
1310 "potentially be coalesced if the older had not yet been read) instead "
1311 "checked if the most recent event could be coalesced with the I<oldest> "
1312 "unread event."
1313 msgstr ""
1314
1315 #. FIXME . https://bugzilla.kernel.org/show_bug.cgi?id=77111
1316 #. type: Plain text
1317 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1318 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1319 msgid ""
1320 "When a watch descriptor is removed by calling B<inotify_rm_watch>(2) (or "
1321 "because a watch file is deleted or the filesystem that contains it is "
1322 "unmounted), any pending unread events for that watch descriptor remain "
1323 "available to read. As watch descriptors are subsequently allocated with "
1324 "B<inotify_add_watch>(2), the kernel cycles through the range of possible "
1325 "watch descriptors (1 to B<INT_MAX>) incrementally. When allocating a free "
1326 "watch descriptor, no check is made to see whether that watch descriptor "
1327 "number has any pending unread events in the inotify queue. Thus, it can "
1328 "happen that a watch descriptor is reallocated even when pending unread "
1329 "events exist for a previous incarnation of that watch descriptor number, "
1330 "with the result that the application might then read those events and "
1331 "interpret them as belonging to the file associated with the newly recycled "
1332 "watch descriptor. In practice, the likelihood of hitting this bug may be "
1333 "extremely low, since it requires that an application cycle through "
1334 "B<INT_MAX> watch descriptors, release a watch descriptor while leaving "
1335 "unread events for that watch descriptor in the queue, and then recycle that "
1336 "watch descriptor. For this reason, and because there have been no reports "
1337 "of the bug occurring in real-world applications, as of Linux 3.15, no kernel "
1338 "changes have yet been made to eliminate this possible bug."
1339 msgstr ""
1340
1341 #. type: SH
1342 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1343 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1344 #, no-wrap
1345 msgid "EXAMPLES"
1346 msgstr ""
1347
1348 #. type: Plain text
1349 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1350 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1351 msgid ""
1352 "The following program demonstrates the usage of the inotify API. It marks "
1353 "the directories passed as a command-line arguments and waits for events of "
1354 "type B<IN_OPEN>, B<IN_CLOSE_NOWRITE>, and B<IN_CLOSE_WRITE>."
1355 msgstr ""
1356
1357 #. type: Plain text
1358 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1359 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1360 msgid ""
1361 "The following output was recorded while editing the file I</home/user/temp/"
1362 "foo> and listing directory I</tmp>. Before the file and the directory were "
1363 "opened, B<IN_OPEN> events occurred. After the file was closed, an "
1364 "B<IN_CLOSE_WRITE> event occurred. After the directory was closed, an "
1365 "B<IN_CLOSE_NOWRITE> event occurred. Execution of the program ended when the "
1366 "user pressed the ENTER key."
1367 msgstr ""
1368
1369 #. type: SS
1370 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1371 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1372 #, no-wrap
1373 msgid "Example output"
1374 msgstr ""
1375
1376 #. type: Plain text
1377 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1378 #: opensuse-tumbleweed
1379 #, no-wrap
1380 msgid ""
1381 "$B< ./a.out /tmp /home/user/temp>;\n"
1382 "Press enter key to terminate.\n"
1383 "Listening for events.\n"
1384 "IN_OPEN: /home/user/temp/foo [file]\n"
1385 "IN_CLOSE_WRITE: /home/user/temp/foo [file]\n"
1386 "IN_OPEN: /tmp/ [directory]\n"
1387 "IN_CLOSE_NOWRITE: /tmp/ [directory]\n"
1388 "\\&\n"
1389 "Listening for events stopped.\n"
1390 msgstr ""
1391
1392 #. type: SS
1393 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1394 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1395 #, no-wrap
1396 msgid "Program source"
1397 msgstr ""
1398
1399 #. type: Plain text
1400 #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed
1401 #, no-wrap
1402 msgid ""
1403 "#include E<lt>errno.hE<gt>\n"
1404 "#include E<lt>poll.hE<gt>\n"
1405 "#include E<lt>stdio.hE<gt>\n"
1406 "#include E<lt>stdlib.hE<gt>\n"
1407 "#include E<lt>sys/inotify.hE<gt>\n"
1408 "#include E<lt>unistd.hE<gt>\n"
1409 "#include E<lt>string.hE<gt>\n"
1410 "\\&\n"
1411 "/* Read all available inotify events from the file descriptor \\[aq]fd\\[aq].\n"
1412 " wd is the table of watch descriptors for the directories in argv.\n"
1413 " argc is the size of wd and argv.\n"
1414 " argv is the list of watched directories.\n"
1415 " Entry 0 of wd and argv is unused. */\n"
1416 "\\&\n"
1417 "static void\n"
1418 "handle_events(int fd, int *wd, int argc, char* argv[])\n"
1419 "{\n"
1420 " /* Some systems cannot read integer variables if they are not\n"
1421 " properly aligned. On other systems, incorrect alignment may\n"
1422 " decrease performance. Hence, the buffer used for reading from\n"
1423 " the inotify file descriptor should have the same alignment as\n"
1424 " struct inotify_event. */\n"
1425 "\\&\n"
1426 " char buf[4096]\n"
1427 " __attribute__ ((aligned(__alignof__(struct inotify_event))));\n"
1428 " const struct inotify_event *event;\n"
1429 " ssize_t size;\n"
1430 "\\&\n"
1431 " /* Loop while events can be read from inotify file descriptor. */\n"
1432 "\\&\n"
1433 " for (;;) {\n"
1434 "\\&\n"
1435 " /* Read some events. */\n"
1436 "\\&\n"
1437 " size = read(fd, buf, sizeof(buf));\n"
1438 " if (size == -1 && errno != EAGAIN) {\n"
1439 " perror(\"read\");\n"
1440 " exit(EXIT_FAILURE);\n"
1441 " }\n"
1442 "\\&\n"
1443 " /* If the nonblocking read() found no events to read, then\n"
1444 " it returns -1 with errno set to EAGAIN. In that case,\n"
1445 " we exit the loop. */\n"
1446 "\\&\n"
1447 " if (size E<lt>= 0)\n"
1448 " break;\n"
1449 "\\&\n"
1450 " /* Loop over all events in the buffer. */\n"
1451 "\\&\n"
1452 " for (char *ptr = buf; ptr E<lt> buf + size;\n"
1453 " ptr += sizeof(struct inotify_event) + event-E<gt>len) {\n"
1454 "\\&\n"
1455 " event = (const struct inotify_event *) ptr;\n"
1456 "\\&\n"
1457 " /* Print event type. */\n"
1458 "\\&\n"
1459 " if (event-E<gt>mask & IN_OPEN)\n"
1460 " printf(\"IN_OPEN: \");\n"
1461 " if (event-E<gt>mask & IN_CLOSE_NOWRITE)\n"
1462 " printf(\"IN_CLOSE_NOWRITE: \");\n"
1463 " if (event-E<gt>mask & IN_CLOSE_WRITE)\n"
1464 " printf(\"IN_CLOSE_WRITE: \");\n"
1465 "\\&\n"
1466 " /* Print the name of the watched directory. */\n"
1467 "\\&\n"
1468 " for (size_t i = 1; i E<lt> argc; ++i) {\n"
1469 " if (wd[i] == event-E<gt>wd) {\n"
1470 " printf(\"%s/\", argv[i]);\n"
1471 " break;\n"
1472 " }\n"
1473 " }\n"
1474 "\\&\n"
1475 " /* Print the name of the file. */\n"
1476 "\\&\n"
1477 " if (event-E<gt>len)\n"
1478 " printf(\"%s\", event-E<gt>name);\n"
1479 "\\&\n"
1480 " /* Print type of filesystem object. */\n"
1481 "\\&\n"
1482 " if (event-E<gt>mask & IN_ISDIR)\n"
1483 " printf(\" [directory]\\[rs]n\");\n"
1484 " else\n"
1485 " printf(\" [file]\\[rs]n\");\n"
1486 " }\n"
1487 " }\n"
1488 "}\n"
1489 "\\&\n"
1490 "int\n"
1491 "main(int argc, char* argv[])\n"
1492 "{\n"
1493 " char buf;\n"
1494 " int fd, i, poll_num;\n"
1495 " int *wd;\n"
1496 " nfds_t nfds;\n"
1497 " struct pollfd fds[2];\n"
1498 "\\&\n"
1499 " if (argc E<lt> 2) {\n"
1500 " printf(\"Usage: %s PATH [PATH ...]\\[rs]n\", argv[0]);\n"
1501 " exit(EXIT_FAILURE);\n"
1502 " }\n"
1503 "\\&\n"
1504 " printf(\"Press ENTER key to terminate.\\[rs]n\");\n"
1505 "\\&\n"
1506 " /* Create the file descriptor for accessing the inotify API. */\n"
1507 "\\&\n"
1508 " fd = inotify_init1(IN_NONBLOCK);\n"
1509 " if (fd == -1) {\n"
1510 " perror(\"inotify_init1\");\n"
1511 " exit(EXIT_FAILURE);\n"
1512 " }\n"
1513 "\\&\n"
1514 " /* Allocate memory for watch descriptors. */\n"
1515 "\\&\n"
1516 " wd = calloc(argc, sizeof(int));\n"
1517 " if (wd == NULL) {\n"
1518 " perror(\"calloc\");\n"
1519 " exit(EXIT_FAILURE);\n"
1520 " }\n"
1521 "\\&\n"
1522 " /* Mark directories for events\n"
1523 " - file was opened\n"
1524 " - file was closed */\n"
1525 "\\&\n"
1526 " for (i = 1; i E<lt> argc; i++) {\n"
1527 " wd[i] = inotify_add_watch(fd, argv[i],\n"
1528 " IN_OPEN | IN_CLOSE);\n"
1529 " if (wd[i] == -1) {\n"
1530 " fprintf(stderr, \"Cannot watch \\[aq]%s\\[aq]: %s\\[rs]n\",\n"
1531 " argv[i], strerror(errno));\n"
1532 " exit(EXIT_FAILURE);\n"
1533 " }\n"
1534 " }\n"
1535 "\\&\n"
1536 " /* Prepare for polling. */\n"
1537 "\\&\n"
1538 " nfds = 2;\n"
1539 "\\&\n"
1540 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
1541 " fds[0].events = POLLIN;\n"
1542 "\\&\n"
1543 " fds[1].fd = fd; /* Inotify input */\n"
1544 " fds[1].events = POLLIN;\n"
1545 "\\&\n"
1546 " /* Wait for events and/or terminal input. */\n"
1547 "\\&\n"
1548 " printf(\"Listening for events.\\[rs]n\");\n"
1549 " for (;;) {\n"
1550 " poll_num = poll(fds, nfds, -1);\n"
1551 " if (poll_num == -1) {\n"
1552 " if (errno == EINTR)\n"
1553 " continue;\n"
1554 " perror(\"poll\");\n"
1555 " exit(EXIT_FAILURE);\n"
1556 " }\n"
1557 "\\&\n"
1558 " if (poll_num E<gt> 0) {\n"
1559 "\\&\n"
1560 " if (fds[0].revents & POLLIN) {\n"
1561 "\\&\n"
1562 " /* Console input is available. Empty stdin and quit. */\n"
1563 "\\&\n"
1564 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
1565 " continue;\n"
1566 " break;\n"
1567 " }\n"
1568 "\\&\n"
1569 " if (fds[1].revents & POLLIN) {\n"
1570 "\\&\n"
1571 " /* Inotify events are available. */\n"
1572 "\\&\n"
1573 " handle_events(fd, wd, argc, argv);\n"
1574 " }\n"
1575 " }\n"
1576 " }\n"
1577 "\\&\n"
1578 " printf(\"Listening for events stopped.\\[rs]n\");\n"
1579 "\\&\n"
1580 " /* Close inotify file descriptor. */\n"
1581 "\\&\n"
1582 " close(fd);\n"
1583 "\\&\n"
1584 " free(wd);\n"
1585 " exit(EXIT_SUCCESS);\n"
1586 "}\n"
1587 msgstr ""
1588
1589 #. type: SH
1590 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1591 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1592 #, no-wrap
1593 msgid "SEE ALSO"
1594 msgstr ""
1595
1596 #. type: Plain text
1597 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1598 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1599 msgid ""
1600 "B<inotifywait>(1), B<inotifywatch>(1), B<inotify_add_watch>(2), "
1601 "B<inotify_init>(2), B<inotify_init1>(2), B<inotify_rm_watch>(2), B<read>(2), "
1602 "B<stat>(2), B<fanotify>(7)"
1603 msgstr ""
1604
1605 #. type: Plain text
1606 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1607 #: opensuse-tumbleweed
1608 msgid ""
1609 "I<Documentation/filesystems/inotify.rst> in the Linux kernel source tree"
1610 msgstr ""
1611
1612 #. type: TH
1613 #: debian-trixie
1614 #, no-wrap
1615 msgid "2024-06-15"
1616 msgstr ""
1617
1618 #. type: TH
1619 #: debian-trixie
1620 #, no-wrap
1621 msgid "Linux man-pages 6.9.1"
1622 msgstr ""
1623
1624 #. FIXME . The type of the 'wd' field should probably be "int32_t".
1625 #. I submitted a patch to fix this. See the LKML thread
1626 #. "[patch] Fix type errors in inotify interfaces", 18 Nov 2008
1627 #. glibc bug filed: https://www.sourceware.org/bugzilla/show_bug.cgi?id=7040
1628 #. type: Plain text
1629 #: debian-trixie fedora-44 fedora-rawhide
1630 #, no-wrap
1631 msgid ""
1632 "struct inotify_event {\n"
1633 " int wd; /* Watch descriptor */\n"
1634 " uint32_t mask; /* Mask describing event */\n"
1635 " uint32_t cookie; /* Unique cookie associating related\n"
1636 " events (for rename(2)) */\n"
1637 " uint32_t len; /* Size of I<name> field */\n"
1638 " char name[]; /* Optional null-terminated name */\n"
1639 "};\n"
1640 msgstr ""
1641
1642 #. type: Plain text
1643 #: debian-trixie
1644 msgid ""
1645 "The I<len> field counts all of the bytes in I<name>, including the null "
1646 "bytes; the length of each I<inotify_event> structure is thus I<sizeof(struct "
1647 "inotify_event)+len>."
1648 msgstr ""
1649
1650 #. type: Plain text
1651 #: debian-trixie fedora-44 fedora-rawhide
1652 #, no-wrap
1653 msgid ""
1654 "$ B<./a.out /tmp /home/user/temp>\n"
1655 "Press enter key to terminate.\n"
1656 "Listening for events.\n"
1657 "IN_OPEN: /home/user/temp/foo [file]\n"
1658 "IN_CLOSE_WRITE: /home/user/temp/foo [file]\n"
1659 "IN_OPEN: /tmp/ [directory]\n"
1660 "IN_CLOSE_NOWRITE: /tmp/ [directory]\n"
1661 "\\&\n"
1662 "Listening for events stopped.\n"
1663 msgstr ""
1664
1665 #. type: Plain text
1666 #: debian-trixie
1667 #, no-wrap
1668 msgid ""
1669 "#include E<lt>errno.hE<gt>\n"
1670 "#include E<lt>poll.hE<gt>\n"
1671 "#include E<lt>stdio.hE<gt>\n"
1672 "#include E<lt>stdlib.hE<gt>\n"
1673 "#include E<lt>sys/inotify.hE<gt>\n"
1674 "#include E<lt>unistd.hE<gt>\n"
1675 "#include E<lt>string.hE<gt>\n"
1676 "\\&\n"
1677 "/* Read all available inotify events from the file descriptor \\[aq]fd\\[aq].\n"
1678 " wd is the table of watch descriptors for the directories in argv.\n"
1679 " argc is the length of wd and argv.\n"
1680 " argv is the list of watched directories.\n"
1681 " Entry 0 of wd and argv is unused. */\n"
1682 "\\&\n"
1683 "static void\n"
1684 "handle_events(int fd, int *wd, int argc, char* argv[])\n"
1685 "{\n"
1686 " /* Some systems cannot read integer variables if they are not\n"
1687 " properly aligned. On other systems, incorrect alignment may\n"
1688 " decrease performance. Hence, the buffer used for reading from\n"
1689 " the inotify file descriptor should have the same alignment as\n"
1690 " struct inotify_event. */\n"
1691 "\\&\n"
1692 " char buf[4096]\n"
1693 " __attribute__ ((aligned(__alignof__(struct inotify_event))));\n"
1694 " const struct inotify_event *event;\n"
1695 " ssize_t len;\n"
1696 "\\&\n"
1697 " /* Loop while events can be read from inotify file descriptor. */\n"
1698 "\\&\n"
1699 " for (;;) {\n"
1700 "\\&\n"
1701 " /* Read some events. */\n"
1702 "\\&\n"
1703 " len = read(fd, buf, sizeof(buf));\n"
1704 " if (len == -1 && errno != EAGAIN) {\n"
1705 " perror(\"read\");\n"
1706 " exit(EXIT_FAILURE);\n"
1707 " }\n"
1708 "\\&\n"
1709 " /* If the nonblocking read() found no events to read, then\n"
1710 " it returns -1 with errno set to EAGAIN. In that case,\n"
1711 " we exit the loop. */\n"
1712 "\\&\n"
1713 " if (len E<lt>= 0)\n"
1714 " break;\n"
1715 "\\&\n"
1716 " /* Loop over all events in the buffer. */\n"
1717 "\\&\n"
1718 " for (char *ptr = buf; ptr E<lt> buf + len;\n"
1719 " ptr += sizeof(struct inotify_event) + event-E<gt>len) {\n"
1720 "\\&\n"
1721 " event = (const struct inotify_event *) ptr;\n"
1722 "\\&\n"
1723 " /* Print event type. */\n"
1724 "\\&\n"
1725 " if (event-E<gt>mask & IN_OPEN)\n"
1726 " printf(\"IN_OPEN: \");\n"
1727 " if (event-E<gt>mask & IN_CLOSE_NOWRITE)\n"
1728 " printf(\"IN_CLOSE_NOWRITE: \");\n"
1729 " if (event-E<gt>mask & IN_CLOSE_WRITE)\n"
1730 " printf(\"IN_CLOSE_WRITE: \");\n"
1731 "\\&\n"
1732 " /* Print the name of the watched directory. */\n"
1733 "\\&\n"
1734 " for (size_t i = 1; i E<lt> argc; ++i) {\n"
1735 " if (wd[i] == event-E<gt>wd) {\n"
1736 " printf(\"%s/\", argv[i]);\n"
1737 " break;\n"
1738 " }\n"
1739 " }\n"
1740 "\\&\n"
1741 " /* Print the name of the file. */\n"
1742 "\\&\n"
1743 " if (event-E<gt>len)\n"
1744 " printf(\"%s\", event-E<gt>name);\n"
1745 "\\&\n"
1746 " /* Print type of filesystem object. */\n"
1747 "\\&\n"
1748 " if (event-E<gt>mask & IN_ISDIR)\n"
1749 " printf(\" [directory]\\[rs]n\");\n"
1750 " else\n"
1751 " printf(\" [file]\\[rs]n\");\n"
1752 " }\n"
1753 " }\n"
1754 "}\n"
1755 "\\&\n"
1756 "int\n"
1757 "main(int argc, char* argv[])\n"
1758 "{\n"
1759 " char buf;\n"
1760 " int fd, i, poll_num;\n"
1761 " int *wd;\n"
1762 " nfds_t nfds;\n"
1763 " struct pollfd fds[2];\n"
1764 "\\&\n"
1765 " if (argc E<lt> 2) {\n"
1766 " printf(\"Usage: %s PATH [PATH ...]\\[rs]n\", argv[0]);\n"
1767 " exit(EXIT_FAILURE);\n"
1768 " }\n"
1769 "\\&\n"
1770 " printf(\"Press ENTER key to terminate.\\[rs]n\");\n"
1771 "\\&\n"
1772 " /* Create the file descriptor for accessing the inotify API. */\n"
1773 "\\&\n"
1774 " fd = inotify_init1(IN_NONBLOCK);\n"
1775 " if (fd == -1) {\n"
1776 " perror(\"inotify_init1\");\n"
1777 " exit(EXIT_FAILURE);\n"
1778 " }\n"
1779 "\\&\n"
1780 " /* Allocate memory for watch descriptors. */\n"
1781 "\\&\n"
1782 " wd = calloc(argc, sizeof(int));\n"
1783 " if (wd == NULL) {\n"
1784 " perror(\"calloc\");\n"
1785 " exit(EXIT_FAILURE);\n"
1786 " }\n"
1787 "\\&\n"
1788 " /* Mark directories for events\n"
1789 " - file was opened\n"
1790 " - file was closed */\n"
1791 "\\&\n"
1792 " for (i = 1; i E<lt> argc; i++) {\n"
1793 " wd[i] = inotify_add_watch(fd, argv[i],\n"
1794 " IN_OPEN | IN_CLOSE);\n"
1795 " if (wd[i] == -1) {\n"
1796 " fprintf(stderr, \"Cannot watch \\[aq]%s\\[aq]: %s\\[rs]n\",\n"
1797 " argv[i], strerror(errno));\n"
1798 " exit(EXIT_FAILURE);\n"
1799 " }\n"
1800 " }\n"
1801 "\\&\n"
1802 " /* Prepare for polling. */\n"
1803 "\\&\n"
1804 " nfds = 2;\n"
1805 "\\&\n"
1806 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
1807 " fds[0].events = POLLIN;\n"
1808 "\\&\n"
1809 " fds[1].fd = fd; /* Inotify input */\n"
1810 " fds[1].events = POLLIN;\n"
1811 "\\&\n"
1812 " /* Wait for events and/or terminal input. */\n"
1813 "\\&\n"
1814 " printf(\"Listening for events.\\[rs]n\");\n"
1815 " while (1) {\n"
1816 " poll_num = poll(fds, nfds, -1);\n"
1817 " if (poll_num == -1) {\n"
1818 " if (errno == EINTR)\n"
1819 " continue;\n"
1820 " perror(\"poll\");\n"
1821 " exit(EXIT_FAILURE);\n"
1822 " }\n"
1823 "\\&\n"
1824 " if (poll_num E<gt> 0) {\n"
1825 "\\&\n"
1826 " if (fds[0].revents & POLLIN) {\n"
1827 "\\&\n"
1828 " /* Console input is available. Empty stdin and quit. */\n"
1829 "\\&\n"
1830 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
1831 " continue;\n"
1832 " break;\n"
1833 " }\n"
1834 "\\&\n"
1835 " if (fds[1].revents & POLLIN) {\n"
1836 "\\&\n"
1837 " /* Inotify events are available. */\n"
1838 "\\&\n"
1839 " handle_events(fd, wd, argc, argv);\n"
1840 " }\n"
1841 " }\n"
1842 " }\n"
1843 "\\&\n"
1844 " printf(\"Listening for events stopped.\\[rs]n\");\n"
1845 "\\&\n"
1846 " /* Close inotify file descriptor. */\n"
1847 "\\&\n"
1848 " close(fd);\n"
1849 "\\&\n"
1850 " free(wd);\n"
1851 " exit(EXIT_SUCCESS);\n"
1852 "}\n"
1853 msgstr ""
1854
1855 #. type: Plain text
1856 #: debian-trixie fedora-44 fedora-rawhide
1857 msgid ""
1858 "I<Documentation/filesystems/inotify.txt> in the Linux kernel source tree"
1859 msgstr ""
1860
1861 #. type: TH
1862 #: fedora-44 fedora-rawhide
1863 #, no-wrap
1864 msgid "2024-11-17"
1865 msgstr ""
1866
1867 #. type: TH
1868 #: fedora-44 fedora-rawhide
1869 #, no-wrap
1870 msgid "Linux man-pages 6.13"
1871 msgstr ""
1872
1873 #. type: Plain text
1874 #: fedora-44 fedora-rawhide
1875 #, no-wrap
1876 msgid ""
1877 "#include E<lt>errno.hE<gt>\n"
1878 "#include E<lt>poll.hE<gt>\n"
1879 "#include E<lt>stdio.hE<gt>\n"
1880 "#include E<lt>stdlib.hE<gt>\n"
1881 "#include E<lt>sys/inotify.hE<gt>\n"
1882 "#include E<lt>unistd.hE<gt>\n"
1883 "#include E<lt>string.hE<gt>\n"
1884 "\\&\n"
1885 "/* Read all available inotify events from the file descriptor \\[aq]fd\\[aq].\n"
1886 " wd is the table of watch descriptors for the directories in argv.\n"
1887 " argc is the size of wd and argv.\n"
1888 " argv is the list of watched directories.\n"
1889 " Entry 0 of wd and argv is unused. */\n"
1890 "\\&\n"
1891 "static void\n"
1892 "handle_events(int fd, int *wd, int argc, char* argv[])\n"
1893 "{\n"
1894 " /* Some systems cannot read integer variables if they are not\n"
1895 " properly aligned. On other systems, incorrect alignment may\n"
1896 " decrease performance. Hence, the buffer used for reading from\n"
1897 " the inotify file descriptor should have the same alignment as\n"
1898 " struct inotify_event. */\n"
1899 "\\&\n"
1900 " char buf[4096]\n"
1901 " __attribute__ ((aligned(__alignof__(struct inotify_event))));\n"
1902 " const struct inotify_event *event;\n"
1903 " ssize_t size;\n"
1904 "\\&\n"
1905 " /* Loop while events can be read from inotify file descriptor. */\n"
1906 "\\&\n"
1907 " for (;;) {\n"
1908 "\\&\n"
1909 " /* Read some events. */\n"
1910 "\\&\n"
1911 " size = read(fd, buf, sizeof(buf));\n"
1912 " if (size == -1 && errno != EAGAIN) {\n"
1913 " perror(\"read\");\n"
1914 " exit(EXIT_FAILURE);\n"
1915 " }\n"
1916 "\\&\n"
1917 " /* If the nonblocking read() found no events to read, then\n"
1918 " it returns -1 with errno set to EAGAIN. In that case,\n"
1919 " we exit the loop. */\n"
1920 "\\&\n"
1921 " if (size E<lt>= 0)\n"
1922 " break;\n"
1923 "\\&\n"
1924 " /* Loop over all events in the buffer. */\n"
1925 "\\&\n"
1926 " for (char *ptr = buf; ptr E<lt> buf + size;\n"
1927 " ptr += sizeof(struct inotify_event) + event-E<gt>len) {\n"
1928 "\\&\n"
1929 " event = (const struct inotify_event *) ptr;\n"
1930 "\\&\n"
1931 " /* Print event type. */\n"
1932 "\\&\n"
1933 " if (event-E<gt>mask & IN_OPEN)\n"
1934 " printf(\"IN_OPEN: \");\n"
1935 " if (event-E<gt>mask & IN_CLOSE_NOWRITE)\n"
1936 " printf(\"IN_CLOSE_NOWRITE: \");\n"
1937 " if (event-E<gt>mask & IN_CLOSE_WRITE)\n"
1938 " printf(\"IN_CLOSE_WRITE: \");\n"
1939 "\\&\n"
1940 " /* Print the name of the watched directory. */\n"
1941 "\\&\n"
1942 " for (size_t i = 1; i E<lt> argc; ++i) {\n"
1943 " if (wd[i] == event-E<gt>wd) {\n"
1944 " printf(\"%s/\", argv[i]);\n"
1945 " break;\n"
1946 " }\n"
1947 " }\n"
1948 "\\&\n"
1949 " /* Print the name of the file. */\n"
1950 "\\&\n"
1951 " if (event-E<gt>len)\n"
1952 " printf(\"%s\", event-E<gt>name);\n"
1953 "\\&\n"
1954 " /* Print type of filesystem object. */\n"
1955 "\\&\n"
1956 " if (event-E<gt>mask & IN_ISDIR)\n"
1957 " printf(\" [directory]\\[rs]n\");\n"
1958 " else\n"
1959 " printf(\" [file]\\[rs]n\");\n"
1960 " }\n"
1961 " }\n"
1962 "}\n"
1963 "\\&\n"
1964 "int\n"
1965 "main(int argc, char* argv[])\n"
1966 "{\n"
1967 " char buf;\n"
1968 " int fd, i, poll_num;\n"
1969 " int *wd;\n"
1970 " nfds_t nfds;\n"
1971 " struct pollfd fds[2];\n"
1972 "\\&\n"
1973 " if (argc E<lt> 2) {\n"
1974 " printf(\"Usage: %s PATH [PATH ...]\\[rs]n\", argv[0]);\n"
1975 " exit(EXIT_FAILURE);\n"
1976 " }\n"
1977 "\\&\n"
1978 " printf(\"Press ENTER key to terminate.\\[rs]n\");\n"
1979 "\\&\n"
1980 " /* Create the file descriptor for accessing the inotify API. */\n"
1981 "\\&\n"
1982 " fd = inotify_init1(IN_NONBLOCK);\n"
1983 " if (fd == -1) {\n"
1984 " perror(\"inotify_init1\");\n"
1985 " exit(EXIT_FAILURE);\n"
1986 " }\n"
1987 "\\&\n"
1988 " /* Allocate memory for watch descriptors. */\n"
1989 "\\&\n"
1990 " wd = calloc(argc, sizeof(int));\n"
1991 " if (wd == NULL) {\n"
1992 " perror(\"calloc\");\n"
1993 " exit(EXIT_FAILURE);\n"
1994 " }\n"
1995 "\\&\n"
1996 " /* Mark directories for events\n"
1997 " - file was opened\n"
1998 " - file was closed */\n"
1999 "\\&\n"
2000 " for (i = 1; i E<lt> argc; i++) {\n"
2001 " wd[i] = inotify_add_watch(fd, argv[i],\n"
2002 " IN_OPEN | IN_CLOSE);\n"
2003 " if (wd[i] == -1) {\n"
2004 " fprintf(stderr, \"Cannot watch \\[aq]%s\\[aq]: %s\\[rs]n\",\n"
2005 " argv[i], strerror(errno));\n"
2006 " exit(EXIT_FAILURE);\n"
2007 " }\n"
2008 " }\n"
2009 "\\&\n"
2010 " /* Prepare for polling. */\n"
2011 "\\&\n"
2012 " nfds = 2;\n"
2013 "\\&\n"
2014 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
2015 " fds[0].events = POLLIN;\n"
2016 "\\&\n"
2017 " fds[1].fd = fd; /* Inotify input */\n"
2018 " fds[1].events = POLLIN;\n"
2019 "\\&\n"
2020 " /* Wait for events and/or terminal input. */\n"
2021 "\\&\n"
2022 " printf(\"Listening for events.\\[rs]n\");\n"
2023 " while (1) {\n"
2024 " poll_num = poll(fds, nfds, -1);\n"
2025 " if (poll_num == -1) {\n"
2026 " if (errno == EINTR)\n"
2027 " continue;\n"
2028 " perror(\"poll\");\n"
2029 " exit(EXIT_FAILURE);\n"
2030 " }\n"
2031 "\\&\n"
2032 " if (poll_num E<gt> 0) {\n"
2033 "\\&\n"
2034 " if (fds[0].revents & POLLIN) {\n"
2035 "\\&\n"
2036 " /* Console input is available. Empty stdin and quit. */\n"
2037 "\\&\n"
2038 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
2039 " continue;\n"
2040 " break;\n"
2041 " }\n"
2042 "\\&\n"
2043 " if (fds[1].revents & POLLIN) {\n"
2044 "\\&\n"
2045 " /* Inotify events are available. */\n"
2046 "\\&\n"
2047 " handle_events(fd, wd, argc, argv);\n"
2048 " }\n"
2049 " }\n"
2050 " }\n"
2051 "\\&\n"
2052 " printf(\"Listening for events stopped.\\[rs]n\");\n"
2053 "\\&\n"
2054 " /* Close inotify file descriptor. */\n"
2055 "\\&\n"
2056 " close(fd);\n"
2057 "\\&\n"
2058 " free(wd);\n"
2059 " exit(EXIT_SUCCESS);\n"
2060 "}\n"
2061 msgstr ""
2062
2063 #. type: TH
2064 #: mageia-cauldron
2065 #, no-wrap
2066 msgid "2026-02-08"
2067 msgstr ""
2068
2069 #. type: TH
2070 #: mageia-cauldron
2071 #, no-wrap
2072 msgid "Linux man-pages 6.17"
2073 msgstr ""
2074
2075 #. type: Plain text
2076 #: mageia-cauldron
2077 #, no-wrap
2078 msgid ""
2079 "#include E<lt>errno.hE<gt>\n"
2080 "#include E<lt>poll.hE<gt>\n"
2081 "#include E<lt>stdio.hE<gt>\n"
2082 "#include E<lt>stdlib.hE<gt>\n"
2083 "#include E<lt>sys/inotify.hE<gt>\n"
2084 "#include E<lt>unistd.hE<gt>\n"
2085 "#include E<lt>string.hE<gt>\n"
2086 "\\&\n"
2087 "/* Read all available inotify events from the file descriptor \\[aq]fd\\[aq].\n"
2088 " wd is the table of watch descriptors for the directories in argv.\n"
2089 " argc is the size of wd and argv.\n"
2090 " argv is the list of watched directories.\n"
2091 " Entry 0 of wd and argv is unused. */\n"
2092 "\\&\n"
2093 "static void\n"
2094 "handle_events(int fd, int *wd, int argc, char* argv[])\n"
2095 "{\n"
2096 " /* Some systems cannot read integer variables if they are not\n"
2097 " properly aligned. On other systems, incorrect alignment may\n"
2098 " decrease performance. Hence, the buffer used for reading from\n"
2099 " the inotify file descriptor should have the same alignment as\n"
2100 " struct inotify_event. */\n"
2101 "\\&\n"
2102 " char buf[4096]\n"
2103 " __attribute__ ((aligned(__alignof__(struct inotify_event))));\n"
2104 " const struct inotify_event *event;\n"
2105 " ssize_t size;\n"
2106 "\\&\n"
2107 " /* Loop while events can be read from inotify file descriptor. */\n"
2108 "\\&\n"
2109 " for (;;) {\n"
2110 "\\&\n"
2111 " /* Read some events. */\n"
2112 "\\&\n"
2113 " size = read(fd, buf, sizeof(buf));\n"
2114 " if (size == -1 && errno != EAGAIN) {\n"
2115 " perror(\"read\");\n"
2116 " exit(EXIT_FAILURE);\n"
2117 " }\n"
2118 "\\&\n"
2119 " /* If the nonblocking read() found no events to read, then\n"
2120 " it returns -1 with errno set to EAGAIN. In that case,\n"
2121 " we exit the loop. */\n"
2122 "\\&\n"
2123 " if (size E<lt>= 0)\n"
2124 " break;\n"
2125 "\\&\n"
2126 " /* Loop over all events in the buffer. */\n"
2127 "\\&\n"
2128 " for (char *ptr = buf; ptr E<lt> buf + size;\n"
2129 " ptr += sizeof(struct inotify_event) + event-E<gt>len) {\n"
2130 "\\&\n"
2131 " event = (const struct inotify_event *) ptr;\n"
2132 "\\&\n"
2133 " /* Print event type. */\n"
2134 "\\&\n"
2135 " if (event-E<gt>mask & IN_OPEN)\n"
2136 " printf(\"IN_OPEN: \");\n"
2137 " if (event-E<gt>mask & IN_CLOSE_NOWRITE)\n"
2138 " printf(\"IN_CLOSE_NOWRITE: \");\n"
2139 " if (event-E<gt>mask & IN_CLOSE_WRITE)\n"
2140 " printf(\"IN_CLOSE_WRITE: \");\n"
2141 "\\&\n"
2142 " /* Print the name of the watched directory. */\n"
2143 "\\&\n"
2144 " for (size_t i = 1; i E<lt> argc; ++i) {\n"
2145 " if (wd[i] == event-E<gt>wd) {\n"
2146 " printf(\"%s/\", argv[i]);\n"
2147 " break;\n"
2148 " }\n"
2149 " }\n"
2150 "\\&\n"
2151 " /* Print the name of the file. */\n"
2152 "\\&\n"
2153 " if (event-E<gt>len)\n"
2154 " printf(\"%s\", event-E<gt>name);\n"
2155 "\\&\n"
2156 " /* Print type of filesystem object. */\n"
2157 "\\&\n"
2158 " if (event-E<gt>mask & IN_ISDIR)\n"
2159 " printf(\" [directory]\\[rs]n\");\n"
2160 " else\n"
2161 " printf(\" [file]\\[rs]n\");\n"
2162 " }\n"
2163 " }\n"
2164 "}\n"
2165 "\\&\n"
2166 "int\n"
2167 "main(int argc, char* argv[])\n"
2168 "{\n"
2169 " char buf;\n"
2170 " int fd, i, poll_num;\n"
2171 " int *wd;\n"
2172 " nfds_t nfds;\n"
2173 " struct pollfd fds[2];\n"
2174 "\\&\n"
2175 " if (argc E<lt> 2) {\n"
2176 " printf(\"Usage: %s PATH [PATH ...]\\[rs]n\", argv[0]);\n"
2177 " exit(EXIT_FAILURE);\n"
2178 " }\n"
2179 "\\&\n"
2180 " printf(\"Press ENTER key to terminate.\\[rs]n\");\n"
2181 "\\&\n"
2182 " /* Create the file descriptor for accessing the inotify API. */\n"
2183 "\\&\n"
2184 " fd = inotify_init1(IN_NONBLOCK);\n"
2185 " if (fd == -1) {\n"
2186 " perror(\"inotify_init1\");\n"
2187 " exit(EXIT_FAILURE);\n"
2188 " }\n"
2189 "\\&\n"
2190 " /* Allocate memory for watch descriptors. */\n"
2191 "\\&\n"
2192 " wd = calloc(argc, sizeof(int));\n"
2193 " if (wd == NULL) {\n"
2194 " perror(\"calloc\");\n"
2195 " exit(EXIT_FAILURE);\n"
2196 " }\n"
2197 "\\&\n"
2198 " /* Mark directories for events\n"
2199 " - file was opened\n"
2200 " - file was closed */\n"
2201 "\\&\n"
2202 " for (i = 1; i E<lt> argc; i++) {\n"
2203 " wd[i] = inotify_add_watch(fd, argv[i],\n"
2204 " IN_OPEN | IN_CLOSE);\n"
2205 " if (wd[i] == -1) {\n"
2206 " fprintf(stderr, \"Cannot watch \\[aq]%s\\[aq]: %s\\[rs]n\",\n"
2207 " argv[i], strerror(errno));\n"
2208 " exit(EXIT_FAILURE);\n"
2209 " }\n"
2210 " }\n"
2211 "\\&\n"
2212 " /* Prepare for polling. */\n"
2213 "\\&\n"
2214 " nfds = 2;\n"
2215 "\\&\n"
2216 " fds[0].fd = STDIN_FILENO; /* Console input */\n"
2217 " fds[0].events = POLLIN;\n"
2218 "\\&\n"
2219 " fds[1].fd = fd; /* Inotify input */\n"
2220 " fds[1].events = POLLIN;\n"
2221 "\\&\n"
2222 " /* Wait for events and/or terminal input. */\n"
2223 "\\&\n"
2224 " printf(\"Listening for events.\\[rs]n\");\n"
2225 " while (1) {\n"
2226 " poll_num = poll(fds, nfds, -1);\n"
2227 " if (poll_num == -1) {\n"
2228 " if (errno == EINTR)\n"
2229 " continue;\n"
2230 " perror(\"poll\");\n"
2231 " exit(EXIT_FAILURE);\n"
2232 " }\n"
2233 "\\&\n"
2234 " if (poll_num E<gt> 0) {\n"
2235 "\\&\n"
2236 " if (fds[0].revents & POLLIN) {\n"
2237 "\\&\n"
2238 " /* Console input is available. Empty stdin and quit. */\n"
2239 "\\&\n"
2240 " while (read(STDIN_FILENO, &buf, 1) E<gt> 0 && buf != \\[aq]\\[rs]n\\[aq])\n"
2241 " continue;\n"
2242 " break;\n"
2243 " }\n"
2244 "\\&\n"
2245 " if (fds[1].revents & POLLIN) {\n"
2246 "\\&\n"
2247 " /* Inotify events are available. */\n"
2248 "\\&\n"
2249 " handle_events(fd, wd, argc, argv);\n"
2250 " }\n"
2251 " }\n"
2252 " }\n"
2253 "\\&\n"
2254 " printf(\"Listening for events stopped.\\[rs]n\");\n"
2255 "\\&\n"
2256 " /* Close inotify file descriptor. */\n"
2257 "\\&\n"
2258 " close(fd);\n"
2259 "\\&\n"
2260 " free(wd);\n"
2261 " exit(EXIT_SUCCESS);\n"
2262 "}\n"
2263 msgstr ""
2264
2265 #. type: TH
2266 #: opensuse-leap-16-1 opensuse-tumbleweed
2267 #, no-wrap
2268 msgid "Linux man-pages (unreleased)"
2269 msgstr ""