1#!/bin/sh 2# 3# $FreeBSD$ 4# 5 6# PROVIDE: linux 7# REQUIRE: archdep 8# KEYWORD: nojail 9 10. /etc/rc.subr 11 12name="linux" 13desc="Enable Linux ABI" 14rcvar="linux_enable" 15start_cmd="${name}_start" 16stop_cmd=":" 17 18unmounted() 19{ 20 [ `stat -f "%d" "$1"` == `stat -f "%d" "$1/.."` -a \ 21 `stat -f "%i" "$1"` != `stat -f "%i" "$1/.."` ] 22} 23 24linux_start() 25{ 26 local _emul_path _tmpdir 27 28 load_kld -e 'linux(aout|elf)' linux 29 case `sysctl -n hw.machine_arch` in 30 amd64) 31 load_kld -e 'linux64elf' linux64 32 ;; 33 esac 34 if [ -x /compat/linux/sbin/ldconfigDisabled ]; then 35 _tmpdir=`mktemp -d -t linux-ldconfig` 36 /compat/linux/sbin/ldconfig -C ${_tmpdir}/ld.so.cache 37 if ! cmp -s ${_tmpdir}/ld.so.cache /compat/linux/etc/ld.so.cache; then 38 cat ${_tmpdir}/ld.so.cache > /compat/linux/etc/ld.so.cache 39 fi 40 rm -rf ${_tmpdir} 41 fi 42 43 # Linux uses the pre-pts(4) tty naming scheme. 44 load_kld pty 45 46 # Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX. 47 if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then 48 sysctl kern.elf64.fallback_brand=3 > /dev/null 49 fi 50 51 if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then 52 sysctl kern.elf32.fallback_brand=3 > /dev/null 53 fi 54 55 if checkyesno linux_mounts_enable; then 56 _emul_path="/compat/linux" 57 unmounted "${_emul_path}/proc" && mount -t linprocfs linprocfs "${_emul_path}/proc" 58 unmounted "${_emul_path}/sys" && mount -t linsysfs linsysfs "${_emul_path}/sys" 59 unmounted "${_emul_path}/dev" && mount -t devfs devfs "${_emul_path}/dev" 60 unmounted "${_emul_path}/dev/fd" && mount -o linrdlnk -t fdescfs fdescfs "${_emul_path}/dev/fd" 61 unmounted "${_emul_path}/dev/shm" && mount -o mode=1777 -t tmpfs tmpfs "${_emul_path}/dev/shm" 62 true 63 fi 64} 65 66load_rc_config $name 67run_rc_command "$1" 68