| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tapper::Base; |
|
2
|
|
|
|
|
|
|
# git description: v4.1.1-1-g1855edc |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { |
|
5
|
2
|
|
|
2
|
|
724151
|
$Tapper::Base::AUTHORITY = 'cpan:AMD'; |
|
6
|
|
|
|
|
|
|
} |
|
7
|
|
|
|
|
|
|
{ |
|
8
|
|
|
|
|
|
|
$Tapper::Base::VERSION = '4.1.4'; |
|
9
|
|
|
|
|
|
|
} |
|
10
|
|
|
|
|
|
|
# ABSTRACT: Tapper - Common functions for all Tapper classes |
|
11
|
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
3927
|
use Moose; |
|
|
2
|
|
|
|
|
1085331
|
|
|
|
2
|
|
|
|
|
17
|
|
|
13
|
2
|
|
|
2
|
|
26745
|
use Fcntl; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
748
|
|
|
14
|
2
|
|
|
2
|
|
17546
|
use LockFile::Simple; |
|
|
2
|
|
|
|
|
62312
|
|
|
|
2
|
|
|
|
|
151
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
4146
|
use common::sense; |
|
|
2
|
|
|
|
|
22
|
|
|
|
2
|
|
|
|
|
13
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
183
|
use 5.010; |
|
|
2
|
|
|
|
|
9
|
|
|
|
2
|
|
|
|
|
4958
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
with 'MooseX::Log::Log4perl'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub kill_instance |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
0
|
|
|
0
|
|
|
my ($self, $pid_file) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# try to kill previous incarnations |
|
28
|
0
|
0
|
0
|
|
|
|
if ((-e $pid_file) and open(my $fh, "<", $pid_file)) {{ |
|
|
0
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $pid = do {local $\; <$fh>}; # slurp |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
($pid) = $pid =~ m/(\d+)/; |
|
31
|
0
|
0
|
|
|
|
|
last unless $pid; |
|
32
|
0
|
|
|
|
|
|
kill 15, $pid; |
|
33
|
0
|
|
|
|
|
|
sleep(2); |
|
34
|
0
|
|
|
|
|
|
kill 9, $pid; |
|
35
|
0
|
|
|
|
|
|
close $fh; |
|
36
|
|
|
|
|
|
|
}} |
|
37
|
0
|
|
|
|
|
|
return 0; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub run_one |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
0
|
|
|
0
|
|
|
my ($self, $conf) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $command = $conf->{command}; |
|
47
|
0
|
|
|
|
|
|
my $pid_file = $conf->{pid_file}; |
|
48
|
0
|
|
0
|
|
|
|
my @argv = @{$conf->{argv} // [] } ; |
|
|
0
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->kill_instance($pid_file); |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
return qq(Can not execute "$command" because it's not an executable) unless -x $command; |
|
53
|
0
|
|
|
|
|
|
my $pid = fork(); |
|
54
|
0
|
0
|
|
|
|
|
return qq(Can not execute "$command". Fork failed: $!) unless defined $pid; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ($pid == 0) { |
|
57
|
0
|
|
|
|
|
|
exec $command, @argv; |
|
58
|
0
|
|
|
|
|
|
exit 0; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
return 0 unless $pid_file; |
|
62
|
0
|
0
|
|
|
|
|
open(my $fh, ">", $pid_file) or return qq(Can not open "$pid_file" for pid $pid:$!); |
|
63
|
0
|
|
|
|
|
|
print $fh $pid; |
|
64
|
0
|
|
|
|
|
|
close $fh; |
|
65
|
0
|
|
|
|
|
|
return 0; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub makedir |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
0
|
|
|
0
|
|
|
my ($self, $dir) = @_; |
|
74
|
0
|
0
|
|
|
|
|
return 0 if -d $dir; |
|
75
|
0
|
0
|
0
|
|
|
|
if (-e $dir and not -d $dir) { |
|
76
|
0
|
|
|
|
|
|
unlink $dir; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
0
|
0
|
|
|
|
|
system("mkdir","-p",$dir) == 0 or return "Can't create $dir:$!"; |
|
79
|
0
|
|
|
|
|
|
return 0; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub log_and_exec |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
|
|
my ($self, @cmd) = @_; |
|
87
|
0
|
|
|
|
|
|
my $cmd = join " ",@cmd; |
|
88
|
0
|
|
|
|
|
|
$self->log->debug( $cmd ); |
|
89
|
0
|
|
|
|
|
|
my $output=`$cmd 2>&1`; |
|
90
|
0
|
|
|
|
|
|
my $retval=$?; |
|
91
|
0
|
0
|
|
|
|
|
if (not defined($output)) { |
|
92
|
0
|
|
|
|
|
|
$output = "Executing $cmd failed"; |
|
93
|
0
|
|
|
|
|
|
$retval = 1; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
0
|
0
|
|
|
|
|
chomp $output if $output; |
|
96
|
0
|
0
|
|
|
|
|
if ($retval) { |
|
97
|
0
|
0
|
|
|
|
|
return ($retval >> 8, $output) if wantarray; |
|
98
|
0
|
|
|
|
|
|
return $output; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
0
|
|
|
|
|
return (0, $output) if wantarray; |
|
101
|
0
|
|
|
|
|
|
return 0; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; # End of Tapper::Base |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |
|
107
|
|
|
|
|
|
|
=pod |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=encoding utf-8 |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 NAME |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Tapper::Base - Tapper - Common functions for all Tapper classes |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
package Tapper::Some::Class; |
|
118
|
|
|
|
|
|
|
use Moose; |
|
119
|
|
|
|
|
|
|
extends 'Tapper::Base'; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 kill_instance |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Kill the process whose id is in the given pidfile. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
@param string - pid file name |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
@return success - 0 |
|
130
|
|
|
|
|
|
|
@return error - error string |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 run_one |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Run one instance of the given command. Kill previous incarnations if necessary. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
@param hash ref - {command => command to execute, |
|
137
|
|
|
|
|
|
|
pid_file => pid file containing the ID of last incarnation, |
|
138
|
|
|
|
|
|
|
argv => array ref containg (optional) arguments} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
@return success - 0 |
|
141
|
|
|
|
|
|
|
@return error - error string |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 makedir |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Checks whether a given directory exists and creates it if not. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
@param string - directory to create |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
@return success - 0 |
|
150
|
|
|
|
|
|
|
@return error - error string |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 log_and_exec |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Execute a given command. Make sure the command is logged if requested and none |
|
155
|
|
|
|
|
|
|
of its output pollutes the console. In scalar context the function returns 0 |
|
156
|
|
|
|
|
|
|
for success and the output of the command on error. In array context the |
|
157
|
|
|
|
|
|
|
function always return a list containing the return value of the command and |
|
158
|
|
|
|
|
|
|
the output of the command. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
@param string - command |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
@return success - 0 |
|
163
|
|
|
|
|
|
|
@return error - error string |
|
164
|
|
|
|
|
|
|
@returnlist success - (0, output) |
|
165
|
|
|
|
|
|
|
@returnlist error - (return value of command, output) |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This software is Copyright (c) 2012 by Advanced Micro Devices, Inc.. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is free software, licensed under: |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|