Add supersect_move function.
[ksplice.git] / ksplice-view.in
blob6a756775334ab0bddca2d235fa09f76e5a8c9663
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 strict;
19 use warnings;
20 use lib 'KSPLICE_DATA_DIR';
21 use Ksplice;
23 my ($kid, $mid, $module, $update, $file);
24 my ($help, $wantversion) = (0, 0);
25 GetOptions("help|?" => \$help,
26 "version" => \$wantversion,
27 "verbose|v:+" => \$Verbose::level,
28 "id=s" => \$kid,
29 "file=s" => \$file) or pod2usage(1);
31 if($wantversion) {
32 print $version_str;
33 exit(0);
35 pod2usage(1) if($help || scalar(@ARGV) != 0);
36 my $actions = (defined $kid) + (defined $file);
37 pod2usage(1) if($actions > 1);
39 view_kid() if(defined $kid);
40 view_file() if(defined $file);
41 view_list() if($actions == 0);
43 exit(0);
45 sub view_kid {
46 $kid =~ s/^ksplice[_-]//;
47 $kid =~ s/[-_].*$//; # In case we got an mid instead
48 $update = "ksplice_$kid";
49 if(!update_loaded($kid)) {
50 print "Ksplice id $kid is not present in the kernel\n";
51 exit(0);
53 my $stage = get_stage($kid);
54 print "Ksplice id $kid is present in the kernel and is $stage.\n\n";
55 my $source_diff = get_patch($kid);
56 return if($source_diff eq "");
57 print "Here is the source code patch associated with this update:\n";
58 print $source_diff;
61 sub view_file {
62 my $tmpdir = tempdir('ksplice-tmp-XXXXXX', TMPDIR => 1, CLEANUP => 1);
63 copy($file, "$tmpdir/" . basename($file));
64 chdir($tmpdir);
65 my $ksplice = unpack_update($file);
66 open(PATCH, '<', "$ksplice/patch") or die $!;
67 local $/;
68 print <PATCH>;
69 close(PATCH);
72 sub view_list {
73 foreach(split(/\n/, runstr("lsmod"))) {
74 next unless my ($mid) = m/^ksplice_(\S*)\s/;
75 $module = "ksplice_$mid";
76 ($kid = $mid) =~ s/[-_].*$//;
77 next unless (-e "/sys/module/$module/$module/stage");
78 open STAGE, '<', "/sys/module/$module/$module/stage" or next;
79 print "$kid\n" if(<STAGE> eq "applied\n");
80 close STAGE;
82 if (-e "/sys/module/ksplice") {
83 chdir("/sys/module/ksplice");
84 foreach $update (glob("ksplice_*")) {
85 ($kid = $update) =~ s/^ksplice_//;
86 print "$kid\n" if(get_stage($kid) eq "applied");
91 =head1 NAME
93 ksplice-view - View in-kernel or on-disk Ksplice kernel updates
95 =head1 SYNOPSIS
97 B<ksplice-view> [B<--id=>I<KSPLICE_ID> | B<--file=>I<UPDATE_TARBALL>]
99 =head1 DESCRIPTION
101 When called with no arguments, B<ksplice-view> lists the identification tags of
102 all of the Ksplice updates that are currently present in the running kernel.
104 B<ksplice-view> can report about a specific Ksplice update when given the
105 update's identification tag (if the update is in the kernel) or given the
106 update's tarball filename I<UPDATE_TARBALL> (if the update is on disk).
108 =head1 SEE ALSO
110 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-undo(8)>
112 =head1 COPYRIGHT
114 Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>.
116 This is free software and documentation. You can redistribute and/or modify it
117 under the terms of the GNU General Public License, version 2.
119 =cut