1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| | # Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# wrap Linux::Inotify2 XS module, support pure Perl via `syscall' someday
package PublicInbox::Inotify;
use v5.12;
our @ISA;
BEGIN { # prefer pure Perl since it works out-of-the-box
my $isa;
for my $m (qw(PublicInbox::Inotify3 Linux::Inotify2)) {
eval "require $m";
next if $@;
$isa = $m;
}
if ($isa) {
push @ISA, $isa;
my $buf = '';
for (qw(IN_MOVED_TO IN_CREATE IN_DELETE IN_DELETE_SELF
IN_MOVE_SELF IN_MOVED_FROM IN_MODIFY)) {
$buf .= "*$_ = \\&PublicInbox::Inotify3::$_;\n";
}
eval $buf;
die $@ if $@;
} else {
die <<EOM;
W: inotify syscall numbers unknown on your platform and
W: Linux::Inotify2 missing: $@
W: public-inbox hackers welcome the plain-text output of ./devel/sysdefs-list
W: at meta\@public-inbox.org
EOM
}
};
sub new {
$_[0]->SUPER::new // do {
my $msg = $!{EMFILE} ? <<EOM : "$_[0]->new: $!\n";
inotify_init/inotify_init1: $!
You may need to raise the `fs.inotify.max_user_instances' sysctl limit.
Consult your OS documentation and/or sysctl(8) + sysctl.conf(5) manpages.
EOM
$msg =~ s/^/E: /smg;
require Carp;
Carp::croak($msg);
}
}
1;
|