CfgTie/TieRsrc.pm

filter: Statementstmt 38.4% 5 / 13 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 1 / 4 Podpod n/a totaltotal 33.3% 7 / 21 CC 2 SCAR 12.3
CC
2
Cov
35%
TIEHASH
6.0
FETCH
2.0
STORE
2.0
CRAP 3.4
« CfgTie/TieProto.pm ↑ Summary CfgTie/TieRealm.pm »
1 #!/usr/bin/perl -Tw
2 #Copyright 1998-2001, Randall Maas. All rights reserved. This program is free
3 #software; you can redistribute it and/or modify it under the same terms as
4 #PERL itself.
5  
6 package CfgTie::TieRsrc;
7  
8 =head1 NAME
9  
10 CfgTie::TieRsrc -- an associative array of resources and their usage limits
11  
12 =head1 SYNOPSIS
13  
14 This module makes the resource limits available as a regular hash
15  
16 tie %Resources,'CfgTie::TieRsrc'
17  
18 =head1 DESCRIPTION
19  
20 This is a straightforward hash tie that allows us to access the user database
21 sanely.
22  
23 The resource limits for the system.
24 Note: this requires that C<BSD::Resource> be installed.
25  
26 It is a hash reference. The keys may be any of C<cpu>, C<data>, C<stack>,
27 C<core>, C<rss>, C<memlock>, C<nproc>, C<nofile>, C<open_max>, C<as>, C<vmem>,
28 C<nlimits>, C<infinity>. The values are always list references of the form:
29  
30 [$soft, $hard]
31  
32 =head1 See Also
33  
34 L<CfgTie::Cfgfile>, L<CfgTie::TieAliases>, L<CfgTie::TieGeneric>,
35 L<CfgTie::TieGroup>,L<CfgTie::TieHost>, L<CfgTie::TieMTab>,
36 L<CfgTie::TieNamed>,L<CfgTie::TieNet>, L<CfgTie::TiePh>,
37 L<CfgTie::TieProto>,L<CfgTie::TieRCService>,L<CfgTie::TieServ>,
38 L<CfgTie::TieShadow>
39  
40 =head1 Author
41  
42 Randall Maas (L<mailto:randym@acm.org>, L<http://www.hamline.edu/~rcmaas/>)
43  
44 =cut
45  
46 1 my $Ok=0;
47 0 ▶if (eval("use BSD::Resource;")) {$Ok=1;}
Subroutine BEGIN: called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
if (eval "use BSD::Resource;") 0 1 1
48  
49 1 my $K=
50 {
51 cpu =>RLIMIT_CPU,
52 fsize=>RLIMIT_FSIZE,
53 data =>RLIMIT_DATA,
54 stack=>RLIMIT_STACK,
55 core =>RLIMIT_CORE,
56 rss =>RLIMIT_RSS,
57 memlock=>RLIMIT_MEMLOCK,
58 nproc =>RLIMIT_NPROC,
59 nofile =>RLIMIT_NOFILE,
60 open_max=>RLIMIT_OPEN_MAX,
61 as =>RLIMIT_AS,
62 vmem =>RLIMIT_VMEM,
63 nlimits =>RLIMIT_NLIMITS,
64 infinity=>RLIMIT_INFINITY,
65 };
66 1 1;
67  
68 sub TIEHASH
69 0 ▶{
Subroutine TIEHASH: not called CC=2 SCAR=17.9
70 0 ▶ if (!$Ok) {return undef;}
Branch: 1 branch
BranchTrueFalseTotal
unless ($Ok) 0 0 0
71 0 return bless {}, $_[0];
72 }
73  
74 sub FETCH
75 0 ▶{
Subroutine FETCH: not called CC=1 SCAR=6.9
76 #Get the limits setting from the system
77 0 getrlimits($_[0]->{id},$->{$_[1]});
78 }
79  
80 sub STORE
81 0 ▶{
Subroutine STORE: not called CC=1 SCAR=6.9
82 #Pass the rlimits setting onto the system
83 0 setrlimits($K->{$_[1]}, $_[2]->[0],$_[2]->[1]);
84 }
« CfgTie/TieProto.pm ↑ Summary CfgTie/TieRealm.pm »