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