Use Fatal and verbose in ksplice.pl.
[ksplice.git] / ksplice-view.in
blobea5702f5b9c4ec0fe13cfa65916b6e9125ece396
1 #!/usr/bin/perl
3 # Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License, version 2.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
16 # 02110-1301, USA.
18 use Getopt::Long;
19 use Cwd 'abs_path', 'getcwd';
20 use File::Basename;
21 use File::Copy;
22 use File::Path;
23 use File::Temp;
24 use Fatal qw(:void copy rename move chdir mkdir unlink rmtree);
25 use Pod::Usage;
26 use strict;
27 use warnings;
28 use lib 'KSPLICE_DATA_DIR';
29 use ksplice;
30 use verbose qw(copy rename move chdir mkdir mkpath unlink rmtree mktemp mkdtemp);
32 my ($kid, $file);
33 my ($help, $wantversion) = (0, 0);
34 GetOptions("help|?" => \$help,
35 "version" => \$wantversion,
36 "verbose|v!" => \$verbose::level,
37 "id=s" => \$kid,
38 "file=s" => \$file) or pod2usage(1);
40 if($wantversion) {
41 print $version_str;
42 exit(0);
44 pod2usage(1) if($help || scalar(@ARGV) != 0);
45 my $actions = (defined $kid) + (defined $file);
46 pod2usage(1) if($actions > 1);
48 view_kid() if(defined $kid);
49 view_file() if(defined $file);
50 view_list() if($actions == 0);
52 exit(0);
54 sub view_kid {
55 $kid =~ s/^ksplice[_-]//;
57 if(! -d "/sys/module") {
58 print "/sys not mounted?\n";
59 exit(1);
61 if(! -d "/sys/module/ksplice_$kid/ksplice") {
62 print "Ksplice id $kid is not present in the kernel\n";
65 open STAGE, '<', "/sys/module/ksplice_$kid/ksplice/stage" or die $!;
66 my $stage = <STAGE>;
67 close STAGE;
68 chomp($stage);
69 print "Ksplice id $kid is present in the kernel and is $stage.\n";
72 sub view_file {
73 $file = abs_path($file);
75 my $tmpdir = init_tmpdir();
76 chdir($tmpdir);
77 runval("cp $file .");
78 my $ksplice = unpack_update($file);
79 print runstr("cat $ksplice/patch");
80 chdir("/");
81 rmtree($tmpdir);
84 sub view_list {
85 chdir("/sys/module");
86 foreach $kid (glob("ksplice_*")) {
87 $kid =~ s/^ksplice_//;
88 open STAGE, '<', "/sys/module/ksplice_$kid/ksplice/stage" or next;
89 print "$kid\n" if(<STAGE> eq "applied\n");
90 close STAGE;
94 =head1 NAME
96 ksplice-view - View in-kernel or on-disk Ksplice kernel updates
98 =head1 SYNOPSIS
100 B<ksplice-view> [B<--id=>I<KSPLICE_ID> | B<--file=>I<UPDATE_TARBALL>]
102 =head1 DESCRIPTION
104 When called with no arguments, B<ksplice-view> lists the identification tags of
105 all of the Ksplice updates that are currently present in the running kernel.
107 B<ksplice-view> can report about a specific Ksplice update when given the
108 update's identification tag (if the update is in the kernel) or given the
109 update's tarball filename I<UPDATE_TARBALL> (if the update is on disk).
111 =head1 SEE ALSO
113 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-undo(8)>
115 =head1 COPYRIGHT
117 Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>.
119 This is free software and documentation. You can redistribute and/or modify it
120 under the terms of the GNU General Public License, version 2.
122 =cut