aboutsummaryrefslogtreecommitdiff
path: root/init.d/sysfs.in
blob: 257f3148fd49eedb3e6ff91a5279561ab030f7bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!@PREFIX@/sbin/runscript
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.

description="Mount the sys filesystem."

depend()
{
	keyword -prefix -vserver
}

mount_sys()
{
	grep -Eq "[[:space:]]+sysfs$" /proc/filesystems || return 1
	mountinfo -q /sys && return 0

	if [ ! -d /sys ]; then
		if ! mkdir -m 0755 /sys; then
			ewarn "Could not create /sys!"
			return 1
		fi
	fi

	ebegin "Mounting /sys"
	if ! fstabinfo --mount /sys; then
		mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys
	fi
	eend $?
}

mount_misc()
{
	# Setup Kernel Support for securityfs
	if [ -d /sys/kernel/security ] && \
		! mountinfo -q /sys/kernel/security; then
		if grep -qs securityfs /proc/filesystems; then
			ebegin "Mounting security filesystem"
			mount -n -t securityfs -o nodev,noexec,nosuid \
				securityfs /sys/kernel/security
			eend $?
		fi
	fi

	# Setup Kernel Support for debugfs
	if [ -d /sys/kernel/debug ] && ! mountinfo -q /sys/kernel/debug; then
		if grep -qs debugfs /proc/filesystems; then
			ebegin "Mounting debug filesystem"
			mount -n -t debugfs -o nodev,noexec,nosuid \
				debugfs /sys/kernel/debug
			eend $?
		fi
	fi

	# Setup Kernel Support for configfs
	if [ -d /sys/kernel/config ] && ! mountinfo -q /sys/kernel/config; then
		if grep -qs configfs /proc/filesystems; then
			ebegin "Mounting config filesystem"
			mount -n -t configfs -o  nodev,noexec,nosuid \
				configfs /sys/kernel/config
			eend $?
		fi
	fi

	# Setup Kernel Support for cgroup
	if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then
		if grep -qs cgroup /proc/filesystems; then
			ebegin "Mounting cgroup filesystem"
			mount -n -t cgroup -o  nodev,noexec,nosuid \
				cgroup /sys/fs/cgroup
			eend $?
		fi
	fi
}

start()
{
	local retval
	mount_sys
	retval=$?
	if [ $retval -eq 0 ]; then
		mount_misc
	fi
	return $retval
}