New hash table interface for objcommon.h, based on BFD hash tables.
[ksplice.git] / ksplice-view.in
blob1695a7728e3936d6d23cb2f544f2adad9649b0a2
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 Pod::Usage;
21 use strict;
22 use warnings;
23 use lib 'KSPLICE_DATA_DIR';
24 use ksplice;
26 my ($kid, $file);
27 my ($help, $wantversion) = (0, 0);
28 GetOptions("help|?" => \$help,
29 "version" => \$wantversion,
30 "verbose|v!" => \$verbose,
31 "id=s" => \$kid,
32 "file=s" => \$file) or pod2usage(1);
34 if($wantversion) {
35 print $version_str;
36 exit(0);
38 pod2usage(1) if($help || scalar(@ARGV) != 0);
39 my $actions = (defined $kid) + (defined $file);
40 pod2usage(1) if($actions > 1);
42 view_kid() if(defined $kid);
43 view_file() if(defined $file);
44 view_list() if($actions == 0);
46 exit(0);
48 sub view_kid {
49 $kid =~ s/^ksplice[_-]//;
50 if (-e "/proc/ksplice_$kid") {
51 print "Ksplice id $kid is present in the kernel\n";
52 } else {
53 print "Ksplice id $kid is not present in the kernel\n";
57 sub view_file {
58 $file = abs_path($file);
60 my $tmpdir = init_tmpdir();
61 runcd($tmpdir);
62 runval("cp $file .");
63 my $ksplice = unpack_update($file);
64 print runstr("cat $ksplice/patch");
65 runval("rm -rf $tmpdir");
68 sub view_list {
69 foreach(split(/\n/, runstr("lsmod"))) {
70 next unless my ($kid) = m/^ksplice_(\S*)\s/;
71 next unless (-e "/proc/ksplice_$kid");
72 print "$kid\n";
76 =head1 NAME
78 ksplice-view - View in-kernel or on-disk Ksplice kernel updates
80 =head1 SYNOPSIS
82 B<ksplice-view> [B<--id=>I<KSPLICE_ID> | B<--file=>I<UPDATE_TARBALL>]
84 =head1 DESCRIPTION
86 When called with no arguments, B<ksplice-view> lists the identification tags of
87 all of the Ksplice updates that are currently present in the running kernel.
89 B<ksplice-view> can report about a specific Ksplice update when given the
90 update's identification tag (if the update is in the kernel) or given the
91 update's tarball filename I<UPDATE_TARBALL> (if the update is on disk).
93 =head1 SEE ALSO
95 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-undo(8)>
97 =head1 COPYRIGHT
99 Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>.
101 This is free software and documentation. You can redistribute and/or modify it
102 under the terms of the GNU General Public License, version 2.
104 =cut