From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 19 23:28:32 2007 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2F25116A417 for ; Wed, 19 Dec 2007 23:28:32 +0000 (UTC) (envelope-from emaste@freebsd.org) Received: from gw.sandvine.com (gw.sandvine.com [199.243.201.138]) by mx1.freebsd.org (Postfix) with ESMTP id E0FF613C447 for ; Wed, 19 Dec 2007 23:28:31 +0000 (UTC) (envelope-from emaste@freebsd.org) Received: from labgw2.phaedrus.sandvine.com ([192.168.3.11]) by gw.sandvine.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 19 Dec 2007 17:26:22 -0500 Received: by labgw2.phaedrus.sandvine.com (Postfix, from userid 12627) id 1757111711; Wed, 19 Dec 2007 17:26:22 -0500 (EST) Date: Wed, 19 Dec 2007 17:26:21 -0500 From: Ed Maste To: freebsd-hackers@freebsd.org Message-ID: <20071219222621.GA79432@sandvine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-OriginalArrivalTime: 19 Dec 2007 22:26:22.0353 (UTC) FILETIME=[2F20D810:01C8428E] Subject: config(8) patch for review for src dir handling X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Dec 2007 23:28:32 -0000 I've attached a patch I'd like to commit to config(8) for the way it handles get_srcdir. I'm asking for review since it partially reverts some changes made in revision 1.42 of usr.sbin/config/main.c and I'd like to make sure there are no issues there. Right now config(8) calls realpath("../..", ... to find the src path to write into the kernel Makefile. I want to change this to use $PWD with the last two path components removed, assuming it's the same dir as ../.. . I want to put this in because I often build from an amd(8)-mounted src tree, and realpath produces a path using amd's special temporary mount directory /.amd_mnt/... instead of the intended /host_mounts/... type of path and it times out when accessed that way. Using the logical cwd means that the generated Makefile references /host_mounts/... and amd knows the mount is still in use when building. Comments? -Ed Index: main.c =================================================================== RCS file: /usr/cvs/src/usr.sbin/config/main.c,v retrieving revision 1.76 diff -p -u -r1.76 main.c --- main.c 17 May 2007 04:53:52 -0000 1.76 +++ main.c 18 Dec 2007 21:02:32 -0000 @@ -249,9 +249,30 @@ main(int argc, char **argv) static void get_srcdir(void) { + char *pwd; if (realpath("../..", srcdir) == NULL) errx(2, "Unable to find root of source tree"); + + if ((pwd = getenv("PWD")) != NULL && *pwd == '/' && + (pwd = strdup(pwd))) { + struct stat lg, phy; + int i; + char *p; + + /* remove last two path components */ + for (i = 0; i < 2; i++) { + if ((p = strrchr(pwd, '/')) == NULL) { + free(pwd); + return; + } + *p = '\0'; + } + if (stat(pwd, &lg) != -1 && stat(srcdir, &phy) != -1 && + lg.st_dev == phy.st_dev && lg.st_ino == phy.st_ino) + strlcpy(srcdir, pwd, MAXPATHLEN); + free(pwd); + } } static void