Prevent regeneration of include/config/kernel.release in diff mode.
[ksplice.git] / ksplice-undo.in
blobb32e17128d6a90ea4cbfad7464135b319ccbaad0
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;
24 use Time::HiRes qw(usleep);
26 my $debug = 0;
27 GetOptions(@common_options,
28 "debug" => \$debug) or pod2usage(1);
30 pod2usage(1) if($help || scalar(@ARGV) != 1);
32 my $kid = $ARGV[0];
33 $kid =~ s/^ksplice[-_]//;
34 $kid =~ s/[-_].*$//;
35 my $update = "ksplice_$kid";
36 my $nounload = runstr("lsmod") =~ m/- $/m;
38 if (!update_loaded($kid)) {
39 print "Ksplice id $kid is not present in the kernel\n";
40 exit(1);
43 chdir("/sys/module/");
44 set_debug_level($kid, $debug) if(defined($debug));
45 my $stage = get_stage($kid);
46 if ($stage ne 'applied') {
47 print "Ksplice id $kid is not applied\n";
49 else {
50 set_stage($kid, "reversed");
53 $stage = get_stage($kid);
54 my $failed = 0;
55 $failed = 1 if ($stage ne 'reversed');
56 foreach my $module (glob("${update}_*")) {
57 if (!$nounload && runval_raw('rmmod', $module) != 0) {
58 child_error();
59 $failed = 1;
62 if ($failed == 0) {
63 set_stage($kid, "cleanup");
64 my $count = 0;
65 while (update_loaded($kid) && $count < 5) {
66 usleep(100000);
67 $count++;
70 if ($failed == 0 && -e "/sys/module/$update") {
71 if (!$nounload && runval_raw('rmmod', $update) != 0) {
72 child_error();
73 $failed = 1;
76 unless($failed == 0) {
77 my ($debugfile, $debugout) = get_debug_output($kid);
78 print STDERR "Error undoing Ksplice update $kid:\n";
79 print $debugout;
80 my $abort_cause = get_abort_cause($kid);
81 my $conflicts = get_conflicts($kid);
82 print_error($abort_cause);
83 if ($abort_cause eq 'code_busy') {
84 print $conflicts;
86 if($debug && defined $debugfile) {
87 print $debugout;
88 print("Debugging output saved to $debugfile\n");
90 die;
92 rmtree("/var/run/ksplice/updates/$kid");
93 exit(0);
95 sub print_error {
96 my ($error) = @_;
97 my %errors = (
98 "code_busy" => <<'END',
99 Ksplice has aborted the undo operation because it appears that the code that
100 you are trying to change is continuously in use by the system. More
101 specifically, Ksplice has been unable to find a moment when one or more of the
102 to-be-changed functions is not on a thread's kernel stack.
104 "module_busy" => <<'END',
105 Ksplice has aborted the undo operation because it appears that the Ksplice
106 update that you are trying to unload is in use by another module. You can find
107 out what module is using the Ksplice update using the lsmod command.
109 "unexpected_running_task" => <<'END',
110 Ksplice has aborted the undo operation because of an unexpected failure during
111 the kernel stack check. Please consider reporting a bug to PACKAGE_BUGREPORT.
113 "out_of_memory" => <<'END',
114 Ksplice has aborted the undo operation because the kernel ran out of memory.
116 "call_failed" => <<'END',
117 Ksplice has aborted the undo operation at the request of a one of the
118 pre-application hooks that were included as part of this Ksplice
119 update. This is likely the result of a bug in the patch used to
120 generate this update.
122 "unexpected" => <<'END',
123 Ksplice has aborted because of an unexpected error.
124 Please consider reporting a bug to PACKAGE_BUGREPORT.
126 "UNKNOWN" => <<'END',
127 The Ksplice kernel component has returned an error code that this version of
128 ksplice-undo does not understand.
130 "ok" => <<'END',
131 Ksplice has aborted the undo operation for unknown reasons.
132 Please consider reporting a bug to PACKAGE_BUGREPORT.
135 $error = "UNKNOWN" if (!exists $errors{$error});
136 print STDERR "\n$errors{$error}\n";
139 =head1 NAME
141 ksplice-undo - Undo a Ksplice update that has been applied to the running kernel
143 =head1 SYNOPSIS
145 B<ksplice-undo> I<KSPLICE_ID>
147 =head1 DESCRIPTION
149 B<ksplice-undo> takes as input a Ksplice identification tag, as reported by
150 L<ksplice-view(8)>, and it reverses that update within the running binary kernel.
152 =head1 OPTIONS
154 =over 8
156 =item B<--debug>
158 Reverses the update with debugging output enabled. Recommended only for
159 debugging.
161 =back
163 =head1 SEE ALSO
165 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-view(8)>
167 =head1 BUGS
169 Please report bugs to <PACKAGE_BUGREPORT>.
171 =head1 COPYRIGHT
173 Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
175 Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
176 Tim Abbott <tabbott@mit.edu>
178 This is free software and documentation. You can redistribute and/or modify it
179 under the terms of the GNU General Public License, version 2.
181 =cut