From nobody@FreeBSD.org  Thu Dec 13 22:34:06 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 5E733780
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 13 Dec 2012 22:34:06 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 2AB078FC16
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 13 Dec 2012 22:34:06 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qBDMY6ZI023785
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 13 Dec 2012 22:34:06 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qBDMY6q0023784;
	Thu, 13 Dec 2012 22:34:06 GMT
	(envelope-from nobody)
Message-Id: <201212132234.qBDMY6q0023784@red.freebsd.org>
Date: Thu, 13 Dec 2012 22:34:06 GMT
From: Kimmo Paasiala <kpaasial@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: usr/src/sys/conf/newvers.sh, SYSDIR set to wrong directory
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         174422
>Category:       conf
>Synopsis:       [newvers.sh] [patch] SYSDIR set to wrong directory
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 13 22:40:00 UTC 2012
>Closed-Date:    Mon Nov 11 01:15:33 UTC 2013
>Last-Modified:  Mon Nov 11 01:15:33 UTC 2013
>Originator:     Kimmo Paasiala
>Release:        9-STABLE
>Organization:
>Environment:
FreeBSD whitezone.rdnzl.info 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0 r244185M: Thu Dec 13 23:08:38 EET 2012     root@whitezone.rdnzl.info:/usr/obj/usr/src/sys/RDNZL  amd64
>Description:
The newvers.sh script in /usr/src/sys/conf sets a wrong value to the
SYSDIR variable when used from /usr/src/include/Makefile as part of
the rule to create osreldate.h.

The Makefile in /usr/src/include sources the newvers.sh instead of
executing it, this causes the SYSDIR variable to be set to "/bin/.."
instead of the intended "/usr/src/sys/conf/.." because "dirname $0"
returns the dirname part of "/bin/sh" instead of dirname of
"/usr/src/sys/conf/newvers.sh".

This breaks at least the .git directory detection in newvers.sh if
there happens to be a .git -directory in the root directory of the
system. In such case builworld stops with an error at the .git directory
detection.
>How-To-Repeat:
Create a git repository in the root directory with "git init" and attempt
a "make buildworld" in /usr/src.
>Fix:
The attached patch should fix the problem. The fix tries to keep the
newvers.sh compatible with other possible uses of it where it's not
sourced by /usr/src/include/Makefile but executed directly.

In a discussion on the freebsd-stable mailing list it was noted that
misc/160646 should be commited before commiting this patch.

Patch attached with submission follows:

Index: include/Makefile
===================================================================
--- include/Makefile	(revision 244138)
+++ include/Makefile	(working copy)
@@ -100,6 +100,7 @@
 	@${ECHO} creating osreldate.h from newvers.sh
 	@MAKE=${MAKE}; \
 	PARAMFILE=${.CURDIR}/../sys/sys/param.h; \
+	SYSDIR=${.CURDIR}/../sys; \
 	. ${.CURDIR}/../sys/conf/newvers.sh; \
 	echo "$$COPYRIGHT" > osreldate.h; \
 	echo "#ifdef _KERNEL" >> osreldate.h; \
Index: sys/conf/newvers.sh
===================================================================
--- sys/conf/newvers.sh	(revision 244138)
+++ sys/conf/newvers.sh	(working copy)
@@ -38,7 +38,7 @@
 fi
 RELEASE="${REVISION}-${BRANCH}"
 VERSION="${TYPE} ${RELEASE}"
-SYSDIR=$(dirname $0)/..
+: ${SYSDIR:=$(dirname $0)/..}
 
 if [ "X${PARAMFILE}" != "X" ]; then
 	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \


>Release-Note:
>Audit-Trail:

