From 3ad6f56a5a4085844d1cef8ecdb746c5cf895d69 Mon Sep 17 00:00:00 2001 From: Hiroki Sato Date: Mon, 21 Oct 2013 08:49:46 +0000 Subject: [PATCH] - Fix jail_parallel_start="YES". - Fix ip[46].addr when interface parameter is not defined. Spotted by: rpaulo --- etc/rc.d/jail | 84 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/etc/rc.d/jail b/etc/rc.d/jail index e2ee380d9a95..fb91aaff821f 100755 --- a/etc/rc.d/jail +++ b/etc/rc.d/jail @@ -132,7 +132,9 @@ parse_options() # _confwarn=1 if [ -r "$jail_conf" -o -r "$_jconf" ]; then - warn "$_conf is created and used for jail $_j." + if ! checkyesno jail_parallel_start; then + warn "$_conf is created and used for jail $_j." + fi fi /usr/bin/install -m 0644 -o root -g wheel /dev/null $_conf || return 1 @@ -367,10 +369,10 @@ jail_handle_ips_option() # Append address to list of addresses for the jail command. case $_type in inet) - echo " ip4.addr += \"${_iface}|${_addr}${_mask}\";" + echo " ip4.addr += \"${_iface:+${_iface}|}${_addr}${_mask}\";" ;; inet6) - echo " ip6.addr += \"${_iface}|${_addr}${_mask}\";" + echo " ip6.addr += \"${_iface:+${_iface}|}${_addr}${_mask}\";" need_dad_wait=1 ;; esac @@ -418,7 +420,7 @@ jail_status() jail_start() { - local _j _jid _jn + local _j _jid _jn _jl if [ $# = 0 ]; then return @@ -446,30 +448,62 @@ jail_start() return ;; esac - for _j in $@; do - _j=$(echo $_j | tr /. _) - parse_options $_j || continue + if checkyesno jail_parallel_start; then + # + # Start jails in parallel and then check jail id when + # jail_parallel_start is YES. + # + _jl= + for _j in $@; do + _j=$(echo $_j | tr /. _) + parse_options $_j || continue - eval rc_flags=\${jail_${_j}_flags:-$jail_flags} - eval command=\${jail_${_j}_program:-$jail_program} - if checkyesno jail_parallel_start; then - command_args="-i -f $_conf -c $_j &" - else + _jl="$_jl $_j" + eval rc_flags=\${jail_${_j}_flags:-$jail_flags} + eval command=\${jail_${_j}_program:-$jail_program} command_args="-i -f $_conf -c $_j" - fi - _tmp=`mktemp -t jail` || exit 3 - if $command $rc_flags $command_args \ - >> $_tmp 2>&1 /dev/null 2>&1 /var/run/jail_${_j}.id - else - rm -f /var/run/jail_${_j}.id - echo " cannot start jail \"${_hostname:-${_j}}\": " - cat $_tmp - fi - rm -f $_tmp - done + if _jid=$($jail_jls -n -j $_j | tr " " "\n" | \ + grep ^jid=); then + echo "${_jid#jid=}" > /var/run/jail_${_j}.id + else + rm -f /var/run/jail_${_j}.id + echo " cannot start jail " \ + "\"${_hostname:-${_j}}\": " + fi + done + else + # + # Start jails one-by-one when jail_parallel_start is NO. + # + for _j in $@; do + _j=$(echo $_j | tr /. _) + parse_options $_j || continue + + eval rc_flags=\${jail_${_j}_flags:-$jail_flags} + eval command=\${jail_${_j}_program:-$jail_program} + command_args="-i -f $_conf -c $_j" + _tmp=`mktemp -t jail` || exit 3 + if $command $rc_flags $command_args \ + >> $_tmp 2>&1 /var/run/jail_${_j}.id + else + rm -f /var/run/jail_${_j}.id + echo " cannot start jail " \ + "\"${_hostname:-${_j}}\": " + cat $_tmp + fi + rm -f $_tmp + done + fi echo '.' }