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 runval_in runval_infile 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);
85 my $pid = open3
(fileno STDIN
, '>&STDOUT', \
*ERROR
, @cmd);
95 print "+ @cmd <<'EOF'\n${in}EOF\n" if($Verbose::level >= 1);
97 open(WRITE, '|-', @cmd) or die "Can
't run @cmd: $!";
99 close(WRITE) or $! == 0 or die "Can't run
@cmd: $!";
101 die "Failed during
: @cmd";
106 my ($infile, @cmd) = @_;
107 print "+ @cmd < $infile\n" if($Verbose::level >= 1);
109 open(INFILE, '<', $infile) or die "Can
't open $infile: $!";
110 my $pid = open2('>&STDOUT
', '<&INFILE
', @cmd) or die "Can't run
@cmd: $!";
113 die "Failed during
: @cmd";
119 runval("tar
", "zxf
", $file);
120 my ($ksplice) = glob('*/');
121 chop($ksplice); # remove the trailing slash
127 if(! -d "/sys/module
") {
128 die "/sys
not mounted?
\n";
130 my $update = "ksplice_
$kid";
131 if (-d "/sys/kernel
/ksplice/$kid") {
132 return "/sys/kernel
/ksplice/$kid";
134 if (-d "/sys/module
/$update/ksplice
") {
135 return "/sys/module
/$update/ksplice
";
142 return defined(get_sysfs($kid));
148 open(INPUT, "<", $file) or die $!;
153 my ($file, $string) = @_;
155 open(INPUT, ">", $file) or die $!;
160 my ($kid, $attr) = @_;
161 my $sysfs = get_sysfs($kid);
162 return undef if (!defined($sysfs));
163 return read_file("$sysfs/$attr");
167 my ($kid, $attr, $string) = @_;
168 my $sysfs = get_sysfs($kid);
169 return undef if (!defined($sysfs));
170 write_file("$sysfs/$attr", $string);
173 sub get_debug_output {
175 my $update = "ksplice_
$kid";
177 my (undef, $debugfs_out) = tempfile('ksplice-debug-XXXXXX', DIR => tmpdir());
178 my $debugfsdir = tempdir('ksplice-debugfs-XXXXXX',
179 TMPDIR => 1, CLEANUP => 1);
180 if (runval_raw(qw(mount -t debugfs debugfs), $debugfsdir) == 0) {
181 copy
("$debugfsdir/$update", "$debugfs_out");
182 $debug = read_file
("$debugfsdir/$update");
183 runval
(qw(umount), $debugfsdir);
184 } elsif ($?
>> 8 == 32) {
190 return ($debugfs_out, $debug);
195 chomp(my $result = read_sysfs
($kid, "stage"));
199 sub get_abort_cause
{
201 chomp(my $result = read_sysfs
($kid, "abort_cause"));
207 chomp(my $conflicts = read_sysfs
($kid, "conflicts"));
208 my @conflicts = split('\n', $conflicts);
210 foreach my $conflict (@conflicts) {
211 my ($name, $pid, @symbols) = split(' ', $conflict);
213 $out .= "Process $name(pid $pid) is using the following symbols changed by update $kid:\n";
214 foreach my $symbol (@symbols) {
215 $out .= " $symbol\n";
223 my $result = read_file
("/var/run/ksplice/updates/$kid/patch");
228 my ($kid, $string) = @_;
229 write_sysfs
($kid, "stage", "$string\n");
232 sub set_debug_level
{
233 my ($kid, $string) = @_;
234 write_sysfs
($kid, "debug", "$string\n");