From: Ian Lepore <ian@cardinalpeak.com>
To: bug-followup@FreeBSD.org, kpaasial@gmail.com
Cc:  
Subject: Re: conf/174422: [newvers.sh] [patch] SYSDIR set to wrong directory
Date: Thu, 19 Sep 2013 08:04:27 -0600

 After some testing I have determined that the patch in misc/160646 is
 sufficient to fix the problem, and the patch attached to this PR is
 unecessary if that patch is commited.
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/174422: commit references a PR
Date: Sat, 21 Sep 2013 22:36:16 +0000 (UTC)

 Author: ian
 Date: Sat Sep 21 22:36:07 2013
 New Revision: 255775
 URL: http://svnweb.freebsd.org/changeset/base/255775
 
 Log:
   Create a separate script to generate osreldate.h rather than sourcing
   newvers.sh into a temporary subshell with inline make rules.
   
   Using a separate script fixes a variety of problems, including establishing
   the correct dependencies in the makefiles.  It also eliminates a problem
   with the way newvers.sh uses `realpath $0`, because $0 expands differently
   within a script sourced into a rule in a makefile depending on the version
   of make and of /bin/sh being used.  The latter can cause build breakage in a
   cross-build environment, and can also make it difficult to compile 10.0 on
   older pre-10.0 systems.
   
   PR:		160646 174422
   Submitted by:	Garrett Cooper <yaneurabeya@gmail.com>
   Approved by:	re (gjb)
   MFC after:	2 weeks
 
 Added:
   head/include/mk-osreldate.sh   (contents, props changed)
 Modified:
   head/include/Makefile
 
 Modified: head/include/Makefile
 ==============================================================================
 --- head/include/Makefile	Sat Sep 21 22:24:10 2013	(r255774)
 +++ head/include/Makefile	Sat Sep 21 22:36:07 2013	(r255775)
 @@ -104,19 +104,16 @@ SHARED?=	copies
  
  INCS+=	osreldate.h
  
 -osreldate.h: ${.CURDIR}/../sys/conf/newvers.sh ${.CURDIR}/../sys/sys/param.h \
 -    ${.CURDIR}/Makefile
 -	@${ECHO} creating osreldate.h from newvers.sh
 -	@MAKE=${MAKE}; \
 -	PARAMFILE=${.CURDIR}/../sys/sys/param.h; \
 -	. ${.CURDIR}/../sys/conf/newvers.sh; \
 -	echo "$$COPYRIGHT" > osreldate.h; \
 -	echo "#ifdef _KERNEL" >> osreldate.h; \
 -	echo "#error \"<osreldate.h> cannot be used in the kernel, use <sys/param.h>\"" >> osreldate.h; \
 -	echo "#else" >> osreldate.h; \
 -	echo "#undef __FreeBSD_version" >> osreldate.h; \
 -	echo "#define __FreeBSD_version $$RELDATE" >> osreldate.h; \
 -	echo "#endif" >> osreldate.h
 +NEWVERS_SH=		${.CURDIR}/../sys/conf/newvers.sh
 +PARAM_H=		${.CURDIR}/../sys/sys/param.h
 +MK_OSRELDATE_SH=	${.CURDIR}/mk-osreldate.sh
 +
 +osreldate.h vers.c: ${NEWVERS_SH} ${PARAM_H} ${MK_OSRELDATE_SH}
 +	env ECHO="${ECHO}" \
 +	    MAKE="${MAKE}" \
 +	    NEWVERS_SH=${NEWVERS_SH} \
 +	    PARAM_H=${PARAM_H} \
 +	    ${MK_OSRELDATE_SH}
  
  .for i in ${LHDRS}
  INCSLINKS+=	sys/$i ${INCLUDEDIR}/$i
 
 Added: head/include/mk-osreldate.sh
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/include/mk-osreldate.sh	Sat Sep 21 22:36:07 2013	(r255775)
 @@ -0,0 +1,49 @@
 +#!/bin/sh -
 +# Copyright (c) 2013 Garrett Cooper
 +# All rights reserved.
 +#
 +# Redistribution and use in source and binary forms, with or without
 +# modification, are permitted provided that the following conditions
 +# are met:
 +# 1. Redistributions of source code must retain the above copyright
 +#    notice, this list of conditions and the following disclaimer.
 +# 2. Redistributions in binary form must reproduce the above copyright
 +#    notice, this list of conditions and the following disclaimer in the
 +#    documentation and/or other materials provided with the distribution.
 +#
 +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 +# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 +# SUCH DAMAGE.
 +#
 +# $FreeBSD$
 +
 +set -e
 +
 +CURDIR=$(pwd)
 +ECHO=${ECHO:=echo}
 +
 +tmpfile=$(mktemp osreldate.XXXXXXXX)
 +trap "rm -f $tmpfile" EXIT
 +
 +${ECHO} creating osreldate.h from newvers.sh
 +
 +export PARAMFILE="${PARAM_H:=$CURDIR/../sys/sys/param.h}"
 +. "${NEWVERS_SH:=$CURDIR/../sys/conf/newvers.sh}"
 +cat > $tmpfile <<EOF
 +$COPYRIGHT
 +#ifdef _KERNEL
 +#error "<osreldate.h> cannot be used in the kernel, use <sys/param.h>"
 +#else
 +#undef __FreeBSD_version
 +#define __FreeBSD_version $RELDATE
 +#endif
 +EOF
 +mv $tmpfile osreldate.h
 _______________________________________________
 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-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/174422: commit references a PR
