| 1 |
#!/opt/bin/perl |
| 2 |
|
| 3 |
# exmaple for Event integration |
| 4 |
|
| 5 |
use Event; |
| 6 |
use Linux::Inotify2; |
| 7 |
|
| 8 |
my $inotify = new Linux::Inotify2; |
| 9 |
|
| 10 |
Event->io (fd => $inotify->fileno, prot => 'r', cb => sub { $inotify->poll }); |
| 11 |
|
| 12 |
$inotify->watch ("/etc/passwd", IN_ACCESS | IN_MODIFY, sub { |
| 13 |
my $e = shift; |
| 14 |
printf "events for <%s> received: %s\n", $e->fullname, $e->mask; |
| 15 |
print "$e->{w}{name} was accessed\n" if $e->IN_ACCESS; |
| 16 |
print "$e->{w}{name} was modified\n" if $e->IN_MODIFY; |
| 17 |
print "$e->{w}{name} is no longer mounted\n" if $e->IN_UNMOUNT; |
| 18 |
print "events for $e->{w}{name} have been lost\n" if $e->IN_Q_OVERFLOW; |
| 19 |
|
| 20 |
Event::unloop; |
| 21 |
}); |
| 22 |
|
| 23 |
Event::loop; |
| 24 |
|