aboutsummaryrefslogtreecommitdiff
path: root/libexec/rc/rc.d/linux
blob: 4381b62cc6607f4a49336a1e13c13a2e43ccb817 (plain) (blame)
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
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: linux
# REQUIRE: archdep
# KEYWORD: nojail

. /etc/rc.subr

name="linux"
desc="Enable Linux ABI"
rcvar="linux_enable"
start_cmd="${name}_start"
stop_cmd=":"

linux_start()
{
	local _emul_path _tmpdir
	_emul_path="$(sysctl -n compat.linux.emul_path)"

	load_kld -e 'linux(aout|elf)' linux
	case `sysctl -n hw.machine_arch` in
	amd64)
		load_kld -e 'linux64elf' linux64
		;;
	esac
	if [ -x ${_emul_path}/sbin/ldconfigDisabled ]; then
		_tmpdir=`mktemp -d -t linux-ldconfig`
		${_emul_path}/sbin/ldconfig -C ${_tmpdir}/ld.so.cache
		if ! cmp -s ${_tmpdir}/ld.so.cache ${_emul_path}/etc/ld.so.cache; then
			cat ${_tmpdir}/ld.so.cache > ${_emul_path}/etc/ld.so.cache
		fi
		rm -rf ${_tmpdir}
	fi

	# Linux uses the pre-pts(4) tty naming scheme.
	load_kld pty

	# Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
	if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then
		sysctl kern.elf64.fallback_brand=3 > /dev/null
	fi

	if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then
		sysctl kern.elf32.fallback_brand=3 > /dev/null
	fi

	if checkyesno linux_mounts_enable; then 
		mount -o nocover -t linprocfs linprocfs "${_emul_path}/proc"
		mount -o nocover -t linsysfs linsysfs "${_emul_path}/sys"
		mount -o nocover -t devfs devfs "${_emul_path}/dev"
		mount -o nocover,linrdlnk -t fdescfs fdescfs "${_emul_path}/dev/fd"
		mount -o nocover,mode=1777 -t tmpfs tmpfs "${_emul_path}/dev/shm"
	fi
}

load_rc_config $name
run_rc_command "$1"