Remove now-unused label_map parsing code.
[ksplice.git] / ksplice-view.in
blob71cdeadf09076eb775566b57aa27c9841db8b98b
1 #!/usr/bin/perl
3 # Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
4 # Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
5 # Tim Abbott <tabbott@mit.edu>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License, version 2.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
18 # 02110-1301, USA.
20 use strict;
21 use warnings;
22 use lib 'KSPLICE_DATA_DIR';
23 use Ksplice;
25 my ($kid, $mid, $module, $update, $file);
26 my ($help, $wantversion) = (0, 0);
27 GetOptions("help|?" => \$help,
28 "version" => \$wantversion,
29 "verbose|v:+" => \$Verbose::level,
30 "id=s" => \$kid,
31 "file=s" => \$file) or pod2usage(1);
33 if($wantversion) {
34 print $version_str;
35 exit(0);
37 pod2usage(1) if($help || scalar(@ARGV) != 0);
38 my $actions = (defined $kid) + (defined $file);
39 pod2usage(1) if($actions > 1);
41 view_kid() if(defined $kid);
42 view_file() if(defined $file);
43 view_list() if($actions == 0);
45 exit(0);
47 sub view_kid {
48 $kid =~ s/^ksplice[_-]//;
49 $kid =~ s/[-_].*$//; # In case we got an mid instead
50 $update = "ksplice_$kid";
51 if(!update_loaded($kid)) {
52 print "Ksplice id $kid is not present in the kernel\n";
53 exit(0);
55 my $stage = get_stage($kid);
56 print "Ksplice id $kid is present in the kernel and is $stage.\n\n";
57 my $source_diff = get_patch($kid);
58 return if($source_diff eq "");
59 print "Here is the source code patch associated with this update:\n";
60 print $source_diff;
63 sub view_file {
64 my $tmpdir = tempdir('ksplice-tmp-XXXXXX', TMPDIR => 1, CLEANUP => 1);
65 copy($file, "$tmpdir/" . basename($file));
66 chdir($tmpdir);
67 my $ksplice = unpack_update($file);
68 open(PATCH, '<', "$ksplice/patch") or die $!;
69 local $/;
70 print <PATCH>;
71 close(PATCH);
74 sub view_list {
75 foreach(split(/\n/, runstr("lsmod"))) {
76 next unless my ($mid) = m/^ksplice_(\S*)\s/;
77 $module = "ksplice_$mid";
78 ($kid = $mid) =~ s/[-_].*$//;
79 next unless (-e "/sys/module/$module/ksplice/stage");
80 open STAGE, '<', "/sys/module/$module/ksplice/stage" or next;
81 print "$kid\n" if(<STAGE> eq "applied\n");
82 close STAGE;
84 if (-e "/sys/kernel/ksplice") {
85 chdir("/sys/kernel/ksplice");
86 foreach $update (glob("*")) {
87 ($kid = $update) =~ s/^ksplice_//;
88 print "$kid\n" if(get_stage($kid) eq "applied");
93 =head1 NAME
95 ksplice-view - View in-kernel or on-disk Ksplice kernel updates
97 =head1 SYNOPSIS
99 B<ksplice-view> [B<--id=>I<KSPLICE_ID> | B<--file=>I<UPDATE_TARBALL>]
101 =head1 DESCRIPTION
103 When called with no arguments, B<ksplice-view> lists the identification tags of
104 all of the Ksplice updates that are currently present in the running kernel.
106 B<ksplice-view> can report about a specific Ksplice update when given the
107 update's identification tag (if the update is in the kernel) or given the
108 update's tarball filename I<UPDATE_TARBALL> (if the update is on disk).
110 =head1 SEE ALSO
112 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-undo(8)>
114 =head1 COPYRIGHT
116 Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
117 Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
118 Tim Abbott <tabbott@mit.edu>
120 This is free software and documentation. You can redistribute and/or modify it
121 under the terms of the GNU General Public License, version 2.
123 =cut