1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # Licensed the same as Danga::Socket (and Perl5)
3 # License: GPL-1.0+ or Artistic-1.0-Perl
4 # <https://www.gnu.org/licenses/gpl-1.0.txt>
5 # <https://dev.perl.org/licenses/artistic.html>
6 use v5.12; use PublicInbox::TestCommon;
7 use_ok 'PublicInbox::DS';
9 if ('close-on-exec for epoll and kqueue') {
10 use PublicInbox::Spawn qw(spawn);
12 my $evfd_re = qr/(?:kqueue|eventpoll)/i;
14 $PublicInbox::DS::loop_timeout = 0;
15 local @PublicInbox::DS::post_loop_do = (sub { 0 });
17 # make sure execve closes if we're using fork()
19 pipe($r, $w) or die "pipe: $!";
21 PublicInbox::DS::add_timer(0, sub { $pid = spawn([qw(sleep 10)]) });
22 PublicInbox::DS::event_loop();
23 ok($pid, 'subprocess spawned');
25 # wait for execve, we need to ensure lsof sees sleep(1)
26 # and not the fork of this process:
27 close $w or die "close: $!";
29 is($l, undef, 'cloexec works and sleep(1) is running');
32 my $rdr = { 2 => \(my $null) };
33 my @of = grep /$evfd_re/, lsof_pid $pid, $rdr;
34 is_deeply(\@of, [], 'no FDs leaked to subprocess');
40 PublicInbox::DS->Reset;
44 require_mods('BSD::Resource', 1);
45 my $rlim = BSD::Resource::RLIMIT_NOFILE();
46 my ($n,undef) = BSD::Resource::getrlimit($rlim);
48 # FreeBSD 11.2 with 2GB RAM gives RLIMIT_NOFILE=57987!
49 if ($n > 1024 && !$ENV{TEST_EXPENSIVE}) {
50 skip "RLIMIT_NOFILE=$n too big w/o TEST_EXPENSIVE for $0", 1;
54 $PublicInbox::DS::loop_timeout = 0;
55 local @PublicInbox::DS::post_loop_do = ($cb);
56 PublicInbox::DS::event_loop();
57 PublicInbox::DS->Reset;
59 ok(1, "Reset works and doesn't hit RLIMIT_NOFILE ($n)");