user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
9673b44290a991ea1853c8642c10c326c5dd779e blob 2443 bytes (raw)

 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
# Copyright (C) 2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# implements the small subset of Linux::Inotify2 functionality we use
# using IO::KQueue on *BSD systems.
package PublicInbox::KQNotify;
use strict;
use IO::KQueue;
use PublicInbox::DSKQXS; # wraps IO::KQueue for fork-safe DESTROY
use PublicInbox::FakeInotify;
use Time::HiRes qw(stat);

# NOTE_EXTEND detects rename(2), NOTE_WRITE detects link(2)
sub MOVED_TO_OR_CREATE () { NOTE_EXTEND|NOTE_WRITE }

sub new {
	my ($class) = @_;
	bless { dskq => PublicInbox::DSKQXS->new, watch => {} }, $class;
}

sub watch {
	my ($self, $path, $mask, $cb) = @_;
	my ($fh, $cls, @extra);
	if (-d $path) {
		opendir($fh, $path) or return;
		my @st = stat($fh);
		@extra = ($path, $st[10]); # 10: ctime
		$cls = 'PublicInbox::KQNotify::Watchdir';
	} else {
		open($fh, '<', $path) or return;
		$cls = 'PublicInbox::KQNotify::Watch';
	}
	my $ident = fileno($fh);
	$self->{dskq}->{kq}->EV_SET($ident, # ident
		EVFILT_VNODE, # filter
		EV_ADD | EV_CLEAR, # flags
		$mask, # fflags
		0, 0); # data, udata
	if ($mask == NOTE_WRITE || $mask == MOVED_TO_OR_CREATE) {
		$self->{watch}->{$ident} = [ $fh, $cb, @extra ];
	} else {
		die "TODO Not implemented: $mask";
	}
	bless \$fh, $cls;
}

# emulate Linux::Inotify::fileno
sub fileno { ${$_[0]->{dskq}->{kq}} }

# noop for Linux::Inotify2 compatibility.  Unlike inotify,
# kqueue doesn't seem to overflow since it's limited by the number of
# open FDs the process has
sub on_overflow {}

# noop for Linux::Inotify2 compatibility, we use `0' timeout for ->kevent
sub blocking {}

# behave like Linux::Inotify2::poll
sub poll {
	my ($self) = @_;
	my @kevents = $self->{dskq}->{kq}->kevent(0);
	for my $kev (@kevents) {
		my $ident = $kev->[KQ_IDENT];
		my $mask = $kev->[KQ_FFLAGS];
		my ($dh, $cb, $path, $old_ctime) = @{$self->{watch}->{$ident}};
		if (!defined($path) && ($mask & NOTE_WRITE) == NOTE_WRITE) {
			eval { $cb->() };
		} elsif ($mask & MOVED_TO_OR_CREATE) {
			my @new_st = stat($path) or next;
			$self->{watch}->{$ident}->[3] = $new_st[10]; # ctime
			rewinddir($dh);
			PublicInbox::FakeInotify::on_new_files($dh, $cb,
							$path, $old_ctime);
		}
	}
}

package PublicInbox::KQNotify::Watch;
use strict;

sub cancel { close ${$_[0]} or die "close: $!" }

package PublicInbox::KQNotify::Watchdir;
use strict;

sub cancel { closedir ${$_[0]} or die "closedir: $!" }

1;
debug log:

solving 9673b44290a ...
found 9673b44290a in public-inbox.git

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git