2 use Cwd
qw(abs_path getcwd);
3 use Getopt
::Long
qw(:config bundling);
7 use File
::Spec
::Functions
qw(tmpdir);
8 use File
::Temp
qw(tempfile tempdir);
9 use Fatal
qw(:void copy rename move chdir mkdir rmdir unlink rmtree);
16 use Verbose
qw(:2 copy rename move utime chdir mkdir mkpath unlink rmtree tempfile tempdir);
18 our @ISA = qw(Exporter);
20 Verbose GetOptions pod2usage shellwords
21 $datadir $libexecdir @common_options $help $raw_errors
22 child_error runval runval_raw runstr runstr_err runval_in runval_infile runval_outfile
24 get_stage set_stage set_debug_level set_partial get_abort_cause get_patch update_loaded
25 get_debug_output get_conflicts get_raw_conflicts get_short_description
27 abs_path getcwd basename dirname tmpdir
28 copy rename move utime chdir mkdir mkpath unlink rmtree tempfile tempdir
29 print_abort_error print_abort_code
32 our ($datadir, $libexecdir) = qw(KSPLICE_DATA_DIR KSPLICE_LIBEXEC_DIR);
36 our @common_options = (
38 "raw-errors" => \
$raw_errors,
39 "version" => sub { print "Ksplice version PACKAGE_VERSION\n"; exit(0); },
40 "api-version" => sub { print "KSPLICE_API_VERSION\n"; exit(0); },
41 "verbose|v:+" => \
$Verbose::level
,
42 "quiet|q:+" => sub { $Verbose::level
-= $_[1]; },
46 die @_ if $^S
|| !$raw_errors;
55 print STDERR
"Failed to exec child\n";
56 } elsif(($?
& 127) != 0) {
57 print STDERR
"Child exited with signal ", ($?
& 127), ($?
& 128) ?
" (core dumped)\n" : "\n";
58 } elsif($?
>> 8 != 0) {
59 print STDERR
"Child exited with status ", $?
>> 8, "\n";
68 if(runval_raw
(@cmd) != 0) {
70 die "Failed during: @cmd\n";
77 print "+ @cmd\n" if($Verbose::level
>= 1);
79 my $pid = open3
(fileno STDIN
, ">&STDOUT", ">/dev/null", @cmd);
89 print "+ @cmd\n" if($Verbose::level
>= 1);
93 open3
(fileno STDIN
, \
*PIPE
, ">/dev/null", @cmd);
95 open PIPE
, '-|', @cmd or die "Can't run @cmd: $!";
98 close PIPE
or $! == 0 or die "Can't run @cmd: $!";
104 print "+ @cmd\n" if($Verbose::level
>= 1);
106 my $pid = open3
(fileno STDIN
, '>&STDOUT', \
*ERROR
, @cmd);
110 print STDERR
$error unless $raw_errors;
116 print "+ @cmd <<'EOF'\n${in}EOF\n" if($Verbose::level >= 1);
119 open3(\*WRITE, ">&STDOUT
", ">/dev/null
", @cmd);
121 open(WRITE, '|-', @cmd) or die "Can
't run @cmd: $!";
124 close(WRITE) or $! == 0 or die "Can't run
@cmd: $!";
126 die "Failed during
: @cmd";
131 my ($infile, @cmd) = @_;
132 print "+ @cmd < $infile\n" if($Verbose::level >= 1);
134 open(INFILE, '<', $infile) or die "Can
't open $infile: $!";
137 $pid = open3('<&INFILE
', '>&STDOUT
', ">/dev/null", @cmd);
139 $pid = open2('>&STDOUT
', '<&INFILE
', @cmd);
143 die "Failed during: @cmd";
148 my ($outfile, @cmd) = @_;
149 print "+ @cmd > $outfile\n" if($Verbose::level >= 1);
151 open(OUTFILE, '>', $outfile) or die "Can't
open $outfile: $!";
154 $pid = open3('</dev/null', '>&OUTFILE', ">/dev/null
", @cmd);
156 $pid = open2('>&OUTFILE', '</dev/null', @cmd);
160 die "Failed during
: @cmd";
166 runval("tar
", "--force
-local", "-zxf
", $file);
167 my ($ksplice) = glob('*/');
168 chop($ksplice); # remove the trailing slash
174 if(! -d "/sys/module
") {
175 die "/sys
not mounted?
\n";
177 my $update = "ksplice_
$kid";
178 if (-d "/sys/kernel
/ksplice/$kid") {
179 return "/sys/kernel
/ksplice/$kid";
181 if (-d "/sys/module
/$update/ksplice
") {
182 return "/sys/module
/$update/ksplice
";
189 return defined(get_sysfs($kid));
195 open(INPUT, "<", $file) or die $!;
200 my ($file, $string) = @_;
202 open(INPUT, ">", $file) or die $!;
207 my ($kid, $attr) = @_;
208 my $sysfs = get_sysfs($kid);
209 return undef if (!defined($sysfs));
210 return read_file("$sysfs/$attr");
214 my ($kid, $attr, $string) = @_;
215 my $sysfs = get_sysfs($kid);
216 return undef if (!defined($sysfs));
217 write_file("$sysfs/$attr", $string);
220 sub get_debug_output {
221 my ($kid, $debugfs_out) = @_;
222 my $update = "ksplice_
$kid";
224 (undef, $debugfs_out) = tempfile('ksplice-debug-XXXXXX', DIR => tmpdir());
226 if (runval_raw("grep", "-qFx
", "nodev
\tdebugfs
", "/proc/filesystems
") == 0) {
227 my $debugfsdir = tempdir('ksplice-debugfs-XXXXXX', TMPDIR => 1);
228 runval(qw(mount -t debugfs debugfs), $debugfsdir);
229 if (-e
"$debugfsdir/$update") {
230 copy
("$debugfsdir/$update", $debugfs_out);
232 runval
(qw(umount), $debugfsdir);
235 } elsif ($?
>> 8 == 1) {
245 chomp(my $result = read_sysfs
($kid, "stage"));
249 sub get_abort_cause
{
251 chomp(my $result = read_sysfs
($kid, "abort_cause"));
257 chomp(my $conflicts = read_sysfs
($kid, "conflicts"));
258 my @conflicts = split('\n', $conflicts);
260 foreach my $conflict (@conflicts) {
261 my ($name, $pid, @symbols) = split(' ', $conflict);
263 $out .= "Process $name(pid $pid) is using the following symbols changed by update $kid:\n";
264 foreach my $symbol (@symbols) {
265 $out .= " $symbol\n";
271 sub get_raw_conflicts
{
273 my $conflicts = read_sysfs
($kid, "conflicts");
279 my $result = read_file
("/var/run/ksplice/updates/$kid/patch");
283 sub get_short_description
{
285 open(INPUT
, "<", "/var/run/ksplice/updates/$kid/description") or return undef;
286 my $result = <INPUT
>;
292 my ($kid, $string) = @_;
293 write_sysfs
($kid, "stage", "$string\n");
296 sub set_debug_level
{
297 my ($kid, $string) = @_;
298 write_sysfs
($kid, "debug", "$string\n");
302 my ($kid, $string) = @_;
303 write_sysfs
($kid, "partial", "$string\n");
306 sub print_abort_error
{
307 my ($kid, %errors) = @_;
308 my $error = get_abort_cause
($kid);
310 print_abort_code
($error, %errors);
311 if ($error eq 'code_busy') {
313 print STDERR get_raw_conflicts
($kid);
315 print STDERR get_conflicts
($kid);
320 sub print_abort_code
{
321 my ($error, %errors) = @_;
323 print STDERR
"$error\n";
325 $error = "UNKNOWN" if (!exists $errors{$error});
326 print STDERR
"\n$errors{$error}\n";