Deleted Added
sdiff udiff text old ( 187708 ) new ( 191620 )
full compact
1#!/bin/sh
2#
3# $FreeBSD: head/etc/rc.d/jail 187708 2009-01-26 12:59:11Z bz $
4#
5
6# PROVIDE: jail
7# REQUIRE: LOGIN cleanvar
8# BEFORE: securelevel
9# KEYWORD: nojail shutdown
10
11# WARNING: This script deals with untrusted data (the data and

--- 24 unchanged lines hidden (view full) ---

36 eval _rootdir=\"\$jail_${_j}_rootdir\"
37 _devdir="${_rootdir}/dev"
38 _fdescdir="${_devdir}/fd"
39 _procdir="${_rootdir}/proc"
40 eval _hostname=\"\$jail_${_j}_hostname\"
41 eval _ip=\"\$jail_${_j}_ip\"
42 eval _interface=\"\${jail_${_j}_interface:-${jail_interface}}\"
43 eval _exec=\"\$jail_${_j}_exec\"
44 eval _exec_start=\"\${jail_${_j}_exec_start:-${jail_exec_start}}\"
45
46 i=1
47 while [ true ]; do
48 eval _exec_afterstart${i}=\"\${jail_${_j}_exec_afterstart${i}:-\${jail_exec_afterstart${i}}}\"
49 [ -z "$(eval echo \"\$_exec_afterstart${i}\")" ] && break
50 i=$((i + 1))
51 done
52
53 eval _exec_stop=\"\${jail_${_j}_exec_stop:-${jail_exec_stop}}\"
54 if [ -n "${_exec}" ]; then
55 # simple/backward-compatible execution
56 _exec_start="${_exec}"
57 _exec_stop=""
58 else
59 # flexible execution
60 if [ -z "${_exec_start}" ]; then
61 _exec_start="/bin/sh /etc/rc"

--- 35 unchanged lines hidden (view full) ---

97 debug "$_j interface: $_interface"
98 debug "$_j fib: $_fib"
99 debug "$_j root: $_rootdir"
100 debug "$_j devdir: $_devdir"
101 debug "$_j fdescdir: $_fdescdir"
102 debug "$_j procdir: $_procdir"
103 debug "$_j ruleset: $_ruleset"
104 debug "$_j fstab: $_fstab"
105 debug "$_j exec start: $_exec_start"
106 debug "$_j consolelog: $_consolelog"
107
108 i=1
109 while [ true ]; do
110 eval out=\"\${_exec_afterstart${i}:-''}\"
111
112 if [ -z "$out" ]; then
113 break;
114 fi
115
116 debug "$_j exec after start #${i}: ${out}"
117 i=$((i + 1))
118 done
119
120 debug "$_j exec stop: $_exec_stop"
121 debug "$_j flags: $_flags"
122 debug "$_j consolelog: $_consolelog"
123
124 if [ -z "${_hostname}" ]; then
125 err 3 "$name: No hostname has been defined for ${_j}"
126 fi
127 if [ -z "${_rootdir}" ]; then
128 err 3 "$name: No root directory has been defined for ${_j}"

--- 421 unchanged lines hidden (view full) ---

550 else
551 info "Mounting procfs onto ${_procdir}"
552 if [ -d "${_procdir}" ] ; then
553 mount -t procfs proc "${_procdir}"
554 fi
555 fi
556 fi
557 _tmp_jail=${_tmp_dir}/jail.$$
558 eval ${_setfib} jail ${_flags} -i ${_rootdir} ${_hostname} \
559 \"${_addrl}\" ${_exec_start} > ${_tmp_jail} 2>&1
560
561 if [ "$?" -eq 0 ] ; then
562 _jail_id=$(head -1 ${_tmp_jail})
563 i=1
564 while [ true ]; do
565 eval out=\"\${_exec_afterstart${i}:-''}\"

--- 4 unchanged lines hidden (view full) ---

570
571 jexec "${_jail_id}" ${out}
572 i=$((i + 1))
573 done
574
575 echo -n " $_hostname"
576 tail +2 ${_tmp_jail} >${_consolelog}
577 echo ${_jail_id} > /var/run/jail_${_jail}.id
578 else
579 jail_umount_fs
580 jail_ips "del"
581 echo " cannot start jail \"${_jail}\": "
582 tail +2 ${_tmp_jail}
583 fi
584 rm -f ${_tmp_jail}
585 done

--- 5 unchanged lines hidden (view full) ---

591{
592 echo -n 'Stopping jails:'
593 for _jail in ${jail_list}
594 do
595 if [ -f "/var/run/jail_${_jail}.id" ]; then
596 _jail_id=$(cat /var/run/jail_${_jail}.id)
597 if [ ! -z "${_jail_id}" ]; then
598 init_variables $_jail
599 if [ -n "${_exec_stop}" ]; then
600 eval env -i /usr/sbin/jexec ${_jail_id} ${_exec_stop} \
601 >> ${_consolelog} 2>&1
602 fi
603 killall -j ${_jail_id} -TERM > /dev/null 2>&1
604 sleep 1
605 killall -j ${_jail_id} -KILL > /dev/null 2>&1
606 jail_umount_fs
607 echo -n " $_hostname"
608 fi
609 jail_ips "del"
610 rm /var/run/jail_${_jail}.id
611 else
612 echo " cannot stop jail ${_jail}. No jail id in /var/run"
613 fi
614 done
615 echo '.'
616}
617
618load_rc_config $name
619cmd="$1"
620if [ $# -gt 0 ]; then
621 shift
622fi
623if [ -n "$*" ]; then
624 jail_list="$*"
625fi
626run_rc_command "${cmd}"