Don't cleanup the bootstrap update immediately when bootstrapping fails.
[ksplice.git] / ksplice-view.in
blobd94a5d3abffa561340da24953bf886f2c108a080
1 #!/usr/bin/perl
3 # Copyright (C) 2007-2009 Ksplice, Inc.
4 # Authors: Jeff Arnold, Anders Kaseorg, Tim Abbott
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
17 # 02110-1301, USA.
19 use strict;
20 use warnings;
21 use lib 'KSPLICE_DATA_DIR';
22 use Ksplice;
24 my ($kid, $mid, $module, $update, $file);
25 GetOptions(@common_options,
26 "id=s" => \$kid,
27 "file=s" => \$file) or pod2usage(1);
29 pod2usage(1) if($help || scalar(@ARGV) != 0);
30 my $actions = (defined $kid) + (defined $file);
31 pod2usage(1) if($actions > 1);
33 view_kid() if(defined $kid);
34 view_file() if(defined $file);
35 view_list() if($actions == 0);
37 exit(0);
39 sub view_kid {
40 $kid =~ s/^ksplice[_-]//;
41 $kid =~ s/[-_].*$//; # In case we got an mid instead
42 $update = "ksplice_$kid";
43 if(!update_loaded($kid)) {
44 print "Ksplice id $kid is not present in the kernel\n";
45 exit(0);
47 my $stage = get_stage($kid);
48 print "Ksplice id $kid is present in the kernel and is $stage.\n\n";
49 my $source_diff = get_patch($kid);
50 return if($source_diff eq "");
51 print "Here is the source code patch associated with this update:\n";
52 print $source_diff;
55 sub view_file {
56 chdir(unpack_update($file));
57 open(PATCH, '<', "patch") or die $!;
58 local $/;
59 print <PATCH>;
60 close(PATCH);
63 sub show_kid {
64 my ($kid) = @_;
65 if ($Verbose::level < 0) {
66 print "$kid\n";
67 } else {
68 my $desc = get_short_description($kid);
69 if (defined($desc)) {
70 print "$kid: $desc";
71 } else {
72 print "$kid: no description available\n";
77 sub view_list {
78 foreach(split(/\n/, runstr("lsmod"))) {
79 next unless my ($mid) = m/^ksplice_(\S*)\s/;
80 $module = "ksplice_$mid";
81 ($kid = $mid) =~ s/[-_].*$//;
82 next unless (-e "/sys/module/$module/ksplice/stage");
83 open STAGE, '<', "/sys/module/$module/ksplice/stage" or die
84 "Unable to read stage file; are you root?";
85 show_kid($kid) if(<STAGE> eq "applied\n");
86 close STAGE;
88 if (-e "/sys/kernel/ksplice") {
89 chdir("/sys/kernel/ksplice");
90 foreach $update (glob("*")) {
91 ($kid = $update) =~ s/^ksplice_//;
92 show_kid($kid) if(get_stage($kid) eq "applied");
97 =head1 NAME
99 ksplice-view - View in-kernel or on-disk Ksplice kernel updates
101 =head1 SYNOPSIS
103 B<ksplice-view>
105 B<ksplice-view> B<--id=>I<KSPLICE_ID>
107 B<ksplice-view> B<--file=>{I<UPDATE_TARBALL> | I<UPDATE_TREE>}
109 =head1 DESCRIPTION
111 When called with no arguments, B<ksplice-view> lists the identification tags of
112 all of the Ksplice updates that are currently present in the running kernel,
113 along with their descriptions.
115 B<ksplice-view> can report about a specific Ksplice update when given the
116 update's identification tag I<KSPLICE_ID> (if the update is in the kernel) or
117 given the update's tarball filename I<UPDATE_TARBALL> or unpacked tree root
118 I<UPDATE_TREE> (if the update is on disk).
120 =head1 OPTIONS
122 =over 8
124 =item B<--id=>I<KSPLICE_ID>
126 Report information about the Ksplice update I<KSPLICE_ID> currently loaded in
127 the running kernel.
129 =item B<--file=>{I<UPDATE_TARBALL> | I<UPDATE_TREE>}
131 Report information about the Ksplice update on disk as the tarball
132 I<UPDATE_TARBALL> or unpacked as the tree I<UPDATE_TREE>.
134 =item B<-q>
136 Output only the update IDs, one per line, omitting descriptions.
138 =back
140 =head1 SEE ALSO
142 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-undo(8)>
144 =head1 BUGS
146 Please report bugs to <PACKAGE_BUGREPORT>.
148 =head1 AUTHORS
150 Jeff Arnold, Anders Kaseorg, and Tim Abbott
152 =head1 COPYRIGHT
154 Copyright (C) 2007-2009 Ksplice, Inc.
156 This is free software and documentation. You can redistribute and/or modify it
157 under the terms of the GNU General Public License, version 2.
159 =cut