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 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 $version_str
22 child_error runval runval_raw runstr runstr_err runsuc runsuc_in unpack_update
23 get_stage set_stage set_debug_level get_abort_cause get_patch update_loaded
24 get_debug_output get_conflicts
25 abs_path getcwd basename dirname tmpdir
26 copy rename move utime chdir mkdir mkpath unlink rmtree tempfile tempdir
29 our ($datadir, $libexecdir) = qw(KSPLICE_DATA_DIR KSPLICE_LIBEXEC_DIR);
30 our $version_str = "Ksplice version PACKAGE_VERSION\n";
34 print STDERR
"Failed to exec child\n";
35 } elsif(($?
& 127) != 0) {
36 print STDERR
"Child exited with signal ", ($?
& 127), ($?
& 128) ?
" (core dumped)\n" : "\n";
37 } elsif($?
>> 8 != 0) {
38 print STDERR
"Child exited with status ", $?
>> 8, "\n";
47 if(runval_raw
(@cmd) != 0) {
49 die "Failed during: @cmd\n";
56 print "+ @cmd\n" if($Verbose::level
>= 1);
57 if($Verbose::level
< 1) {
58 open $out, ">&STDOUT" or die "Can't dup STDOUT: $!";
59 open $err, ">&STDERR" or die "Can't dup STDERR: $!";
60 open STDOUT
, '>', "/dev/null" or die "Can't hide STDOUT: $!";
61 open STDERR
, '>', "/dev/null" or die "Can't hide STDERR: $!";
63 my $val = system(@cmd);
64 if($Verbose::level
< 1) {
65 open STDOUT
, ">&", $out or die "Can't restore STDOUT: $!";
66 open STDERR
, ">&", $err or die "Can't restore STDERR: $!";
73 print "+ @cmd\n" if($Verbose::level
>= 1);
75 open PIPE
, '-|', @cmd or die "Can't run @cmd: $!";
77 close PIPE
or $! == 0 or die "Can't run @cmd: $!";
83 print "+ @cmd\n" if($Verbose::level
>= 1);
84 my $pid = open3
(\
*WRITE
, \
*READ
, \
*ERROR
, @cmd);
91 my ($cmd, @args) = @_;
92 my $output = runstr
("$libexecdir/ksplice-$cmd", @args);
94 print "Output: $output\n";
95 die "Failed during: $libexecdir/ksplice-$cmd @args";
101 my ($in, $cmd, @args) = @_;
102 my @cmd = ("$libexecdir/ksplice-$cmd", @args);
103 print "+ @cmd <<'EOF'\n${in}EOF\n" if($Verbose::level >= 1);
104 local (*READ, *WRITE);
105 my $pid = open2(\*READ, \*WRITE, @cmd);
110 die "Failed during
: $libexecdir/ksplice
-$cmd @args";
118 runval("tar
", "zxf
", $file);
119 my ($ksplice) = glob('*/');
120 chop($ksplice); # remove the trailing slash
126 if(! -d "/sys/module
") {
127 die "/sys
not mounted?
\n";
129 my $update = "ksplice_
$kid";
130 if (-d "/sys/kernel
/ksplice/$kid") {
131 return "/sys/kernel
/ksplice/$kid";
133 if (-d "/sys/module
/$update/ksplice
") {
134 return "/sys/module
/$update/ksplice
";
141 return defined(get_sysfs($kid));
147 open(INPUT, "<", $file) or die $!;
152 my ($file, $string) = @_;
154 open(INPUT, ">", $file) or die $!;
159 my ($kid, $attr) = @_;
160 my $sysfs = get_sysfs($kid);
161 return undef if (!defined($sysfs));
162 return read_file("$sysfs/$attr");
166 my ($kid, $attr, $string) = @_;
167 my $sysfs = get_sysfs($kid);
168 return undef if (!defined($sysfs));
169 write_file("$sysfs/$attr", $string);
172 sub get_debug_output {
174 my $update = "ksplice_
$kid";
176 my (undef, $debugfs_out) = tempfile('ksplice-debug-XXXXXX', DIR => tmpdir());
177 my $debugfsdir = tempdir('ksplice-debugfs-XXXXXX',
178 TMPDIR => 1, CLEANUP => 1);
179 if (runval_raw(qw(mount -t debugfs debugfs), $debugfsdir) == 0) {
180 copy
("$debugfsdir/$update", "$debugfs_out");
181 $debug = read_file
("$debugfsdir/$update");
182 runval
(qw(umount), $debugfsdir);
183 } elsif ($?
>> 8 == 32) {
184 my $dmesg = runstr
("dmesg | grep ksplice");
185 while($dmesg =~ /ksplice: Preparing to reverse/) {
189 write_file($debugfs_out, $dmesg);
194 return ($debugfs_out, $debug);
199 chomp(my $result = read_sysfs($kid, "stage"));
203 sub get_abort_cause {
205 chomp(my $result = read_sysfs($kid, "abort_cause"));
211 chomp(my $conflicts = read_sysfs($kid, "conflicts"));
212 my @conflicts = split('\n', $conflicts);
214 foreach my $conflict (@conflicts) {
215 my ($name, $pid, @symbols) = split(' ', $conflict);
217 $out .= "Process $name(pid $pid) is using the following symbols changed by update $kid:\n";
218 foreach my $symbol (@symbols) {
219 $out .= " $symbol\n";
227 my $result = read_file("/var/run/ksplice/updates/$kid/patch");
232 my ($kid, $string) = @_;
233 write_sysfs($kid, "stage", "$string\n");
236 sub set_debug_level {
237 my ($kid, $string) = @_;
238 write_sysfs($kid, "debug", "$string\n");