From a927ebd931418af32b37f71d8b9037ae30a3d658 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 11 May 2023 16:58:28 +0200 Subject: [PATCH 4/4] alpine: only create missing device node Avoid error out if some of the device nodes exists --- templates/lxc-alpine.in | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in index 8e71cc0..45ffc6f 100644 --- a/templates/lxc-alpine.in +++ b/templates/lxc-alpine.in @@ -290,19 +290,33 @@ install_packages() { --update-cache --initdb add $packages } +_mknod() { + while getopts "m:" opt; do + case $opt in + m) MODE="-m $OPTARG";; + \?) return 1;; + esac + done + shift $((OPTIND - 1)) + + test -c "$1" && return 0 # device exists + test -f "$1" && rm -f "$1" # device is a regular file + mknod $MODE $@ +} + make_dev_nodes() { mkdir -p -m 755 dev/pts mkdir -p -m 1777 dev/shm local i; for i in $(seq 0 4); do - mknod -m 620 dev/tty$i c 4 $i + _mknod -m 620 dev/tty$i c 4 $i chown 0:5 dev/tty$i # root:tty done - mknod -m 666 dev/tty c 5 0 + _mknod -m 666 dev/tty c 5 0 chown 0:5 dev/tty # root:tty - mknod -m 620 dev/console c 5 1 - mknod -m 666 dev/ptmx c 5 2 + _mknod -m 620 dev/console c 5 1 + _mknod -m 666 dev/ptmx c 5 2 chown 0:5 dev/ptmx # root:tty } -- 2.40.1