From 6c5234e162319f007e9fce03a8b50bd2a3a12c46 Mon Sep 17 00:00:00 2001 From: Matthew Thode Date: Tue, 20 Dec 2016 21:49:25 -0600 Subject: [PATCH] Fix Gentoo builds on Ubuntu 16.04 Xenial hosts Xenial's bind of /dev into the chroot includes /dev/shm which is in use by the host. An alternitive fix for this would be to use rbind to recursivly bind mount /dev instead of just the base bind of /dev Change-Id: I2c0f70afd1e82dd52a522f0dd2b3ea618b30b6c6 --- elements/gentoo/bin/install-packages | 34 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/elements/gentoo/bin/install-packages b/elements/gentoo/bin/install-packages index f0a4bf49..a059bc78 100755 --- a/elements/gentoo/bin/install-packages +++ b/elements/gentoo/bin/install-packages @@ -33,15 +33,25 @@ function show_options { } function fix_shm { + # make /dev/shm dir if it doesn't exist + # mount tmpfs and chown it + # existing programs could be using /dev/shm + # This means it cannot be moved or backed + # up as a copy easily. The only remaining + # option is to move the link if it exists + # as a link. Existing programs will still + # hold the file handle of the original + # location open and new programs can use + # the fixed /dev/shm. if [[ "${RUN_ONCE_SHM}" == '1' ]]; then - if [[ -L /dev/shm.orig ]]; then - rm /dev/shm.orig + if [[ ! -d /dev/shm ]]; then + if [[ ! -e /dev/shm ]]; then + if [[ -L /dev/shm ]]; then + mv /dev/shm /dev/shm.orig + fi + mkdir /dev/shm + fi fi - if [[ -d /dev/shm.orig ]]; then - rm -Rf /dev/shm.orig - fi - mv /dev/shm /dev/shm.orig - mkdir /dev/shm mount -t tmpfs none /dev/shm chmod 1777 /dev/shm RUN_ONCE_SHM='0' @@ -49,10 +59,16 @@ function fix_shm { } function unfix_shm { + # unmount tmpfs + # care about anything still using it if [[ "${RUN_ONCE_SHM}" == '0' ]]; then umount /dev/shm - rmdir /dev/shm - mv /dev/shm.orig /dev/shm + if fuser /dev/shm; then + rmdir /dev/shm + fi + if [[ -e /dev/shm.orig ]]; then + mv /dev/shm.orig /dev/shm + fi fi }