Makefile.ksplice: Rewrite ksplice-cow-check as a wrapper function.
[ksplice.git] / ksplice-view.in
blob4b29a5cf5cfc11ca188ed01bbfa5410cc82a721d
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 my $tmpdir = tempdir('ksplice-tmp-XXXXXX', TMPDIR => 1, CLEANUP => 1);
57 copy($file, "$tmpdir/" . basename($file));
58 chdir($tmpdir);
59 my $ksplice = unpack_update($file);
60 open(PATCH, '<', "$ksplice/patch") or die $!;
61 local $/;
62 print <PATCH>;
63 close(PATCH);
66 sub show_kid {
67 my ($kid) = @_;
68 if ($Verbose::level < 0) {
69 print "$kid\n";
70 } else {
71 my $desc = get_short_description($kid);
72 if (defined($desc)) {
73 print "$kid: $desc";
74 } else {
75 print "$kid: no description available\n";
80 sub view_list {
81 foreach(split(/\n/, runstr("lsmod"))) {
82 next unless my ($mid) = m/^ksplice_(\S*)\s/;
83 $module = "ksplice_$mid";
84 ($kid = $mid) =~ s/[-_].*$//;
85 next unless (-e "/sys/module/$module/ksplice/stage");
86 open STAGE, '<', "/sys/module/$module/ksplice/stage" or die
87 "Unable to read stage file; are you root?";
88 show_kid($kid) if(<STAGE> eq "applied\n");
89 close STAGE;
91 if (-e "/sys/kernel/ksplice") {
92 chdir("/sys/kernel/ksplice");
93 foreach $update (glob("*")) {
94 ($kid = $update) =~ s/^ksplice_//;
95 show_kid($kid) if(get_stage($kid) eq "applied");
100 =head1 NAME
102 ksplice-view - View in-kernel or on-disk Ksplice kernel updates
104 =head1 SYNOPSIS
106 B<ksplice-view>
108 B<ksplice-view> B<--id=>I<KSPLICE_ID>
110 B<ksplice-view> B<--file=>I<UPDATE_TARBALL>
112 =head1 DESCRIPTION
114 When called with no arguments, B<ksplice-view> lists the identification tags of
115 all of the Ksplice updates that are currently present in the running kernel,
116 along with their descriptions.
118 B<ksplice-view> can report about a specific Ksplice update when given the
119 update's identification tag (if the update is in the kernel) or given the
120 update's tarball filename I<UPDATE_TARBALL> (if the update is on disk).
122 =head1 OPTIONS
124 =over 8
126 =item B<--id=>I<KSPLICE_ID>
128 Report information about the Ksplice update I<KSPLICE_ID> currently loaded in
129 the running kernel.
131 =item B<--file=>I<UPDATE_TARBALL>
133 Report information about the Ksplice update I<UPDATE_TARBALL> on disk.
135 =item B<-q>
137 Output only the update IDs, one per line, omitting descriptions.
139 =back
141 =head1 SEE ALSO
143 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-undo(8)>
145 =head1 BUGS
147 Please report bugs to <PACKAGE_BUGREPORT>.
149 =head1 AUTHORS
151 Jeff Arnold, Anders Kaseorg, and Tim Abbott
153 =head1 COPYRIGHT
155 Copyright (C) 2007-2009 Ksplice, Inc.
157 This is free software and documentation. You can redistribute and/or modify it
158 under the terms of the GNU General Public License, version 2.
160 =cut