linux-image: prerm: Ignore version of running kernel inside a container or chroot

This commit is contained in:
Ben Hutchings 2016-05-26 23:27:56 +01:00
parent 49b5fbab50
commit 9f4d29bb04
2 changed files with 26 additions and 1 deletions

2
debian/changelog vendored
View File

@ -24,6 +24,8 @@ linux (4.6-1~exp2) UNRELEASED; urgency=medium
* linux-image: Add workaround for bug #817083 in debconf
* linux-image: prerm: Allow removal of running kernel if we can't ask debconf
questions (Closes: #825423)
* linux-image: prerm: Ignore version of running kernel inside a container or
chroot
[ Aurelien Jarno ]
* [mips64{,el}] Set CPU to MIPS64 R2.

View File

@ -4,6 +4,7 @@ use strict;
use warnings;
use POSIX ();
use Debconf::Client::ConfModule qw(:all);
use FileHandle;
version('2.0');
my $capb=capb("backup");
@ -43,9 +44,31 @@ if (-r "$CONF_LOC" && -f "$CONF_LOC" ) {
}
# Are we in a container? Check for $container in pid 1's environment.
sub in_container {
my $res = 0;
if (my $fh = new FileHandle('/proc/1/environ', 'r')) {
local $/ = "\0";
$res = grep(/^container=/, <$fh>);
close($fh);
}
return $res;
}
# Are we in in a chroot? Compare root device and inode numbers with pid 1.
sub in_chroot {
my @my_root_st = stat('/');
my @pid1_root_st = stat('/proc/1/root');
return @my_root_st && @pid1_root_st &&
($my_root_st[0] != $pid1_root_st[0] || $my_root_st[1] != $pid1_root_st[1]);
}
# Check to see if we are trying to remove a running kernel.
chop($running=`uname -r`);
if ($running eq $version) {
if (!in_container() && !in_chroot() && $running eq $version) {
# If we can ask debconf questions, ask whether that's intended
# and abort if not.
if (exists($ENV{'DEBIAN_FRONTEND'}) &&