Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: src/platform/cryptohome/bin/umount

Issue 2051003: Initial patch from Will. (Closed) Base URL: ssh://git@chromiumos-git/chromiumos
Patch Set: Address style nits. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/bin/bash
2 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 set -e # exit on error
7 set -E # force error handler inheritance
8 set -u # require all variables to be defined
9 trap error_handler ERR;
10
11 function error_handler() {
12 cryptohome::log "unmount failed: the system may be rebooted"
13 $sync || $true
14
15 cryptohome::log "lsof ${DEFAULT_MOUNT_POINT}: $(lsof ${DEFAULT_MOUNT_POINT})"
16 cryptohome::log "current mount table: $(mount)"
17
18 cryptohome::is_mounted && $reboot
19 cryptohome::log "unmount but the filesystem is no longer mounted"
20
21 # Make sure we aren't leaving a mess or an accessible key.
22 if cryptohome::is_opened; then
23 cryptohome::log "device mapper device still present; attempting to close"
24 cryptohome::log \
25 "lsof ${DEFAULT_MAPPER_DEVICE}: $(lsof ${DEFAULT_MAPPER_DEVICE})"
26 cryptohome::close || $reboot
27 $exit 1
28 fi
29
30 if cryptohome::attached; then
31 cryptohome::log "loop device still present; attempting to detach"
32 cryptohome::detach || $reboot
33 $exit 1
34 fi
35
36 cryptohome::log "forced unmount and cleanup successful"
37 $exit 0
38 }
39
40 function umount_main() {
41 # If we can't unmount, do it the hard way, for now.
42 local target="${1:-$DEFAULT_MOUNT_POINT}"
43 # Variables that define how long to wait for unmount to complete and the
44 # increment to check for its completion.
45 local max_delay=20
46 local current_delay=0
47 local increment=1
48
49 # Loop until we've unmounted cryptohome or have reached the $max_delay.
50 while cryptohome::is_mounted "$target" ; do
51 if [ $current_delay -ge $max_delay ] ; then
52 # If we've reached a max_delay, abort and go through reboot logic
53 cryptohome::log "Unmount max delay reached. Aborting."
54 error_handler
55 fi
56 if ! cryptohome::unmount "$target" ; then
57 cryptohome::log "Unmount error, sleeping and attempting to unmount again"
58 $sync && $sleep $increment
59 current_delay=$(( current_delay + increment ))
60 fi
61 done
62 # is_mounted ignores incognito mounts since they diverge from
63 # the actual cryptohome landscape (dm, losetup).
64 if $mount | $grep -q "^$INCOGNITO_MOUNT_NAME "; then
65 # We want all processes killed that use this mountpoint, but
66 # we also need to ensure that the user is completely gone to
67 # avoid processes persisting across mounts.
68 cryptohome::log "unmounting incognito mount"
69 $pkill -9 -u ${DEFAULT_USER} && $true &> /dev/null
70 # Since we don't have additional work after the unmount, we can
71 # do it lazily.
72 $umount -n -l "$INCOGNITO_MOUNT_NAME"
73 fi
74 }
75
76 if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
77 source "$(dirname "$0")/../lib/chromeos-cryptohome/common"
78 utils::declare_commands reboot exit sync
79 umount_main "$@"
80 fi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698