Date: Sat, 28 Sep 2013 16:39:54 +0000 (UTC)

 Author: ian
 Date: Sat Sep 28 16:39:46 2013
 New Revision: 255930
 URL: http://svnweb.freebsd.org/changeset/base/255930
 
 Log:
   Allow the path to the system source directory to be passed in to
   newvers.sh.  Pass it in from include/Makefile.  If it isn't passed in,
   fall back to the old logic of using dirname $0.
   
   Using dirname $0 does not yield the path to the script if it was
   sourced in from another script in another directory; you end up with
   the parent script's path.  That was causing newvers.sh to look one
   level below the FreeBSD src/ directory when building osreldate.h and it
   may find something like a git or svn repo there that has nothing to do
   with FreeBSD.
   
   PR:		174422
   Approved by:	re ()
   MFC after:	2 weeks
 
 Modified:
   head/include/Makefile
   head/sys/conf/newvers.sh
 
 Modified: head/include/Makefile
 ==============================================================================
 --- head/include/Makefile	Sat Sep 28 16:25:20 2013	(r255929)
 +++ head/include/Makefile	Sat Sep 28 16:39:46 2013	(r255930)
 @@ -104,8 +104,9 @@ SHARED?=	copies
  
  INCS+=	osreldate.h
  
 -NEWVERS_SH=		${.CURDIR}/../sys/conf/newvers.sh
 -PARAM_H=		${.CURDIR}/../sys/sys/param.h
 +SYSDIR=			${.CURDIR}/../sys
 +NEWVERS_SH=		${SYSDIR}/conf/newvers.sh
 +PARAM_H=		${SYSDIR}/sys/param.h
  MK_OSRELDATE_SH=	${.CURDIR}/mk-osreldate.sh
  
  osreldate.h vers.c: ${NEWVERS_SH} ${PARAM_H} ${MK_OSRELDATE_SH}
 @@ -113,6 +114,7 @@ osreldate.h vers.c: ${NEWVERS_SH} ${PARA
  	    MAKE="${MAKE}" \
  	    NEWVERS_SH=${NEWVERS_SH} \
  	    PARAM_H=${PARAM_H} \
 +	    SYSDIR=${SYSDIR} \
  	    sh ${MK_OSRELDATE_SH}
  
  .for i in ${LHDRS}
 
 Modified: head/sys/conf/newvers.sh
 ==============================================================================
 --- head/sys/conf/newvers.sh	Sat Sep 28 16:25:20 2013	(r255929)
 +++ head/sys/conf/newvers.sh	Sat Sep 28 16:39:46 2013	(r255930)
 @@ -38,7 +38,10 @@ if [ "X${BRANCH_OVERRIDE}" != "X" ]; the
  fi
  RELEASE="${REVISION}-${BRANCH}"
  VERSION="${TYPE} ${RELEASE}"
 -SYSDIR=$(dirname $0)/..
 +
 +if [ "X${SYSDIR}" = "X" ]; then
 +    SYSDIR=$(dirname $0)/..
 +fi
  
  if [ "X${PARAMFILE}" != "X" ]; then
  	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
 _______________________________________________
 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-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/174422: commit references a PR
Date: Sat, 12 Oct 2013 17:31:29 +0000 (UTC)

 Author: ian
 Date: Sat Oct 12 17:31:21 2013
 New Revision: 256386
 URL: http://svnweb.freebsd.org/changeset/base/256386
 
 Log:
   MFC r255775 r255796 r255807 r255930 r255929 r255957:
   
   Create a separate script to generate osreldate.h rather than sourcing
   newvers.sh into a temporary subshell with inline make rules.
   Fixes PR 160646.
   
   Allow the path to the system source directory to be passed in to
   newvers.sh.  Pass it in from include/Makefile.  If it isn't passed in,
   fall back to the old logic of using dirname $0.  Fixes PR 174422.
   
   PR:		160646 174422
 
 Added:
   stable/9/include/mk-osreldate.sh
      - copied, changed from r255775, head/include/mk-osreldate.sh
 Modified:
   stable/9/include/Makefile
   stable/9/sys/conf/newvers.sh
 Directory Properties:
   stable/9/include/   (props changed)
   stable/9/sys/   (props changed)
   stable/9/sys/conf/   (props changed)
 
 Modified: stable/9/include/Makefile
 ==============================================================================
 --- stable/9/include/Makefile	Sat Oct 12 17:27:59 2013	(r256385)
 +++ stable/9/include/Makefile	Sat Oct 12 17:31:21 2013	(r256386)
 @@ -99,19 +99,18 @@ SHARED?=	copies
  
  INCS+=	osreldate.h
  
 -osreldate.h: ${.CURDIR}/../sys/conf/newvers.sh ${.CURDIR}/../sys/sys/param.h \
 -    ${.CURDIR}/Makefile
 -	@${ECHO} creating osreldate.h from newvers.sh
 -	@MAKE=${MAKE}; \
 -	PARAMFILE=${.CURDIR}/../sys/sys/param.h; \
 -	. ${.CURDIR}/../sys/conf/newvers.sh; \
 -	echo "$$COPYRIGHT" > osreldate.h; \
 -	echo "#ifdef _KERNEL" >> osreldate.h; \
 -	echo "#error \"<osreldate.h> cannot be used in the kernel, use <sys/param.h>\"" >> osreldate.h; \
 -	echo "#else" >> osreldate.h; \
 -	echo "#undef __FreeBSD_version" >> osreldate.h; \
 -	echo "#define __FreeBSD_version $$RELDATE" >> osreldate.h; \
 -	echo "#endif" >> osreldate.h
 +SYSDIR=			${.CURDIR}/../sys
 +NEWVERS_SH=		${SYSDIR}/conf/newvers.sh
 +PARAM_H=		${SYSDIR}/sys/param.h
 +MK_OSRELDATE_SH=	${.CURDIR}/mk-osreldate.sh
 +
 +osreldate.h vers.c: ${NEWVERS_SH} ${PARAM_H} ${MK_OSRELDATE_SH}
 +	env ECHO="${ECHO}" \
 +	    MAKE="${MAKE}" \
 +	    NEWVERS_SH=${NEWVERS_SH} \
 +	    PARAM_H=${PARAM_H} \
 +	    SYSDIR=${SYSDIR} \
 +	    sh ${MK_OSRELDATE_SH}
  
  .for i in ${LHDRS}
  INCSLINKS+=	sys/$i ${INCLUDEDIR}/$i
 
 Copied and modified: stable/9/include/mk-osreldate.sh (from r255775, head/include/mk-osreldate.sh)
 ==============================================================================
 --- head/include/mk-osreldate.sh	Sat Sep 21 22:36:07 2013	(r255775, copy source)
 +++ stable/9/include/mk-osreldate.sh	Sat Oct 12 17:31:21 2013	(r256386)
 @@ -36,7 +36,9 @@ trap "rm -f $tmpfile" EXIT
  ${ECHO} creating osreldate.h from newvers.sh
  
  export PARAMFILE="${PARAM_H:=$CURDIR/../sys/sys/param.h}"
 -. "${NEWVERS_SH:=$CURDIR/../sys/conf/newvers.sh}"
 +set +e
 +. "${NEWVERS_SH:=$CURDIR/../sys/conf/newvers.sh}" || exit 1
 +set -e
  cat > $tmpfile <<EOF
  $COPYRIGHT
  #ifdef _KERNEL
 @@ -46,4 +48,5 @@ $COPYRIGHT
  #define __FreeBSD_version $RELDATE
  #endif
  EOF
 +chmod 644 $tmpfile
  mv $tmpfile osreldate.h
 
 Modified: stable/9/sys/conf/newvers.sh
 ==============================================================================
 --- stable/9/sys/conf/newvers.sh	Sat Oct 12 17:27:59 2013	(r256385)
 +++ stable/9/sys/conf/newvers.sh	Sat Oct 12 17:31:21 2013	(r256386)
 @@ -38,7 +38,10 @@ if [ "X${BRANCH_OVERRIDE}" != "X" ]; the
  fi
  RELEASE="${REVISION}-${BRANCH}"
  VERSION="${TYPE} ${RELEASE}"
 -SYSDIR=$(dirname $0)/..
 +
 +if [ "X${SYSDIR}" = "X" ]; then
 +    SYSDIR=$(dirname $0)/..
 +fi
  
  if [ "X${PARAMFILE}" != "X" ]; then
  	RELDATE=$(awk '/__FreeBSD_version.*propagated to newvers/ {print $3}' \
 _______________________________________________
 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-unsubscribe@freebsd.org"
 

From: Ian Lepore <ian@cardinalpeak.com>
To: bug-followup@FreeBSD.org, kpaasial@gmail.com
Cc:  
Subject: Re: conf/174422: [newvers.sh] [patch] SYSDIR set to wrong directory
Date: Sat, 12 Oct 2013 11:34:07 -0600

 This was fixed in r255930 with semi-related changes in r255775 r255796
 r255807 r255929 r255957; it was MFC'd to 9-stable in r256386.  This can
 now be closed.
 
 
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Mon Nov 11 01:14:55 UTC 2013 
State-Changed-Why:  
MFC'd to 9-stable in r256386. 

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