Match/KernProc.pm

filter: Statementstmt 89.4% 34 / 38 Branchbran 66.6% 8 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 85.0% 57 / 67 CC 9 SCAR 19.6
CC
9
Cov
84%
match
9.8
BEGIN
1.0
BEGIN
1.0
CRAP 7.1
« Match/Command.pm ↑ Summary Match/Idle.pm »
1 package Proc::ProcessTable::Match::KernProc;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Proc::ProcessTable::Match::KernProc - Attempts to match the kernel processes.
10  
11 =head1 VERSION
12  
13 Version 0.1.0
14  
15 =cut
16  
17 2 our $VERSION = '0.1.0';
18  
19 =head1 SYNOPSIS
20  
21 use Proc::ProcessTable::Match::KernProc;
22
23 my $checker=Proc::ProcessTable::Match::KernProc->new;
24
25 if ( $checker->match( $proc ) ){
26 print "It matches.\n";
27 }
28  
29 This modules functions via looking for processes matching the following.
30  
31 UID == 0
32 fname present
33 cmndline =~ /^$/
34  
35 =head1 METHODS
36  
37 =head2 new
38  
39 This intiates the object.
40  
41 my $checker=Proc::ProcessTable::Match::KernProc->new;
42  
43 =cut
44  
45 1 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
46 1 my $class=$_[0];
47 1 my $self = {
48 };
49 1 bless $self, $class;
50  
51 1 return $self;
52 }
53  
54 =head2 match
55  
56 Checks if a single Proc::ProcessTable::Process object matches the stack.
57  
58 One argument is taken and that is a Proc::ProcessTable::Process object.
59  
60 The returned value is a boolean.
61  
62 if ( $checker->match( $proc ) ){
63 print "The process matches.\n";
64 }
65  
66 =cut
67  
68 5 ▶sub match{
Subroutine match: called CC=9 SCAR=22.8
Pod documented
69 5 my $self=$_[0];
70 5 my $object=$_[1];
71  
72 5 ▶ if ( !defined( $object ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 5 5
73 0 return 0;
74 }
75  
76 5 ▶ if ( ref( $object ) ne 'Proc::ProcessTable::Process' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object ne "Proc::ProcessTable::Process") 0 5 5
77 0 return 0;
78 }
79  
80 # a zombie also has a blank cmndline, but is not a kernel proc
81 # "zombie" is used by the BSDs and "defunct" by Linux
82 5 my $proc_state;
83 5 eval{
84 5 $proc_state=$object->state;
85 };
86 5 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proc_state and $proc_state =~ /^(zombie|defunct)$/) 2 3 5
Condition66%2/3
defined $proc_state and $proc_state =~ /^(zombie|defunct)$/
!ll&&!rl&&r
032
MC/DC50%1/2
defined $proc_state and $proc_state =~ /^(zombie|defunct)$/
defined $proc_state $proc_state =~ /^(zombie|defunct)$/
Truth table66%2/3
A and B
A= defined $proc_stateB= $proc_state =~ /^(zombie|defunct)$/
ABresult
0X0
100
111
87 ( defined( $proc_state ) ) &&
88 ( $proc_state =~ /^(zombie|defunct)$/ )
89 ){
90 2 return 0;
91 }
92  
93 3 my $proc_uid;
94 3 eval{
95 3 $proc_uid=$object->uid;
96 };
97  
98 # don't bother proceeding, the object won't match ever
99 # as it does not have a uid
100 3 ▶ if ( ! defined( $proc_uid ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_uid) 0 3 3
101 0 return 0;
102 }
103  
104 3 my $proc_cmd;
105 3 eval{
106 3 $proc_cmd=$object->cmndline;
107 };
108  
109 # don't bother proceeding, the object won't match ever
110 # as it does not have a cmndline
111 3 ▶ if ( ! defined( $proc_cmd ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_cmd) 0 3 3
112 0 return 0;
113 }
114  
115 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_uid == 0 and $proc_cmd =~ /^$/) 1 2 3
Condition100%3/3
$proc_uid == 0 and $proc_cmd =~ /^$/
!ll&&!rl&&r
111
MC/DC100%2/2
$proc_uid == 0 and $proc_cmd =~ /^$/
$proc_uid == 0 $proc_cmd =~ /^$/
Truth table100%3/3
A and B
A= $proc_uid == 0B= $proc_cmd =~ /^$/
ABresult
0X0
100
111
116 ( $proc_uid == 0 ) &&
117 ( $proc_cmd =~ /^$/ )
118 ){
119 1 return 1;
120 }
121  
122 2 return 0;
123 }
124  
125 =head1 AUTHOR
126  
127 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
128  
129 =head1 BUGS
130  
131 Please report any bugs or feature requests to C<bug-Proc-ProcessTable-Match at rt.cpan.org>, or through
132 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-ProcessTable-Match>. I will be notified, and then you'll
133 automatically be notified of progress on your bug as I make changes.
134  
135  
136  
137  
138 =head1 SUPPORT
139  
140 You can find documentation for this module with the perldoc command.
141  
142 perldoc Proc::ProcessTable::Match
143  
144  
145 You can also look for information at:
146  
147 =over 4
148  
149 =item * RT: CPAN's request tracker (report bugs here)
150  
151 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Proc-ProcessTable-Match>
152  
153 =item * Search CPAN
154  
155 L<https://metacpan.org/release/Proc-ProcessTable-Match>
156  
157 =back
158  
159  
160 =head1 ACKNOWLEDGEMENTS
161  
162  
163 =head1 LICENSE AND COPYRIGHT
164  
165 Copyright 2019 Zane C. Bowers-Hadley.
166  
167 This program is free software; you can redistribute it and/or modify it
168 under the terms of the the Artistic License (2.0). You may obtain a
169 copy of the full license at:
170  
171 L<http://www.perlfoundation.org/artistic_license_2_0>
172  
173 Any use, modification, and distribution of the Standard or Modified
174 Versions is governed by this Artistic License. By using, modifying or
175 distributing the Package, you accept this license. Do not use, modify,
176 or distribute the Package, if you do not accept this license.
177  
178 If your Modified Version has been derived from a Modified Version made
179 by someone other than you, you are nevertheless required to ensure that
180 your Modified Version complies with the requirements of this license.
181  
182 This license does not grant you the right to use any trademark, service
183 mark, tradename, or logo of the Copyright Holder.
184  
185 This license includes the non-exclusive, worldwide, free-of-charge
186 patent license to make, have made, use, offer to sell, sell, import and
187 otherwise transfer the Package with respect to any patent claims
188 licensable by the Copyright Holder that are necessarily infringed by the
189 Package. If you institute patent litigation (including a cross-claim or
190 counterclaim) against any party alleging that the Package constitutes
191 direct or contributory patent infringement, then this Artistic License
192 to you shall terminate on the date that such litigation is filed.
193  
194 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
195 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
196 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
197 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
198 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
199 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
200 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
201 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
202  
203  
204 =cut
205  
206 2 1; # End of Proc::ProcessTable::Match
« Match/Command.pm ↑ Summary Match/Idle.pm »