summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Gilligan <gilligan@vyatta.com>2010-01-25 15:42:48 -0800
committerBob Gilligan <gilligan@vyatta.com>2010-01-25 15:42:48 -0800
commit255541f16db12d5295cb81287021231096a42ab6 (patch)
treeccd849a45f95721cdd403474dd32df262460299d
parent232d94d3f92efdcb9f5e80ac77cfe5171b52adc9 (diff)
downloadvyatta-op-255541f16db12d5295cb81287021231096a42ab6.tar.gz
vyatta-op-255541f16db12d5295cb81287021231096a42ab6.zip
Bugfix 5238: Prevent the running image from being deleted
In order to prevent the running image from being deleted, we now get the image name of the running system from the kernel boot path given by /proc/cmdline. Since the menu of names of images to delete comes from the grub config file, this is guranteed to exactly match the grub entry that was used to boot. Also fix the help text for "delete system image" command.
-rwxr-xr-xscripts/vyatta-boot-image.pl26
-rw-r--r--templates/delete/system/image/node.tag/node.def2
2 files changed, 13 insertions, 15 deletions
diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl
index c3040b4..127177d 100755
--- a/scripts/vyatta-boot-image.pl
+++ b/scripts/vyatta-boot-image.pl
@@ -286,21 +286,19 @@ sub select_by_name {
# Returns the version string of the currently running system.
#
sub curVer {
- my ($fd, $ver) = (undef, undef);
-
- my $image_boot = `grep -e '^unionfs / unionfs.*squashfs=ro' /proc/mounts`;
- if ($image_boot ne "") {
- open($fd, '<', $VER_FILE) or return undef;
- while (<$fd>) {
- next if (!(/^Version\s+:\s+(\S+)$/));
- $ver = $1;
- last;
- }
- close($fd);
- } else {
- $ver = $OLD_IMG_VER_STR;
+ my $vers = `awk '{print \$1}' /proc/cmdline`;
+
+ # In an image-booted system, the image name is the directory name
+ # directory under "/boot" in the pathname of the kernel we booted.
+ $vers =~ s/BOOT_IMAGE=\/boot\///;
+ $vers =~ s/\/?vmlinuz.*\n$//;
+
+ # In a non-image system, the kernel resides directly under "/boot".
+ # No second-level directory means that $vers will be null.
+ if ($vers eq "") {
+ $vers = $OLD_IMG_VER_STR;
}
- return $ver;
+ return $vers;
}
# Deletes all of the files belonging to the disk-based non-image
diff --git a/templates/delete/system/image/node.tag/node.def b/templates/delete/system/image/node.tag/node.def
index 2c26bf4..403bd80 100644
--- a/templates/delete/system/image/node.tag/node.def
+++ b/templates/delete/system/image/node.tag/node.def
@@ -1,4 +1,4 @@
-help: Default boot image name
+help: Name of image image to delete
allowed:
local -a images ;