From nobody@FreeBSD.org  Sat May 18 21:32:23 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 5FAD1282
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 May 2013 21:32:23 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.FreeBSD.org (oldred.freebsd.org [8.8.178.121])
	by mx1.freebsd.org (Postfix) with ESMTP id 378533D9
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 May 2013 21:32:23 +0000 (UTC)
Received: from oldred.FreeBSD.org ([127.0.1.6])
	by oldred.FreeBSD.org (8.14.5/8.14.5) with ESMTP id r4ILWMvb088264
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 May 2013 21:32:22 GMT
	(envelope-from nobody@oldred.FreeBSD.org)
Received: (from nobody@localhost)
	by oldred.FreeBSD.org (8.14.5/8.14.5/Submit) id r4ILWMfn088263;
	Sat, 18 May 2013 21:32:22 GMT
	(envelope-from nobody)
Message-Id: <201305182132.r4ILWMfn088263@oldred.FreeBSD.org>
Date: Sat, 18 May 2013 21:32:22 GMT
From: Daniel Shahaf <danielsh@apache.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: rc.d/jail: set jname at jail start time
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         178760
>Category:       conf
>Synopsis:       rc.d/jail: set jname at jail start time
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-jail
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 18 21:40:00 UTC 2013
>Closed-Date:    Sat May 25 16:40:04 UTC 2013
>Last-Modified:  Sat May 25 16:40:04 UTC 2013
>Originator:     Daniel Shahaf
>Release:        9.1-RELEASE-p3
>Organization:
The Apache Software Foundation
>Environment:
FreeBSD metis.apache.org 9.1-RELEASE-p3 FreeBSD 9.1-RELEASE-p3 #0 r250118: Tue Apr 30 22:06:26 UTC 2013     root@loki.apache.org:/usr/obj/usr/src/sys/ASF  amd64

>Description:
When /etc/rc.d/jail starts a jail, it sets the jail's name (as in `jls name`) to be equal to the jid.  For example:

    metis% jls jid name
    1 1
    2 2
    metis% 

It would be more useful to set the jname to, for example, the rc.conf identifier of the jail.  That allows for 'jexec' to be used with the jail's name directly, without having to look up its jid first.

Current behaviour:

    metis% jls jid name
    1 1
    2 2
    metis# jexec jena /usr/bin/true
    jexec: jail "jena" not found
    zsh: exit 1     jexec jena /usr/bin/true

Current workaround:
    metis# jls jid name host.hostname | grep jena | awk '{print $1}'
    3
    metis# jexec 3 /usr/bin/true; echo $?
    0
    metis# 

Alternative workaround:

    metis# jls jid name host.hostname | grep jena | awk '{print $1}'
    3
    metis# jail -m jid=3 name=subversion
    metis# jexec jena /usr/bin/true; echo $?
    0
    metis# 

Behaviour with the patch applied (for jails that have been (re)started with the patch applied):
    metis# jls jid name 
    3 jena
    4 james
    metis# jexec james /usr/bin/true; echo $?
    0
    metis# 

>How-To-Repeat:
Just use /etc/rc.d/jail to start a jail.  In our case we start jails from rc.conf:

jail_sysvipc_allow="YES"
jail_enable="YES"
jail_set_hostname_allow="NO"
jail_list="jena james"
jail_james_hostname="james.zones.apache.org"
jail_james_ip="140.211.11.81"
jail_james_interface="bce1"
jail_james_rootdir="/x1/jails/james.zones.apache.org"
jail_james_devfs_enable="YES"
jail_jena_hostname="jena.zones.apache.org"
jail_jena_ip="140.211.11.85"
jail_jena_interface="bce1"
jail_jena_rootdir="/x1/jails/jena.zones.apache.org"
jail_jena_devfs_enable="YES"

>Fix:
Patch attached.  We have used it since 9.0-RELEASE on multiple jail hosts without issue.

Patch attached with submission follows:

--- infrastructure/trunk/machines/freebsd/metis.apache.org/etc/rc.d/jail (original)
+++ infrastructure/trunk/machines/freebsd/metis.apache.org/etc/rc.d/jail Sat May 18 20:18:40 2013
@@ -112,7 +112,7 @@ init_variables()
        eval _fstab=\"\${jail_${_j}_fstab:-${jail_fstab}}\"
        [ -z "${_fstab}" ] && _fstab="/etc/fstab.${_j}"
        eval _flags=\"\${jail_${_j}_flags:-${jail_flags}}\"
-       [ -z "${_flags}" ] && _flags="-l -U root"
+       [ -z "${_flags}" ] && _flags="-n ${_j} -l -U root"
        eval _consolelog=\"\${jail_${_j}_consolelog:-${jail_consolelog}}\"
        [ -z "${_consolelog}" ] && _consolelog="/var/log/jail_${_j}_console.log"
        eval _fib=\"\${jail_${_j}_fib:-${jail_fib}}\"


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sat May 18 22:12:07 UTC 2013 
Responsible-Changed-Why:  
over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=178760 

From: Miroslav Lachman <000.fbsd@quip.cz>
To: bug-followup@FreeBSD.org, danielsh@apache.org
Cc:  
Subject: Re: conf/178760: rc.d/jail: set jname at jail start time
Date: Sun, 19 May 2013 11:09:25 +0200

 I don't know if it's worth the change as you can already use
 jail_jena_flags="-l -U root -n jena"
 in you rc.conf.
 
 On the other side, the change is really simple and should be there for 
 years (from the first time the jail can have own name)
 
 The forthcoming new jail system with /etc/jail.conf will have all jails 
 named and there will be completely different rc.d/jail script for it.
 
 Miroslav Lachman

From: Daniel Shahaf <danielsh@apache.org>
To: Miroslav Lachman <000.fbsd@quip.cz>
Cc: bug-followup@FreeBSD.org
Subject: Re: conf/178760: rc.d/jail: set jname at jail start time
Date: Mon, 20 May 2013 17:34:20 +0300

 Miroslav Lachman wrote on Sun, May 19, 2013 at 11:09:25 +0200:
 > I don't know if it's worth the change as you can already use
 > jail_jena_flags="-l -U root -n jena"
 > in you rc.conf.
 >
 
 True.  However, flags set in rc.conf replace the default ones, not
 append to them, so we cut the middleman and patched our rc.d/jail
 locally, to ensure that if the default flags change, we won't miss
 that when we upgrade.
 
 Another reason for just patching rc.d/jail is that we want the -n flag
 for every jail.  (That's also the reason we upstream the change.)
 
 > On the other side, the change is really simple and should be there for  
 > years (from the first time the jail can have own name)
 >
 > The forthcoming new jail system with /etc/jail.conf will have all jails  
 > named and there will be completely different rc.d/jail script for it.
 
 That's great.  However, if jail.conf is scheduled to appear in 9.2,
 I think the patch still makes sense for 9.1.
Responsible-Changed-From-To: freebsd-rc->freebsd-jail 
Responsible-Changed-By: crees 
Responsible-Changed-When: Mon May 20 18:27:17 UTC 2013 
Responsible-Changed-Why:  
I'm a big fan of this change.  Would anyone like to approve? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=178760 
State-Changed-From-To: open->closed 
State-Changed-By: crees 
State-Changed-When: Sat May 25 16:40:04 UTC 2013 
State-Changed-Why:  
On closer inspection, the jail name is set since r238102, which was 
merged to stable/9.  Unfortunately it didn't make 9.1-R.  Thanks for the 
patch however. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=178760 
>Unformatted:
