On Sat, 2016-06-04 at 11:17 +0200, Aurelien Jarno wrote: > On 2016-05-26 22:50, Ben Hutchings wrote: > > I'm inclined to add a check to linux-image prerm scripts that skips the > > question when DEBIAN_FRONTEND=noninteractive. > > > > Aside from that, I might add the check for a chroot or container, if > > there's a simple way to do that. > > You can use the command ischroot from the debianutils package.
Why would I want to add a dependency on that? It only solves half the problem, anyway I ended up with: # 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]); } But I'm preparing a rewrite of the maintainer scripts, not using Perl, and the implementation as a shell script is even shorter: # Are we in a container? Check for $container in pid 1's environment. in_container() { grep -qz '^container=' /proc/1/environ } # Are we in in a chroot? Compare root device and inode numbers with pid 1. in_chroot() { test "$(stat -L -c %d:%i /)" != "$(stat -L -c %d:%i /proc/1/root)" } Ben. -- Ben Hutchings The most exhausting thing in life is being insincere. - Anne Morrow Lindberg
signature.asc
Description: This is a digitally signed message part