Exit with status 66 if no changes are detected.
[ksplice.git] / ksplice-undo.in
blobc5f184825f6db276a258de182bd59b71aa2f46a0
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;
27 my $debugon = 0;
28 GetOptions(@common_options,
29 "debug" => \$debugon,
30 "debugfile=s" => \$debug) or pod2usage(1);
32 pod2usage(1) if($help || scalar(@ARGV) != 1);
33 $debugon = 1 if (defined($debug));
34 $debug = abs_path($debug) if (defined $debug);
36 my $kid = $ARGV[0];
37 $kid =~ s/^ksplice[-_]//;
38 $kid =~ s/[-_].*$//;
39 my $update = "ksplice_$kid";
40 my $nounload = runstr("lsmod") =~ m/- $/m;
42 if (!update_loaded($kid)) {
43 print "Ksplice id $kid is not present in the kernel\n";
44 exit(1);
47 chdir("/sys/module/");
48 set_debug_level($kid, $debugon);
49 my $stage = get_stage($kid);
50 if ($stage ne 'applied') {
51 print "Ksplice id $kid is not applied\n";
53 else {
54 set_stage($kid, "reversed");
57 $stage = get_stage($kid);
58 my $failed = 0;
59 $failed = 1 if ($stage ne 'reversed');
60 foreach my $module (glob("${update}_*")) {
61 if (!$nounload && runval_raw('rmmod', $module) != 0) {
62 child_error();
63 $failed = 1;
66 if ($failed == 0) {
67 set_stage($kid, "cleanup");
68 my $count = 0;
69 while (update_loaded($kid) && $count < 5) {
70 usleep(100000);
71 $count++;
74 if ($failed == 0 && -e "/sys/module/$update") {
75 if (!$nounload && runval_raw('rmmod', $update) != 0) {
76 child_error();
77 $failed = 1;
80 unless($failed == 0) {
81 my $debugfile = get_debug_output($kid, $debug);
82 print STDERR "Error undoing Ksplice update $kid:\n";
83 my $abort_cause = get_abort_cause($kid);
84 my $conflicts = get_conflicts($kid);
85 print_error($abort_cause);
86 if ($abort_cause eq 'code_busy') {
87 print $conflicts;
89 if($debugon && defined $debugfile) {
90 print("Debugging output saved to $debugfile\n");
92 die;
94 rmtree("/var/run/ksplice/updates/$kid");
95 exit(0);
97 sub print_error {
98 my ($error) = @_;
99 my %errors = (
100 "code_busy" => <<'END',
101 Ksplice has aborted the undo operation because it appears that the code that
102 you are trying to change is continuously in use by the system. More
103 specifically, Ksplice has been unable to find a moment when one or more of the
104 to-be-changed functions is not on a thread's kernel stack.
106 "module_busy" => <<'END',
107 Ksplice has aborted the undo operation because it appears that the Ksplice
108 update that you are trying to unload is in use by another module. You can find
109 out what module is using the Ksplice update using the lsmod command.
111 "unexpected_running_task" => <<'END',
112 Ksplice has aborted the undo operation because of an unexpected failure during
113 the kernel stack check. Please consider reporting a bug to PACKAGE_BUGREPORT.
115 "out_of_memory" => <<'END',
116 Ksplice has aborted the undo operation because the kernel ran out of memory.
118 "call_failed" => <<'END',
119 Ksplice has aborted the undo operation at the request of a one of the
120 pre-application hooks that were included as part of this Ksplice
121 update. This is likely the result of a bug in the patch used to
122 generate this update.
124 "unexpected" => <<'END',
125 Ksplice has aborted because of an unexpected error.
126 Please consider reporting a bug to PACKAGE_BUGREPORT.
128 "UNKNOWN" => <<'END',
129 The Ksplice kernel component has returned an error code that this version of
130 ksplice-undo does not understand.
132 "ok" => <<'END',
133 Ksplice has aborted the undo operation for unknown reasons.
134 Please consider reporting a bug to PACKAGE_BUGREPORT.
137 $error = "UNKNOWN" if (!exists $errors{$error});
138 print STDERR "\n$errors{$error}\n";
141 =head1 NAME
143 ksplice-undo - Undo a Ksplice update that has been applied to the running kernel
145 =head1 SYNOPSIS
147 B<ksplice-undo> I<KSPLICE_ID>
149 =head1 DESCRIPTION
151 B<ksplice-undo> takes as input a Ksplice identification tag, as reported by
152 L<ksplice-view(8)>, and it reverses that update within the running binary kernel.
154 =head1 OPTIONS
156 =over 8
158 =item B<--debug>
160 Reverses the update with debugging output enabled. Recommended only for
161 debugging.
163 =item B<--debugfile=>I<filename>
165 Sets the location where debugging output should be saved. Implies --debug.
167 =back
169 =head1 SEE ALSO
171 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-view(8)>
173 =head1 BUGS
175 Please report bugs to <PACKAGE_BUGREPORT>.
177 =head1 COPYRIGHT
179 Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
181 Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
182 Tim Abbott <tabbott@mit.edu>
184 This is free software and documentation. You can redistribute and/or modify it
185 under the terms of the GNU General Public License, version 2.
187 =cut