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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2771 - (show annotations) (download) (as text)
Wed Jul 11 17:27:46 2007 UTC (7 years, 5 months ago) by uberlord
File MIME type: text/x-sh
File size: 1902 byte(s)
Don't unmount network filesystems in localmount or halt.sh, #175602.
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, char *no_fslist)
5 # Handy function to handle all our unmounting needs
6 # mountinfo 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-point-regex} $2 ${3:+--node-regex} $3 ${4:+--fstype-regex} $4 ${5:+--skip-fstype-regex} $5 \
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 case "${cmd}" in
56 umount*)
57 LC_ALL=C ${cmd} -f "${mnt}" || retry=-999
58 ;;
59 *)
60 retry=-999
61 ;;
62 esac
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