/[baselayout]/trunk/sh/rc-mount.sh
Gentoo

Contents of /trunk/sh/rc-mount.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2719 - (show annotations) (download) (as text)
Wed May 30 15:24:21 2007 UTC (11 years, 10 months ago) by uberlord
File MIME type: text/x-sh
File size: 1960 byte(s)
Call umount with LC_ALL=C so that we can umount /usr
1 # Copyright 2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # bool do_unmount(char *cmd, char *no_unmounts, char *nodes, char *fslist)
5 # Handy function to handle all our unmounting needs
6 # find-mount is a C program to actually find our mounts on our supported OS's
7 do_unmount() {
8 local cmd="$1" retval=0 retry=
9 local f_opts="-m -c" f_kill="-s " mnt=
10 if [ "${RC_UNAME}" = "Linux" ] ; then
11 f_opts="-m"
12 f_kill="-"
13 fi
14
15 local mnts="$(mountinfo ${2:+--skip-regex} $2 ${3:+--node-regex} $3 ${4:+--fstype-regex} $4 --reverse \
16 | sed -e "s/'/'\\\\''/g" -e "s/^/'/g" -e "s/$/'/g")"
17 eval set -- ${mnts}
18 for mnt in "$@" ; do
19 case "${cmd}" in
20 umount*)
21 # If we're using the mount (probably /usr) then don't unmount us
22 local pids="$(fuser ${f_opts} "${mnt}" 2>/dev/null)"
23 case " ${pids} " in
24 *" $$ "*)
25 ewarn "We are using ${mnt}, not unmounting"
26 continue
27 ;;
28 esac
29 ebegin "Unmounting ${mnt}"
30 ;;
31 *)
32 ebegin "Remounting ${mnt}"
33 ;;
34 esac
35
36 retry=3
37 while ! LC_ALL=C ${cmd} "${mnt}" 2>/dev/null ; do
38 # Don't kill if it's us (/ and possibly /usr)
39 local pids="$(fuser ${f_opts} "${mnt}" 2>/dev/null)"
40 case " ${pids} " in
41 *" $$ "*) retry=0 ;;
42 " ") eend 1 "in use but fuser finds nothing"; retry=0 ;;
43 *)
44 local sig="KILL"
45 [ ${retry} -gt 0 ] && sig="TERM"
46 fuser ${f_kill}${sig} -k ${f_opts} "${mnt}" \
47 >/dev/null 2>/dev/null
48 sleep 1
49 retry=$((${retry} - 1))
50 ;;
51 esac
52
53 # OK, try forcing things
54 if [ ${retry} -le 0 ] ; then
55 local extra_opts="-f"
56 case "${cmd}" in
57 mount*)
58 # Silly reiserfs helper blocks us, so bypass it
59 [ "${RC_UNAME}" = "Linux" ] && extra_opts="-i"
60 ;;
61 esac
62 ${cmd} ${extra_opts} "${mnt}" || retry=-999
63 break
64 fi
65 done
66 if [ ${retry} -eq -999 ] ; then
67 eend 1
68 retval=1
69 else
70 eend 0
71 fi
72 done
73 return ${retval}
74 }
75
76 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20