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