File tree 9 files changed +61
-22
lines changed
9 files changed +61
-22
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,6 @@ if [ "${SURE}" != "y" ]; then
39
39
exit 1
40
40
fi
41
41
42
- sudo umount " $OUTPUT_DIR " /* /* 2> /dev/null
43
- sudo umount /tmp/esp.* 2> /dev/null
42
+ safe_umount " $OUTPUT_DIR " /* /* 2> /dev/null
43
+ safe_umount /tmp/esp.* 2> /dev/null
44
44
sudo losetup -d /dev/loop* 2> /dev/null
Original file line number Diff line number Diff line change @@ -562,20 +562,30 @@ safe_umount_tree() {
562
562
fi
563
563
564
564
# First try to unmount in one shot to speed things up.
565
- if sudo umount -d ${mounts} ; then
565
+ if safe_umount -d ${mounts} ; then
566
566
return 0
567
567
fi
568
568
569
569
# Well that didn't work, so lazy unmount remaining ones.
570
570
mounts=$( sub_mounts " $1 " )
571
571
warn " Failed to unmount ${mounts} "
572
572
warn " Doing a lazy unmount"
573
- if ! sudo umount -d -l ${mounts} ; then
573
+ if ! safe_umount -d -l ${mounts} ; then
574
574
mounts=$( sub_mounts " $1 " )
575
575
die " Failed to lazily unmount ${mounts} "
576
576
fi
577
577
}
578
578
579
+
580
+ # Helper; all scripts should use this since it ensures our
581
+ # override of umount is used (inside the chroot, it's enforced
582
+ # via configuration; outside is the concern).
583
+ # Args are passed directly to umount; no sudo args are allowed.
584
+ safe_umount () {
585
+ sudo " ${SCRIPT_ROOT} /path-overrides/umount" " $@ "
586
+ }
587
+
588
+
579
589
get_git_id () {
580
590
git var GIT_COMMITTER_IDENT | sed -e ' s/^.*<\(\S\+\)>.*$/\1/'
581
591
}
Original file line number Diff line number Diff line change @@ -348,7 +348,7 @@ if [ -b "${FLAGS_to}" ]; then
348
348
if [ -n " ${mount_list} " ]; then
349
349
echo " Attempting to unmount any mounts on the target device..."
350
350
for i in ${mount_list} ; do
351
- if sudo umount " $i " 2>&1 > /dev/null | grep " not found" ; then
351
+ if safe_umount " $i " 2>&1 > /dev/null | grep " not found" ; then
352
352
die_notrace " $i needs to be unmounted outside the chroot"
353
353
fi
354
354
done
Original file line number Diff line number Diff line change @@ -146,8 +146,8 @@ dd if="${SRC_IMAGE}" of="${TEMP_PMBR}" bs=512 count=1
146
146
TEMP_MNT=$( mktemp -d)
147
147
TEMP_ESP_MNT=$( mktemp -d)
148
148
cleanup () {
149
- sudo umount " ${TEMP_MNT} "
150
- sudo umount " ${TEMP_ESP_MNT} "
149
+ safe_umount " ${TEMP_MNT} "
150
+ safe_umount " ${TEMP_ESP_MNT} "
151
151
rmdir " ${TEMP_MNT} " " ${TEMP_ESP_MNT} "
152
152
}
153
153
trap cleanup INT TERM EXIT
Original file line number Diff line number Diff line change 68
68
69
69
# Prepare to mount rootfs.
70
70
umount_loop () {
71
- sudo umount r || true
72
- sudo umount s || true
71
+ safe_umount r || true
72
+ safe_umount s || true
73
73
false
74
74
}
75
75
@@ -141,7 +141,7 @@ sudo cp "s/dev_image/etc/lsb-factory" "r/${LSB_FACTORY_DIR}"
141
141
142
142
# Clean up mounts.
143
143
trap - EXIT
144
- sudo umount r s
144
+ safe_umount r s
145
145
sudo rm -rf r s
146
146
147
147
# Generate an initrd fo u-boot to load.
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ get_install_vblock() {
77
77
sudo cp " $stateful_mnt /vmlinuz_hd.vblock" " $out "
78
78
sudo chown $USER " $out "
79
79
80
- sudo umount " $stateful_mnt "
80
+ safe_umount " $stateful_mnt "
81
81
rmdir " $stateful_mnt "
82
82
switch_to_strict_mode
83
83
echo " $out "
@@ -186,7 +186,7 @@ create_recovery_kernel_image() {
186
186
# safe.
187
187
sudo sed -i -e " s/cros_efi/cros_efi kern_b_hash=$kern_hash /g" \
188
188
" $efi_dir /efi/boot/grub.cfg" || true
189
- sudo umount " $efi_dir "
189
+ safe_umount " $efi_dir "
190
190
sudo losetup -a | sed ' s/^/16651 /'
191
191
sudo losetup -d " $efi_dev "
192
192
rmdir " $efi_dir "
@@ -243,7 +243,7 @@ install_recovery_kernel() {
243
243
local esp_mnt=$( mktemp -d)
244
244
sudo mount -o loop,offset=$(( esp_offset * 512 )) " $RECOVERY_IMAGE " " $esp_mnt "
245
245
sudo cp " $vmlinuz " " $esp_mnt /syslinux/vmlinuz.A" || failed=1
246
- sudo umount " $esp_mnt "
246
+ safe_umount " $esp_mnt "
247
247
rmdir " $esp_mnt "
248
248
switch_to_strict_mode
249
249
fi
@@ -322,7 +322,7 @@ maybe_resize_stateful() {
322
322
set +e
323
323
sudo mount -o loop $small_stateful $new_stateful_mnt
324
324
sudo cp " $INSTALL_VBLOCK " " $new_stateful_mnt /vmlinuz_hd.vblock"
325
- sudo umount " $new_stateful_mnt "
325
+ safe_umount " $new_stateful_mnt "
326
326
rmdir " $new_stateful_mnt "
327
327
switch_to_strict_mode
328
328
Original file line number Diff line number Diff line change @@ -85,13 +85,13 @@ unmount_image() {
85
85
" ${FLAGS_stateful_mountpt} "
86
86
fix_broken_symlinks " ${FLAGS_rootfs_mountpt} "
87
87
fi
88
- sudo umount " ${FLAGS_rootfs_mountpt} /usr/local"
89
- sudo umount " ${FLAGS_rootfs_mountpt} /var"
88
+ safe_umount " ${FLAGS_rootfs_mountpt} /usr/local"
89
+ safe_umount " ${FLAGS_rootfs_mountpt} /var"
90
90
if [[ -n " ${FLAGS_esp_mountpt} " ]]; then
91
- sudo umount " ${FLAGS_esp_mountpt} "
91
+ safe_umount " ${FLAGS_esp_mountpt} "
92
92
fi
93
- sudo umount " ${FLAGS_stateful_mountpt} "
94
- sudo umount " ${FLAGS_rootfs_mountpt} "
93
+ safe_umount " ${FLAGS_stateful_mountpt} "
94
+ safe_umount " ${FLAGS_rootfs_mountpt} "
95
95
switch_to_strict_mode
96
96
}
97
97
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Work around a bug on precise where gvfs trash goes looking in mounts
4
+ # it shouldn't, resulting in the umount failing when it shouldn't.
5
+ # See crosbug.com/23443 for the sordid details.
6
+
7
+ suppressed_dir=$( dirname " $( readlink -f " $0 " ) " )
8
+ cleaned_path=" $( echo " $PATH " | sed -e ' s+\(^\|:\)/usr/local/sbin\(:\|$\)++g' ) "
9
+ binary=" $( PATH=" ${cleaned_path} " type -P umount) "
10
+ if [ $? -ne 0 ]; then
11
+ echo " umount: command not found" >&2
12
+ exit 127
13
+ fi
14
+
15
+ for x in {1..10}; do
16
+ # umount doesn't give use a distinct exit code for device is busy; thus grep
17
+ # the output.
18
+ output=$( LC_ALL=C " ${binary} " " $@ " 2>&1 )
19
+ ret=$?
20
+ if [ ${ret} -eq 0 ] || [[ " ${output} " == * " device is busy" * ]]; then
21
+ # Nothing to do in these scenarios; either ran fine, or it failed in a non
22
+ # busy fashion.
23
+ break
24
+ fi
25
+ sleep 1
26
+ done
27
+
28
+ echo -n " ${output} " >&2
29
+ exit ${ret}
Original file line number Diff line number Diff line change 159
159
ESP_FS_DIR=$( mktemp -d /tmp/esp.XXXXXX)
160
160
cleanup () {
161
161
set +e
162
- if ! sudo umount " ${ESP_FS_DIR} " ; then
162
+ if ! safe_umount " ${ESP_FS_DIR} " ; then
163
163
# There is a race condition possible on some ubuntu setups
164
164
# with mounting and unmounting a device very quickly
165
165
# Doing a quick sleep/retry as a temporary workaround
166
166
warn " Initial unmount failed. Possibly crosbug.com/23443. Retrying"
167
167
sleep 5
168
- sudo umount " ${ESP_FS_DIR} "
168
+ safe_umount " ${ESP_FS_DIR} "
169
169
fi
170
170
if [[ -n " ${ESP_DEV} " && -z " ${ESP_DEV// \/ dev\/ loop* } " ]]; then
171
171
sudo losetup -d " ${ESP_DEV} "
@@ -211,7 +211,7 @@ if [[ "${FLAGS_arch}" = "x86" || "${FLAGS_arch}" = "amd64" ]]; then
211
211
# Install the syslinux loader on the ESP image (part 12) so it is ready when
212
212
# we cut over from rootfs booting (extlinux).
213
213
if [[ ${FLAGS_install_syslinux} -eq ${FLAGS_TRUE} ]]; then
214
- sudo umount " ${ESP_FS_DIR} "
214
+ safe_umount " ${ESP_FS_DIR} "
215
215
sudo syslinux -d /syslinux " ${ESP_DEV} "
216
216
# mount again for cleanup to free resource gracefully
217
217
sudo mount -o ro " ${ESP_DEV} " " ${ESP_FS_DIR} "
You can’t perform that action at this time.
0 commit comments