diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 6683004832..86c7f6116d 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -261,13 +261,6 @@ setup_env() { disown $! fi - # Turn off automounting of external media when we enter the chroot by - # stopping the gvfs-gdu-volume-monitor and gvfsd-trash daemons. This is - # currently the most reliable way to disable automounting. - # See https://bugzilla.gnome.org/show_bug.cgi?id=677648 - sudo killall -STOP -r '^gvfs-gdu-volume.*$|^gvfsd-trash$' 2>/dev/null \ - || true - debug "Mounting chroot environment." MOUNT_CACHE=$(echo $(awk '{print $2}' /proc/mounts)) mount_queue_init @@ -394,6 +387,22 @@ setup_env() { warn "-- Note: modprobe fuse failed. gmergefs will not work" fi + # Turn off automounting of external media when we enter the + # chroot; thus we don't have to worry about being able to unmount + # from inside. + if SAVED_PREF=$(gconftool-2 -g ${AUTOMOUNT_PREF} 2>/dev/null); then + if [ "${SAVED_PREF}" != "false" ]; then + if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then + warn "-- Note: USB sticks may be automounted by your host OS." + warn "-- Note: If you plan to burn bootable media, you may need to" + warn "-- Note: unmount these devices manually, or run image_to_usb.sh" + warn "-- Note: outside the chroot." + fi + fi + fi + # Always write the temp file so we can read it when exiting + echo "${SAVED_PREF:-false}" > "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}" + # Fix permissions on ccache tree. If this is a fresh chroot, then they # might not be set up yet. Or if the user manually `rm -rf`-ed things, # we need to reset it. Otherwise, gcc itself takes care of fixing things @@ -505,6 +514,12 @@ teardown_env() { # Remove any dups from lock file while installing new one sort -u -n "$TMP_LOCKFILE" > "$LOCKFILE" + SAVED_PREF=$(<"${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}") + if [ "${SAVED_PREF}" != "false" ]; then + gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \ + warn "could not re-set your automount preference." + fi + if [ -s "$LOCKFILE" ]; then debug "At least one other pid is running in the chroot, so not" debug "tearing down env." @@ -531,10 +546,6 @@ teardown_env() { debug "Unmounting chroot environment." safe_umount_tree "${MOUNTED_PATH}/" - - # Now that we've exited the chroot, allow automounting again. - sudo killall -CONT -r '^gvfs-gdu-volume.*$|^gvfsd-trash$' 2>/dev/null \ - || true fi ) 200>>"$LOCKFILE" || die "teardown_env failed" } diff --git a/update_bootloaders.sh b/update_bootloaders.sh index 5aa9b9326b..681f4935eb 100755 --- a/update_bootloaders.sh +++ b/update_bootloaders.sh @@ -161,16 +161,19 @@ fi ESP_FS_DIR=$(mktemp -d /tmp/esp.XXXXXX) cleanup() { - local failed=() - if [[ -n "${ESP_FS_DIR}" ]]; then - sudo umount "${ESP_FS_DIR}" && rm -rf "${ESP_FS_DIR}" || failed+=( umount ) + set +e + if ! sudo umount "${ESP_FS_DIR}"; then + # There is a race condition possible on some ubuntu setups + # with mounting and unmounting a device very quickly + # Doing a quick sleep/retry as a temporary workaround + warn "Initial unmount failed. Possibly crosbug.com/23443. Retrying" + sleep 5 + sudo umount "${ESP_FS_DIR}" fi if [[ -n "${ESP_DEV}" && -z "${ESP_DEV//\/dev\/loop*}" ]]; then - sudo losetup -d "${ESP_DEV}" || failed+=( losetup ) - fi - if [[ -n "${failed[*]}" ]]; then - die "Cleanup failed in ${failed[*]}" + sudo losetup -d "${ESP_DEV}" fi + rm -rf "${ESP_FS_DIR}" } trap cleanup EXIT sudo mount "${ESP_DEV}" "${ESP_FS_DIR}" @@ -212,9 +215,9 @@ if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then # we cut over from rootfs booting (extlinux). if [[ ${FLAGS_install_syslinux} -eq ${FLAGS_TRUE} ]]; then sudo umount "${ESP_FS_DIR}" - rm -rf "${ESP_FS_DIR}" - ESP_FS_DIR= sudo syslinux -d /syslinux "${ESP_DEV}" + # mount again for cleanup to free resource gracefully + sudo mount -o ro "${ESP_DEV}" "${ESP_FS_DIR}" fi elif [[ "${FLAGS_arch}" = "arm" ]]; then # Copy u-boot script to ESP partition