~ubuntu-branches/debian/experimental/sysvinit/experimental

« back to all changes in this revision

Viewing changes to debian/initscripts/lib/init/mount-functions.sh

  • Committer: Bazaar Package Importer
  • Author(s): Petter Reinholdtsen
  • Date: 2008-08-12 16:07:50 UTC
  • Revision ID: james.westby@ubuntu.com-20080812160750-65gpyv74vh4qr69w
Tags: 2.86.ds1-61
* Fix typo in rcS(5), proberly->properly (Closes: #484233).  Thanks to
  Julien Danjou for noticing.
* Fix typo in rcS(5), maually->manually (Closes: #493680).  Thanks to
  Xr for noticing.
* Modify runlevel detection code in invoke-rc.d to notice the
  difference between runlevels 0 and 6, and the boot runlevel, to
  make it possible to use invoke-rc.d during boot (Closes: 384509).
* Make sure to call restorecon after mounting tmpfs file systems, to
  set SELinux permissions (Closes: #493679).  Patch from Russell
  Coker.
* Move responsibility of stopping the splash screen process from
  individual init.d scripts to init.d/rc.  This make sure the
  progress calculation reflect reality, and that the splash screen
  is taken down in runlevel 1 (Closes: #431560) and that it stop
  before gdm and kdm (Closes: #422922, #489734).
* Skip error message from checkfs.sh when / is read-only.  Patch
  from Mirek Slugen (Closes: #492214).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Functions used by several mount* scripts in initscripts package
 
3
#
 
4
# Sourcer must set PATH and include /lib/init in it because
 
5
# domount() uses the custom readlink program
 
6
#
 
7
# Sourcer must also source /lib/lsb/init-functions.sh
 
8
 
 
9
# $1: directory
 
10
is_empty_dir() {
 
11
        for FILE in $1/* $1/.*
 
12
        do
 
13
                case "$FILE" in
 
14
                  "$1/.*") return 0 ;;
 
15
                  "$1/*"|"$1/."|"$1/..") continue ;;
 
16
                  *) return 1 ;;
 
17
                esac
 
18
        done
 
19
        return 0
 
20
}
 
21
 
 
22
 
 
23
selinux_enabled () {
 
24
        which selinuxenabled >/dev/null 2>&1 && selinuxenabled
 
25
}
 
26
 
 
27
 
 
28
# Called before mtab is writable to mount kernel and device file systems.
 
29
# $1: file system type
 
30
# $2: alternative file system type (or empty string if none)
 
31
# $3: mount point
 
32
# $4: mount device name
 
33
# $5... : extra mount program options
 
34
domount () {
 
35
        MTPT="$3"
 
36
        KERNEL="$(uname -s)"
 
37
        # Figure out filesystem type
 
38
        FSTYPE=
 
39
        if [ "$1" = proc ]
 
40
        then
 
41
                case "$KERNEL" in
 
42
                        Linux|GNU) FSTYPE=proc ;;
 
43
                        *FreeBSD)  FSTYPE=linprocfs ;;
 
44
                        *)         FSTYPE=procfs ;;
 
45
                esac
 
46
        elif [ "$1" = tmpfs ]
 
47
        then # always accept tmpfs, to mount /lib/init/rw before /proc
 
48
                FSTYPE=$1
 
49
        elif grep -E -qs "$1\$" /proc/filesystems
 
50
        then
 
51
                FSTYPE=$1
 
52
        elif grep -E -qs "$2\$" /proc/filesystems
 
53
        then
 
54
                FSTYPE=$2
 
55
        fi
 
56
 
 
57
        if [ ! "$FSTYPE" ]
 
58
        then
 
59
                if [ "$2" ]
 
60
                then
 
61
                        log_warning_msg "Filesystem types '$1' and '$2' are not supported. Skipping mount."
 
62
                else
 
63
                        log_warning_msg "Filesystem type '$1' is not supported. Skipping mount."
 
64
                fi
 
65
                return
 
66
        fi
 
67
 
 
68
        # We give file system type as device name if not specified as
 
69
        # an argument
 
70
        if [ "$4" ] ; then
 
71
            DEVNAME=$4
 
72
        else
 
73
            DEVNAME=$FSTYPE
 
74
        fi
 
75
 
 
76
        # Get the options from /etc/fstab.
 
77
        OPTS=
 
78
        if [ -f /etc/fstab ]
 
79
        then
 
80
                exec 9<&0 </etc/fstab
 
81
 
 
82
                while read TAB_DEV TAB_MTPT TAB_FSTYPE TAB_OPTS TAB_REST
 
83
                do
 
84
                        case "$TAB_DEV" in (""|\#*) continue ;; esac
 
85
                        [ "$MTPT" = "$TAB_MTPT" ] || continue
 
86
                        [ "$FSTYPE" = "$TAB_FSTYPE" ] || continue
 
87
                        case "$TAB_OPTS" in
 
88
                          noauto|*,noauto|noauto,*|*,noauto,*)
 
89
                                exec 0<&9 9<&-
 
90
                                return
 
91
                                ;;
 
92
                          ?*)
 
93
                                OPTS="-o$TAB_OPTS"
 
94
                                ;;
 
95
                        esac
 
96
                        break
 
97
                done
 
98
 
 
99
                exec 0<&9 9<&-
 
100
        fi
 
101
 
 
102
        if [ ! -d "$MTPT" ]
 
103
        then
 
104
                log_warning_msg "Mount point '$MTPT' does not exist. Skipping mount."
 
105
                return
 
106
        fi
 
107
 
 
108
        if mountpoint -q "$MTPT"
 
109
        then
 
110
                return # Already mounted
 
111
        fi
 
112
 
 
113
        if [ "$VERBOSE" != "no" ]; then
 
114
                is_empty_dir "$MTPT" >/dev/null 2>&1 || log_warning_msg "Files under mount point '$MTPT' will be hidden."
 
115
        fi
 
116
        mount -n -t $FSTYPE $5 $OPTS $DEVNAME $MTPT
 
117
        if [ "$FSTYPE" = "tmpfs" -a -x /sbin/restorecon ]; then
 
118
                /sbin/restorecon $MTPT
 
119
        fi
 
120
}
 
121
 
 
122
#
 
123
# Preserve /var/run and /var/lock mountpoints
 
124
#
 
125
pre_mountall ()
 
126
{
 
127
        # We may end up mounting something over top of /var, either directly
 
128
        # or because /var is a symlink to something that's mounted.  So keep
 
129
        # copies of the /var/run and /var/lock mounts elsewhere on the root
 
130
        # filesystem so they can be moved back.
 
131
        if [ yes = "$RAMRUN" ] ; then
 
132
                mkdir /lib/init/rw/var.run
 
133
                mount -n --bind /var/run /lib/init/rw/var.run
 
134
        fi
 
135
        if [ yes = "$RAMLOCK" ] ; then
 
136
                mkdir /lib/init/rw/var.lock
 
137
                mount -n --bind /var/lock /lib/init/rw/var.lock
 
138
        fi
 
139
}
 
140
 
 
141
#
 
142
# Restore /var/run and /var/lock mountpoints if something was mounted
 
143
# as /var/.  Avoid mounting them back over themselves if nothing was
 
144
# mounted as /var/ by checking if /var/run/ and /var/lock/ are still
 
145
# mount points.  Enabling RAMRUN and RAMLOCK while listing /var/run or
 
146
# /var/lock in /etc/fstab is not supported.
 
147
#
 
148
post_mountall ()
 
149
{
 
150
        if [ yes = "$RAMRUN" ] ; then
 
151
                [ -d /var/run ] || mkdir /var/run
 
152
                if mountpoint -q /var/run ; then
 
153
                        umount /lib/init/rw/var.run
 
154
                else
 
155
                        mount -n --move /lib/init/rw/var.run /var/run
 
156
                fi
 
157
                rmdir /lib/init/rw/var.run
 
158
        fi
 
159
        if [ yes = "$RAMLOCK" ] ; then
 
160
                [ -d /var/lock ] || mkdir /var/lock
 
161
                if mountpoint -q /var/lock ; then
 
162
                        umount /lib/init/rw/var.lock
 
163
                else
 
164
                        mount -n --move /lib/init/rw/var.lock /var/lock
 
165
                fi
 
166
                rmdir /lib/init/rw/var.lock
 
167
        fi
 
168
}