Author: hrs
Date: Tue Oct 15 04:54:49 2013
New Revision: 256498
URL: http://svnweb.freebsd.org/changeset/base/256498

Log:
  - Fix "ifname|addr" syntax support in jail_{jname}_ip.
  - Create /var/run/jail_{jname}.id because ezjail-admin depends on it.

Modified:
  head/etc/rc.d/jail

Modified: head/etc/rc.d/jail
==============================================================================
--- head/etc/rc.d/jail  Tue Oct 15 04:45:09 2013        (r256497)
+++ head/etc/rc.d/jail  Tue Oct 15 04:54:49 2013        (r256498)
@@ -22,7 +22,7 @@ status_cmd="jail_status"
 extra_commands="config console status"
 : ${jail_conf:=/etc/jail.conf}
 : ${jail_program:=/usr/sbin/jail}
-: ${jail_consolecmd:=/bin/sh}
+: ${jail_consolecmd:=/usr/bin/login -f root}
 : ${jail_jexec:=/usr/sbin/jexec}
 : ${jail_jls:=/usr/sbin/jls}
 
@@ -329,9 +329,9 @@ jail_extract_address()
 #
 jail_handle_ips_option()
 {
-       local _x _type _i _iface
+       local _x _type _i _defif
        _x=$1
-       _iface=$2
+       _defif=$2
 
        if [ -z "${_x}" ]; then
                # No IP given. This can happen for the primary address
@@ -355,7 +355,8 @@ jail_handle_ips_option()
                _type=""
                _addr=""
                _mask=""
-               jail_extract_address $_i $_iface
+               _iface=""
+               jail_extract_address $_i $_defif
 
                # make sure we got an address.
                case $_addr in
@@ -366,10 +367,10 @@ jail_handle_ips_option()
                # Append address to list of addresses for the jail command.
                case $_type in
                inet)
-                       echo "  ip4.addr += \"${_addr}${_mask}\";"
+                       echo "  ip4.addr += \"${_iface}|${_addr}${_mask}\";"
                ;;
                inet6)
-                       echo "  ip6.addr += \"${_addr}${_mask}\";"
+                       echo "  ip6.addr += \"${_iface}|${_addr}${_mask}\";"
                        need_dad_wait=1
                ;;
                esac
@@ -393,16 +394,19 @@ jail_config()
 
 jail_console()
 {
-       local _j
+       local _j _cmd
 
        # One argument that is not _ALL.
        case $#:$1 in
-       1:_ALL) err 3 "Specify a jail name." ;;
-       1:*)    ;;
-       *)      err 3 "Specify a jail name." ;;
+       0:*|1:_ALL)     err 3 "Specify a jail name." ;;
+       1:*)            ;;
        esac
        _j=$(echo $1 | tr /. _)
-       eval _cmd=\${jail_${_j}_consolecmd:-$jail_consolecmd}
+       shift
+       case $# in
+       0)      eval _cmd=\${jail_${_j}_consolecmd:-$jail_consolecmd} ;;
+       *)      _cmd=$@ ;;
+       esac
        $jail_jexec $_j $_cmd
 }
 
@@ -414,7 +418,7 @@ jail_status()
 
 jail_start()
 {
-       local _j
+       local _j _jid _jn
 
        if [ $# = 0 ]; then
                return
@@ -426,7 +430,15 @@ jail_start()
                command=$jail_program
                rc_flags=$jail_flags
                command_args="-f $jail_conf -c"
-               $command $rc_flags $command_args "*"
+               $jail_jls -nq | while read IN; do
+                       _jn=$(echo $IN | tr " " "\n" | grep name=)
+                       _jid=$(echo $IN | tr " " "\n" | grep jid=)
+                       if $command $rc_flags $command_args ${_jn#name=}; then
+                               echo -n " ${_jn#name=}"
+                               echo "${_jid#jid=}" \
+                                   > /var/run/jail_${_jn#name=}.id
+                       fi
+               done
                echo '.'
                return
        ;;
@@ -446,7 +458,10 @@ jail_start()
                if $command $rc_flags $command_args \
                    >> $_tmp 2>&1 </dev/null; then
                        echo -n " ${_hostname:-${_j}}"
+                       _jid=$($jail_jls -n -j $_j | tr " " "\n" | grep jid=)
+                       echo "${_jid#jid=}" > /var/run/jail_${_j}.id
                else
+                       rm -f /var/run/jail_${_j}.id
                        echo " cannot start jail \"${_hostname:-${_j}}\": "
                        cat $_tmp
                fi
@@ -457,7 +472,7 @@ jail_start()
 
 jail_stop()
 {
-       local _j
+       local _j _jn
 
        if [ $# = 0 ]; then
                return
@@ -469,7 +484,14 @@ jail_stop()
                command=$jail_program
                rc_flags=$jail_flags
                command_args="-f $jail_conf -r"
-               $command $rc_flags $command_args "*"
+               $jail_jls -nq | while read IN; do
+                       _jn=$(echo $IN | tr " " "\n" | grep name=)
+                       echo -n " ${_jn#name=}"
+                       $command $rc_flags $command_args ${_jn#name=}
+                       if ! $jail_jls -j ${_jn#name=} > /dev/null 2>&1; then
+                               rm -f /var/run/jail_${_jn#name=}.id
+                       fi
+               done
                echo '.'
                return
        ;;
@@ -477,9 +499,14 @@ jail_stop()
        for _j in $@; do
                _j=$(echo $_j | tr /. _)
                parse_options $_j || continue
+               if ! $jail_jls -j $_j > /dev/null 2>&1; then
+                       continue
+               fi
                eval command=\${jail_${_j}_program:-$jail_program}
-               if $command -q -f $_conf -r $_j; then
-                       echo -n " ${_hostname:-${_j}}"
+               echo -n " ${_hostname:-${_j}}"
+               $command -q -f $_conf -r $_j
+               if ! $jail_jls -j $_j > /dev/null 2>&1; then
+                       rm -f /var/run/jail_${_j}.id
                fi
        done
        echo '.'
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to