Replace all section type functions with an enum in the supersect.
[ksplice.git] / ksplice-undo.in
blobfc37ac1c99ffcd7bf23d97cef35810623fc9171c
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 ($help, $wantversion, $debug) = (0, 0, 0);
26 GetOptions("help|?" => \$help,
27 "version" => \$wantversion,
28 "verbose|v:+" => \$Verbose::level,
29 "debug" => \$debug) or pod2usage(1);
31 if($wantversion) {
32 print $version_str;
33 exit(0);
35 pod2usage(1) if($help || scalar(@ARGV) != 1);
37 my $kid = $ARGV[0];
38 $kid =~ s/^ksplice[-_]//;
39 $kid =~ s/[-_].*$//;
40 my $update = "ksplice_$kid";
41 my $nounload = runstr("lsmod") =~ m/- $/m;
43 if (!update_loaded($kid)) {
44 print "Ksplice id $kid is not present in the kernel\n";
45 exit(1);
48 chdir("/sys/module/");
49 set_debug_level($kid, $debug) if(defined($debug));
50 my $stage = get_stage($kid);
51 if ($stage ne 'applied') {
52 print "Ksplice id $kid is not applied\n";
54 else {
55 set_stage($kid, "reversed");
58 my $failed = 0;
59 foreach my $module (glob("${update}_*")) {
60 if (!$nounload && runval_raw('rmmod', $module) != 0) {
61 child_error();
62 $failed = 1;
65 if ($failed == 0 && -e "/sys/module/$update") {
66 if (!$nounload && runval_raw('rmmod', $update) != 0) {
67 child_error();
68 $failed = 1;
71 unless($failed == 0) {
72 my ($debugfile, $debugout) = get_debug_output($kid);
73 print STDERR "Error undoing Ksplice update $kid:\n";
74 print $debugout;
75 my $abort_cause = get_abort_cause($kid);
76 my $conflicts = get_conflicts($kid);
77 print_error($abort_cause);
78 if ($abort_cause eq 'code_busy') {
79 print $conflicts;
81 print("Debugging output saved to $debugout\n");
82 die;
84 exit(0);
86 sub print_error {
87 my ($error) = @_;
88 my %errors = (
89 "code_busy" => <<'END',
90 Ksplice has aborted the undo operation because it appears that the code that
91 you are trying to change is continuously in use by the system. More
92 specifically, Ksplice has been unable to find a moment when one or more of the
93 to-be-changed functions is not on a thread's kernel stack.
94 END
95 "module_busy" => <<'END',
96 Ksplice has aborted the undo operation because it appears that the Ksplice
97 update that you are trying to unload is in use by another module. You can find
98 out what module is using the Ksplice update using the lsmod command.
99 END
100 "unexpected_running_task" => <<'END',
101 Ksplice has aborted the undo operation because of an unexpected failure during
102 the kernel stack check. Please consider reporting a bug to PACKAGE_BUGREPORT.
104 "out_of_memory" => <<'END',
105 Ksplice has aborted the undo operation because the kernel ran out of memory.
107 "unexpected" => <<'END',
108 Ksplice has aborted because of an unexpected error.
109 Please consider reporting a bug to PACKAGE_BUGREPORT.
111 "UNKNOWN" => <<'END',
112 The Ksplice kernel component has returned an error code that this version of
113 ksplice-undo does not understand.
115 "ok" => <<'END',
116 Ksplice has aborted the undo operation for unknown reasons.
117 Please consider reporting a bug to PACKAGE_BUGREPORT.
120 $error = "UNKNOWN" if (!exists $errors{$error});
121 print STDERR "\n$errors{$error}\n";
124 =head1 NAME
126 ksplice-undo - Undo a Ksplice update that has been applied to the running kernel
128 =head1 SYNOPSIS
130 B<ksplice-undo> I<KSPLICE_ID>
132 =head1 DESCRIPTION
134 B<ksplice-undo> takes as input a Ksplice identification tag, as reported by
135 L<ksplice-view(8)>, and it reverses that update within the running binary kernel.
137 =head1 OPTIONS
139 =over 8
141 =item B<--debug>
143 Reverses the update with debugging output enabled. Recommended only for
144 debugging.
146 =back
148 =head1 SEE ALSO
150 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-view(8)>
152 =head1 COPYRIGHT
154 Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
155 Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
156 Tim Abbott <tabbott@mit.edu>
158 This is free software and documentation. You can redistribute and/or modify it
159 under the terms of the GNU General Public License, version 2.
161 =cut