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 @common_options $help
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_short_description
27 abs_path getcwd basename dirname tmpdir
28 copy rename move utime chdir mkdir mkpath unlink rmtree tempfile tempdir
31 our ($datadir, $libexecdir) = qw(KSPLICE_DATA_DIR KSPLICE_LIBEXEC_DIR);
34 our @common_options = (
36 "version" => sub { print "Ksplice version PACKAGE_VERSION\n"; exit(0); },
37 "api-version" => sub { print "KSPLICE_API_VERSION\n"; exit(0); },
38 "verbose|v:+" => \
$Verbose::level
,
39 "quiet|q:+" => sub { $Verbose::level
-= $_[1]; },
44 print STDERR
"Failed to exec child\n";
45 } elsif(($?
& 127) != 0) {
46 print STDERR
"Child exited with signal ", ($?
& 127), ($?
& 128) ?
" (core dumped)\n" : "\n";
47 } elsif($?
>> 8 != 0) {
48 print STDERR
"Child exited with status ", $?
>> 8, "\n";
57 if(runval_raw
(@cmd) != 0) {
59 die "Failed during: @cmd\n";
66 print "+ @cmd\n" if($Verbose::level
>= 1);
72 print "+ @cmd\n" if($Verbose::level
>= 1);
74 open PIPE
, '-|', @cmd or die "Can't run @cmd: $!";
76 close PIPE
or $! == 0 or die "Can't run @cmd: $!";
82 print "+ @cmd\n" if($Verbose::level
>= 1);
84 my $pid = open3
(fileno STDIN
, '>&STDOUT', \
*ERROR
, @cmd);
94 print "+ @cmd <<'EOF'\n${in}EOF\n" if($Verbose::level >= 1);
96 open(WRITE, '|-', @cmd) or die "Can
't run @cmd: $!";
98 close(WRITE) or $! == 0 or die "Can't run
@cmd: $!";
100 die "Failed during
: @cmd";
105 my ($infile, @cmd) = @_;
106 print "+ @cmd < $infile\n" if($Verbose::level >= 1);
108 open(INFILE, '<', $infile) or die "Can
't open $infile: $!";
109 my $pid = open2('>&STDOUT
', '<&INFILE
', @cmd) or die "Can't run
@cmd: $!";
112 die "Failed during
: @cmd";
117 my ($outfile, @cmd) = @_;
118 print "+ @cmd > $outfile\n" if($Verbose::level >= 1);
120 open(OUTFILE, '>', $outfile) or die "Can
't open $outfile: $!";
121 my $pid = open2('>&OUTFILE
', '</dev/null
', @cmd) or die "Can't run
@cmd: $!";
124 die "Failed during
: @cmd";
130 runval("tar
", "zxf
", $file);
131 my ($ksplice) = glob('*/');
132 chop($ksplice); # remove the trailing slash
138 if(! -d "/sys/module
") {
139 die "/sys
not mounted?
\n";
141 my $update = "ksplice_
$kid";
142 if (-d "/sys/kernel
/ksplice/$kid") {
143 return "/sys/kernel
/ksplice/$kid";
145 if (-d "/sys/module
/$update/ksplice
") {
146 return "/sys/module
/$update/ksplice
";
153 return defined(get_sysfs($kid));
159 open(INPUT, "<", $file) or die $!;
164 my ($file, $string) = @_;
166 open(INPUT, ">", $file) or die $!;
171 my ($kid, $attr) = @_;
172 my $sysfs = get_sysfs($kid);
173 return undef if (!defined($sysfs));
174 return read_file("$sysfs/$attr");
178 my ($kid, $attr, $string) = @_;
179 my $sysfs = get_sysfs($kid);
180 return undef if (!defined($sysfs));
181 write_file("$sysfs/$attr", $string);
184 sub get_debug_output {
186 my $update = "ksplice_
$kid";
187 my (undef, $debugfs_out) = tempfile('ksplice-debug-XXXXXX', DIR => tmpdir());
188 my $debugfsdir = tempdir('ksplice-debugfs-XXXXXX',
189 TMPDIR => 1, CLEANUP => 1);
190 if (runval_raw("grep", "-qFx
", "nodev
\tdebugfs
", "/proc/filesystems
") == 0) {
191 runval(qw(mount -t debugfs debugfs), $debugfsdir);
192 copy
("$debugfsdir/$update", "$debugfs_out");
193 my $debug = read_file
("$debugfsdir/$update");
194 runval
(qw(umount), $debugfsdir);
195 return ($debugfs_out, $debug);
196 } elsif ($?
>> 8 == 1) {
206 chomp(my $result = read_sysfs
($kid, "stage"));
210 sub get_abort_cause
{
212 chomp(my $result = read_sysfs
($kid, "abort_cause"));
218 chomp(my $conflicts = read_sysfs
($kid, "conflicts"));
219 my @conflicts = split('\n', $conflicts);
221 foreach my $conflict (@conflicts) {
222 my ($name, $pid, @symbols) = split(' ', $conflict);
224 $out .= "Process $name(pid $pid) is using the following symbols changed by update $kid:\n";
225 foreach my $symbol (@symbols) {
226 $out .= " $symbol\n";
234 my $result = read_file
("/var/run/ksplice/updates/$kid/patch");
238 sub get_short_description
{
240 open(INPUT
, "<", "/var/run/ksplice/updates/$kid/description") or return undef;
241 my $result = <INPUT
>;
247 my ($kid, $string) = @_;
248 write_sysfs
($kid, "stage", "$string\n");
251 sub set_debug_level
{
252 my ($kid, $string) = @_;
253 write_sysfs
($kid, "debug", "$string\n");
257 my ($kid, $string) = @_;
258 write_sysfs
($kid, "partial", "$string\n");