On Wed, Oct 02, 2019 at 06:07:39PM +0100, Steve Hay wrote:
>
> I'm not sure about this area, but if it works for with your patch then
> it's probably an improvement :-)
>
> Just out of interest, does the following alternative patch work?
>
> Index: lib/Apache2/Resource.pm
> ===================================================================
> --- lib/Apache2/Resource.pm (revision 1866274)
> +++ lib/Apache2/Resource.pm (working copy)
> @@ -115,8 +115,7 @@
> "</tr>");
>
> for my $res (keys %$lim) {
> - my $val = eval "&BSD::Resource::${res}()";
> - my ($soft, $hard) = getrlimit $val;
> + my ($soft, $hard) = getrlimit($lim->{$res});
> (my $limit = $res) =~ s/^RLIMIT_//;
> ($soft, $hard) = ("$soft " . BM($soft), "$hard ". BM($hard))
> if $is_mb{$limit};
Yes, that works just as well for me.
> This avoids making the &BSD::Resource::${res}() calls, which are what
> is returning undef for you in some cases. Or does this fail just the
> same because some of the values of %$lim are also undef anyway?
The %$lim values are not undef. See the attached stand-alone test and
output for the problematic values which I see and which also shows that
the limits for those resources are still retrievable via getrlimit().
HTH,
Pete
--
Openstrike - improving business through open source
https://www.openstrike.co.uk/ or call 01722 770036
use strict;
use warnings;
use Test::More;
use BSD::Resource qw/getrlimit get_rlimits/;
my $lim = get_rlimits ();
ok defined $lim, "get_rlimits returns defined value";
ok ref $lim, "get_rlimits returns reference";
is ref $lim, 'HASH', "get_rlimits returns hash reference";
for my $res (keys %$lim) {
my $subval = eval "&BSD::Resource::${res}()";
ok defined $subval, "BSD::Resource::${res}() gives defined result";
is $subval, $lim->{$res}, 'Sub from resource matches hash value';
my ($soft, $hard) = getrlimit $lim->{$res};
ok defined $soft, "$res has soft limit $soft";
ok defined $hard, "$res has hard limit $hard";
}
done_testing (3 + 4 * keys %$lim);
ok 1 - get_rlimits returns defined value ok 2 - get_rlimits returns reference ok 3 - get_rlimits returns hash reference ok 4 - BSD::Resource::RLIMIT_STACK() gives defined result ok 5 - Sub from resource matches hash value ok 6 - RLIMIT_STACK has soft limit 8388608 ok 7 - RLIMIT_STACK has hard limit -1 ok 8 - BSD::Resource::RLIMIT_LOCKS() gives defined result ok 9 - Sub from resource matches hash value ok 10 - RLIMIT_LOCKS has soft limit -1 ok 11 - RLIMIT_LOCKS has hard limit -1 ok 12 - BSD::Resource::RLIMIT_CORE() gives defined result ok 13 - Sub from resource matches hash value ok 14 - RLIMIT_CORE has soft limit 0 ok 15 - RLIMIT_CORE has hard limit -1 ok 16 - BSD::Resource::RLIMIT_DATA() gives defined result ok 17 - Sub from resource matches hash value ok 18 - RLIMIT_DATA has soft limit -1 ok 19 - RLIMIT_DATA has hard limit -1 ok 20 - BSD::Resource::RLIMIT_AS() gives defined result ok 21 - Sub from resource matches hash value ok 22 - RLIMIT_AS has soft limit -1 ok 23 - RLIMIT_AS has hard limit -1 ok 24 - BSD::Resource::RLIMIT_CPU() gives defined result ok 25 - Sub from resource matches hash value ok 26 - RLIMIT_CPU has soft limit -1 ok 27 - RLIMIT_CPU has hard limit -1 ok 28 - BSD::Resource::RLIMIT_MEMLOCK() gives defined result ok 29 - Sub from resource matches hash value ok 30 - RLIMIT_MEMLOCK has soft limit 65536 ok 31 - RLIMIT_MEMLOCK has hard limit 65536 ok 32 - BSD::Resource::RLIMIT_OFILE() gives defined result ok 33 - Sub from resource matches hash value ok 34 - RLIMIT_OFILE has soft limit 1024 ok 35 - RLIMIT_OFILE has hard limit 4096 ok 36 - BSD::Resource::RLIMIT_FSIZE() gives defined result ok 37 - Sub from resource matches hash value ok 38 - RLIMIT_FSIZE has soft limit -1 ok 39 - RLIMIT_FSIZE has hard limit -1 ok 40 - BSD::Resource::RLIMIT_OPEN_MAX() gives defined result ok 41 - Sub from resource matches hash value ok 42 - RLIMIT_OPEN_MAX has soft limit 1024 ok 43 - RLIMIT_OPEN_MAX has hard limit 4096 ok 44 - BSD::Resource::RLIMIT_NPROC() gives defined result ok 45 - Sub from resource matches hash value ok 46 - RLIMIT_NPROC has soft limit 4096 ok 47 - RLIMIT_NPROC has hard limit 30837 not ok 48 - BSD::Resource::RLIMIT_MSGQUEUE() gives defined result # Failed test 'BSD::Resource::RLIMIT_MSGQUEUE() gives defined result' # at getrlimit.t line 14. not ok 49 - Sub from resource matches hash value # Failed test 'Sub from resource matches hash value' # at getrlimit.t line 15. # got: undef # expected: '12' ok 50 - RLIMIT_MSGQUEUE has soft limit 819200 ok 51 - RLIMIT_MSGQUEUE has hard limit 819200 ok 52 - BSD::Resource::RLIMIT_NOFILE() gives defined result ok 53 - Sub from resource matches hash value ok 54 - RLIMIT_NOFILE has soft limit 1024 ok 55 - RLIMIT_NOFILE has hard limit 4096 not ok 56 - BSD::Resource::RLIMIT_NICE() gives defined result # Failed test 'BSD::Resource::RLIMIT_NICE() gives defined result' # at getrlimit.t line 14. not ok 57 - Sub from resource matches hash value # Failed test 'Sub from resource matches hash value' # at getrlimit.t line 15. # got: undef # expected: '13' ok 58 - RLIMIT_NICE has soft limit 0 ok 59 - RLIMIT_NICE has hard limit 0 ok 60 - BSD::Resource::RLIMIT_VMEM() gives defined result ok 61 - Sub from resource matches hash value ok 62 - RLIMIT_VMEM has soft limit -1 ok 63 - RLIMIT_VMEM has hard limit -1 not ok 64 - BSD::Resource::RLIMIT_SIGPENDING() gives defined result # Failed test 'BSD::Resource::RLIMIT_SIGPENDING() gives defined result' # at getrlimit.t line 14. not ok 65 - Sub from resource matches hash value # Failed test 'Sub from resource matches hash value' # at getrlimit.t line 15. # got: undef # expected: '11' ok 66 - RLIMIT_SIGPENDING has soft limit 30837 ok 67 - RLIMIT_SIGPENDING has hard limit 30837 not ok 68 - BSD::Resource::RLIMIT_RTTIME() gives defined result # Failed test 'BSD::Resource::RLIMIT_RTTIME() gives defined result' # at getrlimit.t line 14. not ok 69 - Sub from resource matches hash value # Failed test 'Sub from resource matches hash value' # at getrlimit.t line 15. # got: undef # expected: '15' ok 70 - RLIMIT_RTTIME has soft limit -1 ok 71 - RLIMIT_RTTIME has hard limit -1 not ok 72 - BSD::Resource::RLIMIT_RTPRIO() gives defined result # Failed test 'BSD::Resource::RLIMIT_RTPRIO() gives defined result' # at getrlimit.t line 14. not ok 73 - Sub from resource matches hash value # Failed test 'Sub from resource matches hash value' # at getrlimit.t line 15. # got: undef # expected: '14' ok 74 - RLIMIT_RTPRIO has soft limit 0 ok 75 - RLIMIT_RTPRIO has hard limit 0 ok 76 - BSD::Resource::RLIMIT_RSS() gives defined result ok 77 - Sub from resource matches hash value ok 78 - RLIMIT_RSS has soft limit -1 ok 79 - RLIMIT_RSS has hard limit -1 1..79 # Looks like you failed 10 tests of 79.
pgpXlvLf7lbcW.pgp
Description: PGP signature
