[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#872577: debootstrap: Handle existing /dev



Ben Hildred <42656e@gmail.com> writes:

> On Sun, Aug 20, 2017 at 3:25 AM, Ansgar Burchardt <ansgar@debian.org> wrote:
>
>> Dan Nicholson writes:
>> > On Fri, Aug 18, 2017 at 2:48 PM, Henrique de Moraes Holschuh
>> > <hmh@debian.org> wrote:
>> >> Wouldn't it be more straigthforward to "test -e || mknod" ?
>> >
>> > I definitely considered that, but it seemed more noisy to the code to
>> > add a conditional for every call. But I'd be fine reworking to that
>> > approach if that's more acceptable, though.
>>
>> You can always introduce a `mknod_if_not_exists` function or so.  Though
>> I'm not sure this is worth here (the name is so long the `test -e` is
>> almost shorter).
>>
>> Ansgar
>>
>>
> function mknod-e () {
>     [ -e "$1" ] || mknod "$@"
> }

$1 for mknod in this case is liable to be '-m'

The attached patch might satisfy the quest for neatness.

One could instead call the function something like
ensure-exists-in-target and leave the /dev/'s on all the filenames, if
that were considered clearer.

Cheers, Phil.

Attachment: signature.asc
Description: PGP signature

>From 28f460d35d8925442ce5a63c45b51d04a0db37dd Mon Sep 17 00:00:00 2001
From: Philip Hands <phil@hands.com>
Date: Sun, 20 Aug 2017 23:48:34 +0200
Subject: [PATCH] in setup_devices_simple(), only create devices that do not
 yet exist

---
 functions | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/functions b/functions
index 3cfa0d4..6c40ec7 100644
--- a/functions
+++ b/functions
@@ -1162,18 +1162,23 @@ setup_dynamic_devices () {
 }
 
 setup_devices_simple () {
+	function ensure-exists-dev() {
+		local path="$TARGET/dev/$1" ; shift
+		[ -e "$path" ] || mknod -m 666 $path "$@"
+	}
+
 	# The list of devices that can be created in a container comes from
 	# src/core/cgroup.c in the systemd source tree.
-	mknod -m 666 $TARGET/dev/null	c 1 3
-	mknod -m 666 $TARGET/dev/zero	c 1 5
-	mknod -m 666 $TARGET/dev/full	c 1 7
-	mknod -m 666 $TARGET/dev/random	c 1 8
-	mknod -m 666 $TARGET/dev/urandom	c 1 9
-	mknod -m 666 $TARGET/dev/tty	c 5 0
+	ensure-exists-dev null		c 1 3
+	ensure-exists-dev zero		c 1 5
+	ensure-exists-dev full		c 1 7
+	ensure-exists-dev random	c 1 8
+	ensure-exists-dev urandom	c 1 9
+	ensure-exists-dev tty		c 5 0
 	mkdir $TARGET/dev/pts/ $TARGET/dev/shm/
 	# Inside a container, we might not be allowed to create /dev/ptmx.
 	# If not, do the next best thing.
-	if ! mknod -m 666 $TARGET/dev/ptmx c 5 2; then
+	if ! ensure-exists-dev ptmx c 5 2; then
 		warning MKNOD "Could not create /dev/ptmx, falling back to symlink. This chroot will require /dev/pts mounted with ptmxmode=666"
 		ln -s pts/ptmx $TARGET/dev/ptmx
 	fi
-- 
2.11.0

-- 
|)|  Philip Hands  [+44 (0)20 8530 9560]  HANDS.COM Ltd.
|-|  http://www.hands.com/    http://ftp.uk.debian.org/
|(|  Hugo-Klemm-Strasse 34,   21075 Hamburg,    GERMANY

Reply to: