80853f5dbc
Previously we checked if /proc was alive by reading /proc/uptime twice with a 1 second sleep between calls, so that it had time to update. This got a complaint of an entire 1 second delay, so we improve the check to be much faster without sleep. We cannot continue to use /proc/uptime as it only has a 10ms resolution. X-Gentoo-Bug: 348416 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=348416 Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
111 lines
3.1 KiB
Plaintext
111 lines
3.1 KiB
Plaintext
#!@SHELL@
|
|
# Copyright (c) 1999-2007 Gentoo Foundation
|
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
|
|
|
# This basically mounts $RC_SVCDIR as a ramdisk.
|
|
# The tricky part is finding something our kernel supports
|
|
# tmpfs and ramfs are easy, so force one or the other.
|
|
svcdir_restorecon()
|
|
{
|
|
local rc=0
|
|
if [ -x /usr/sbin/selinuxenabled -a -c /selinux/null ] &&
|
|
selinuxenabled; then
|
|
restorecon $RC_SVCDIR
|
|
rc=$?
|
|
fi
|
|
return $rc
|
|
}
|
|
|
|
mount_svcdir()
|
|
{
|
|
# mount from fstab if we can
|
|
fstabinfo --mount "$RC_SVCDIR" && return 0
|
|
|
|
local fs= fsopts="-o rw,noexec,nodev,nosuid"
|
|
local svcsize=${rc_svcsize:-1024}
|
|
|
|
# Some buggy kernels report tmpfs even when not present :(
|
|
if grep -Eq "[[:space:]]+tmpfs$" /proc/filesystems; then
|
|
local tmpfsopts="${fsopts},mode=755,size=${svcsize}k"
|
|
mount -n -t tmpfs $tmpfsopts rc-svcdir "$RC_SVCDIR"
|
|
if [ $? -eq 0 ]; then
|
|
svcdir_restorecon
|
|
[ $? -eq 0 ] && return 0
|
|
fi
|
|
fi
|
|
|
|
if grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
|
|
fs="ramfs"
|
|
# ramfs has no special options
|
|
elif [ -e /dev/ram0 ] \
|
|
&& grep -Eq "[[:space:]]+ext2$" /proc/filesystems; then
|
|
devdir="/dev/ram0"
|
|
fs="ext2"
|
|
dd if=/dev/zero of="$devdir" bs=1k count="$svcsize"
|
|
mkfs -t "$fs" -i 1024 -vm0 "$devdir" "$svcsize"
|
|
else
|
|
echo
|
|
eerror "OpenRC requires tmpfs, ramfs or a ramdisk + ext2"
|
|
eerror "compiled into the kernel"
|
|
echo
|
|
return 1
|
|
fi
|
|
|
|
mount -n -t "$fs" $fsopts rc-svcdir "$RC_SVCDIR"
|
|
if [ $? -eq 0 ]; then
|
|
svcdir_restorecon
|
|
[ $? -eq 0 ] && return 0
|
|
fi
|
|
}
|
|
|
|
. "$RC_LIBEXECDIR"/sh/functions.sh
|
|
[ -r /etc/rc.conf ] && . /etc/rc.conf
|
|
|
|
# By default VServer already has /proc mounted, but OpenVZ does not!
|
|
# However, some of our users have an old proc image in /proc
|
|
# NFC how they managed that, but the end result means we have to test if
|
|
# /proc actually works or not. We to this by comparing two reads of
|
|
# /proc/self/stat. They will not match, because at least the minor fault count
|
|
# field (field 10) should have changed.
|
|
#
|
|
# We can use any file here that fills the following requirements:
|
|
# - changes between sequential reads
|
|
# - is world-readable (not blocked in hardened kernel)
|
|
# - Is only a single line (ergo entire check is doable with no forks)
|
|
mountproc=true
|
|
f=/proc/self/stat
|
|
if [ -e $f ]; then
|
|
exec 9<$f ; read a <&9 ; exec 9<&-
|
|
exec 9<$f ; read b <&9 ; exec 9<&-
|
|
if [ "$a" = "$b" ]; then
|
|
eerror "You have cruft in /proc that should be deleted"
|
|
else
|
|
einfo "/proc is already mounted, skipping"
|
|
mountproc=false
|
|
fi
|
|
fi
|
|
unset a b f
|
|
|
|
if $mountproc; then
|
|
procfs="proc"
|
|
[ "$RC_UNAME" = "GNU/kFreeBSD" ] && proc="linprocfs"
|
|
ebegin "Mounting /proc"
|
|
if ! fstabinfo --mount /proc; then
|
|
mount -n -t "$procfs" -o noexec,nosuid,nodev proc /proc
|
|
fi
|
|
eend $?
|
|
fi
|
|
|
|
# Try to mount xenfs as early as possible, otherwise rc_sys() will always
|
|
# return RC_SYS_XENU and will think that we are in a domU while it's not.
|
|
if grep -Eq "[[:space:]]+xenfs$" /proc/filesystems; then
|
|
ebegin "Mounting xenfs"
|
|
if ! fstabinfo --mount /proc/xen; then
|
|
mount -n -t xenfs xenfs /proc/xen -o nosuid,nodev,noexec
|
|
fi
|
|
eend $?
|
|
fi
|
|
|
|
. "$RC_LIBEXECDIR"/sh/init-common-post.sh
|