1 | NAME |
1 | NAME |
2 | Linux::Inotify2 - scalable directory/file change notification |
2 | Linux::Inotify2 - scalable directory/file change notification |
3 | |
3 | |
4 | SYNOPSIS |
4 | SYNOPSIS |
|
|
5 | Callback interface |
5 | use Linux::Inotify2; |
6 | use Linux::Inotify2; |
6 | |
7 | |
7 | # create a new object |
8 | # create a new object |
8 | my $inotify = new Linux::Inotify2 |
9 | my $inotify = new Linux::Inotify2 |
9 | or die "Unable to create new inotify object: $!"; |
10 | or die "Unable to create new inotify object: $!"; |
… | |
… | |
22 | print "$name was accessed\n" if $e->IN_ACCESS; |
23 | print "$name was accessed\n" if $e->IN_ACCESS; |
23 | print "$name is no longer mounted\n" if $e->IN_UNMOUNT; |
24 | print "$name is no longer mounted\n" if $e->IN_UNMOUNT; |
24 | print "$name is gone\n" if $e->IN_IGNORED; |
25 | print "$name is gone\n" if $e->IN_IGNORED; |
25 | print "events for $name have been lost\n" if $e->IN_Q_OVERFLOW; |
26 | print "events for $name have been lost\n" if $e->IN_Q_OVERFLOW; |
26 | |
27 | |
27 | # cancel this watcheR: remove no further events |
28 | # cancel this watcher: remove no further events |
28 | $e->w->cancel; |
29 | $e->w->cancel; |
29 | }); |
30 | }); |
|
|
31 | |
|
|
32 | Streaming Interface |
|
|
33 | use Linux::Inotify2 ; |
|
|
34 | |
|
|
35 | # create a new object |
|
|
36 | my $inotify = new Linux::Inotify2 |
|
|
37 | or die "Unable to create new inotify object: $!" ; |
|
|
38 | |
|
|
39 | # create watch |
|
|
40 | $inotify->watch ("/etc/passwd", IN_ACCESS) |
|
|
41 | or die "watch creation failed" ; |
|
|
42 | |
|
|
43 | while () { |
|
|
44 | my @events = $inotify->read; |
|
|
45 | unless (@events > 0) { |
|
|
46 | print "read error: $!"; |
|
|
47 | last ; |
|
|
48 | } |
|
|
49 | printf "mask\t%d\n", $_->mask foreach @events ; |
|
|
50 | } |
30 | |
51 | |
31 | DESCRIPTION |
52 | DESCRIPTION |
32 | This module implements an interface to the Linux 2.6.13 and later |
53 | This module implements an interface to the Linux 2.6.13 and later |
33 | Inotify file/directory change notification sytem. |
54 | Inotify file/directory change notification sytem. |
34 | |
55 | |
… | |
… | |
56 | Example: |
77 | Example: |
57 | |
78 | |
58 | my $inotify = new Linux::Inotify2 |
79 | my $inotify = new Linux::Inotify2 |
59 | or die "Unable to create new inotify object: $!"; |
80 | or die "Unable to create new inotify object: $!"; |
60 | |
81 | |
61 | $watch = $inotify->watch ($name, $mask, $cb) |
82 | $watch = $inotify->watch ($name, $mask[, $cb]) |
62 | Add a new watcher to the given notifier. The watcher will create |
83 | Add a new watcher to the given notifier. The watcher will create |
63 | events on the pathname $name as given in $mask, which can be any of |
84 | events on the pathname $name as given in $mask, which can be any of |
64 | the following constants (all exported by default) ORed together. |
85 | the following constants (all exported by default) ORed together. |
65 | |
86 | |
66 | "file" refers to any filesystem object in the watch'ed object |
87 | "file" refers to any filesystem object in the watch'ed object |
… | |
… | |
85 | IN_ONESHOT only send event once |
106 | IN_ONESHOT only send event once |
86 | |
107 | |
87 | IN_CLOSE same as IN_CLOSE_WRITE | IN_CLOSE_NOWRITE |
108 | IN_CLOSE same as IN_CLOSE_WRITE | IN_CLOSE_NOWRITE |
88 | IN_MOVE same as IN_MOVED_FROM | IN_MOVED_TO |
109 | IN_MOVE same as IN_MOVED_FROM | IN_MOVED_TO |
89 | |
110 | |
90 | $cb is a perl code reference that is called for each event. It |
111 | $cb is a perl code reference that, if given, is called for each |
91 | receives a "Linux::Inotify2::Event" object. |
112 | event. It receives a "Linux::Inotify2::Event" object. |
92 | |
113 | |
93 | The returned $watch object is of class "Linux::Inotify2::Watch". |
114 | The returned $watch object is of class "Linux::Inotify2::Watch". |
94 | |
115 | |
95 | On error, "undef" is returned and $! will be set accordingly. The |
116 | On error, "undef" is returned and $! will be set accordingly. The |
96 | following errors are documented: |
117 | following errors are documented: |
… | |
… | |
116 | $inotify->fileno |
137 | $inotify->fileno |
117 | Returns the fileno for this notify object. You are responsible for |
138 | Returns the fileno for this notify object. You are responsible for |
118 | calling the "poll" method when this fileno becomes ready for |
139 | calling the "poll" method when this fileno becomes ready for |
119 | reading. |
140 | reading. |
120 | |
141 | |
|
|
142 | $inotify->blocking ($blocking) |
|
|
143 | Clears ($blocking true) or sets ($blocking false) the "O_NONBLOCK" |
|
|
144 | flag on the file descriptor. |
|
|
145 | |
121 | $count = $inotify->poll |
146 | $count = $inotify->poll |
122 | Reads events from the kernel and handles them. If the notify fileno |
147 | Reads events from the kernel and handles them. If the notify fileno |
123 | is blocking (the default), then this method waits for at least one |
148 | is blocking (the default), then this method waits for at least one |
124 | event (and thus returns true unless an error occurs). Otherwise it |
149 | event (and thus returns true unless an error occurs). Otherwise it |
125 | returns immediately when no pending events could be read. |
150 | returns immediately when no pending events could be read. |
126 | |
151 | |
127 | Returns the count of events that have been handled. |
152 | Returns the count of events that have been handled. |
|
|
153 | |
|
|
154 | $count = $inotify->read |
|
|
155 | Reads events from the kernel. Blocks in blocking mode (default) |
|
|
156 | until any event arrives. Returns list of "Linux::Inotify2::Event" |
|
|
157 | objects or empty list if none (non-blocking mode) or error occured |
|
|
158 | ($! should be checked). |
128 | |
159 | |
129 | The Linux::Inotify2::Event Class |
160 | The Linux::Inotify2::Event Class |
130 | Objects of this class are handed as first argument to the watch |
161 | Objects of this class are handed as first argument to the watch |
131 | callback. It has the following members and methods: |
162 | callback. It has the following members and methods: |
132 | |
163 | |