From 46a07de4800ad665502fe61bf4e9fb85c804febe Mon Sep 17 00:00:00 2001 From: Andreas Florath Date: Thu, 23 Nov 2017 19:50:31 +0000 Subject: [PATCH] Fix /dev/pts mount options handling The current implementation - as introduced in Iee44703297a15b14c715f4bfb7bae67f613aceee - has some shortcomings / bugs, like: * the 'grep' check is too sloppy * when /dev/pts is already mounted multiple times the current implementation fails: $ mount | grep devpts | sed 's/.*(\(.*\))/\1/' rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 * code duplication * Using the undocumented and non-robust output of 'mount'. This patch fixed the above problems. Change-Id: Ib0c7358772480c56d405659a6a32afd60c311686 Signed-off-by: Andreas Florath --- .../elements/yum-minimal/root.d/08-yum-chroot | 10 +++------- .../zypper-minimal/root.d/08-zypper-chroot | 10 +++------- diskimage_builder/lib/common-functions | 19 ++++++++++++------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot index 069805180..41bc251af 100755 --- a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot +++ b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot @@ -23,6 +23,8 @@ fi set -eu set -o pipefail +source $_LIB/common-functions + if [ -f ${TARGET_ROOT}/.extra_settings ] ; then . ${TARGET_ROOT}/.extra_settings fi @@ -223,13 +225,7 @@ function _install_pkg_manager { sudo mkdir -p $TARGET_ROOT/proc $TARGET_ROOT/dev $TARGET_ROOT/sys sudo mount -t proc none $TARGET_ROOT/proc sudo mount --bind /dev $TARGET_ROOT/dev -# Kernel commit https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eedf265aa003b4781de24cfed40a655a664457e6 -# introduced in v4.7 allows multiple instances of devpts. However, -# some distributions are running older kernels so we need to take -# care on what options we use to mount a new instance of devpts -# filesystem since it's not completely independent. The best thing -# to do is to simply use the existing mount options. -sudo mount -t devpts -o $(mount | grep devpts | sed 's/.*(\(.*\))/\1/') devpts $TARGET_ROOT/dev/pts +sudo mount -t devpts $(mount_dev_pts_options) devpts $TARGET_ROOT/dev/pts sudo mount -t sysfs none $TARGET_ROOT/sys # initalize rpmdb diff --git a/diskimage_builder/elements/zypper-minimal/root.d/08-zypper-chroot b/diskimage_builder/elements/zypper-minimal/root.d/08-zypper-chroot index d9a0d7260..843cf018c 100755 --- a/diskimage_builder/elements/zypper-minimal/root.d/08-zypper-chroot +++ b/diskimage_builder/elements/zypper-minimal/root.d/08-zypper-chroot @@ -24,6 +24,8 @@ fi set -eu set -o pipefail +source $_LIB/common-functions + function cleanup() { sudo umount $TARGET_ROOT/proc sudo umount $TARGET_ROOT/dev/pts @@ -87,13 +89,7 @@ sudo zypper ${ZYPPER_TARGET_OPTS} refresh sudo mkdir -p $TARGET_ROOT/proc $TARGET_ROOT/dev $TARGET_ROOT/sys sudo mount -t proc none $TARGET_ROOT/proc sudo mount --bind /dev $TARGET_ROOT/dev -# Kernel commit https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eedf265aa003b4781de24cfed40a655a664457e6 -# introduced in v4.7 allows multiple instances of devpts. However, -# some distributions are running older kernels so we need to take -# care on what options we use to mount a new instance of devpts -# filesystem since it's not completely independent. The best thing -# to do is to simply use the existing mount options. -sudo mount -t devpts -o $(mount | grep devpts | sed 's/.*(\(.*\))/\1/') devpts $TARGET_ROOT/dev/pts +sudo mount -t devpts $(mount_dev_pts_options) devpts $TARGET_ROOT/dev/pts sudo mount -t sysfs none $TARGET_ROOT/sys # Install filesystem, base and useful tools diff --git a/diskimage_builder/lib/common-functions b/diskimage_builder/lib/common-functions index 981e9c742..2244de831 100644 --- a/diskimage_builder/lib/common-functions +++ b/diskimage_builder/lib/common-functions @@ -312,17 +312,22 @@ function create_base () { mount_proc_dev_sys } +# Get mount options for mounting /dev/pts +# Kernel commit https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eedf265aa003b4781de24cfed40a655a664457e6 +# introduced in v4.7 allows multiple instances of devpts. However, +# some distributions are running older kernels so we need to take +# care on what options we use to mount a new instance of devpts +# filesystem since it's not completely independent. The best thing +# to do is to simply use the existing mount options. +function mount_dev_pts_options() { + echo "-o $(findmnt --first-only /dev/pts --noheadings --output OPTIONS)" +} + function mount_proc_dev_sys () { # supporting kernel file systems sudo mount -t proc none $TMP_MOUNT_PATH/proc sudo mount --bind /dev $TMP_MOUNT_PATH/dev - # Kernel commit https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eedf265aa003b4781de24cfed40a655a664457e6 - # introduced in v4.7 allows multiple instances of devpts. However, - # some distributions are running older kernels so we need to take - # care on what options we use to mount a new instance of devpts - # filesystem since it's not completely independent. The best thing - # to do is to simply use the existing mount options. - sudo mount -t devpts -o $(mount | grep devpts | sed 's/.*(\(.*\))/\1/') devpts $TMP_MOUNT_PATH/dev/pts + sudo mount -t devpts $(mount_dev_pts_options) devpts $TMP_MOUNT_PATH/dev/pts sudo mount -t sysfs none $TMP_MOUNT_PATH/sys }