config(8) patch for review for src dir handling
Ed Maste
emaste at freebsd.org
Wed Dec 19 15:28:32 PST 2007
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
More information about the freebsd-hackers
mailing list