Re: config(8) patch for review for src dir handling

2007-12-26 Thread Ed Maste
On Sun, Dec 23, 2007 at 10:40:39AM +0100, Dag-Erling Sm??rgrav wrote:

> Ed Maste <[EMAIL PROTECTED]> writes:
> > 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'm worried that your patch assumes that $PWD is present and correct,
> for which there is no guarantee.  What happens if you use getcwd()
> instead of getenv("PWD")?

The patch assumes neither; it checks for $PWD and verifies that the dir
obtained by removing the last two components is the same as that
provided by realpath("../.." .  If $PWD is not set, or the path based on
it is not correct, it falls back to the current behaviour -- the path
returned by realpath("../.." .

Getcwd doesn't give the desired behaviour since, like realpath, it
returns the physical directory.

-Ed
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: config(8) patch for review for src dir handling

2007-12-23 Thread Jilles Tjoelker
On Sun, Dec 23, 2007 at 10:40:39AM +0100, Dag-Erling Smørgrav wrote:
> Ed Maste <[EMAIL PROTECTED]> writes:
> > 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'm worried that your patch assumes that $PWD is present and correct,
> for which there is no guarantee.  What happens if you use getcwd()
> instead of getenv("PWD")?

getcwd() does not use $PWD, it returns a pathname without symlinks.
So that would lead to the original behaviour.

A better way could be to use $PWD if it is set and an absolute logical
pathname referring to the current directory, as in src/bin/pwd/pwd.c .

-- 
Jilles Tjoelker
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: config(8) patch for review for src dir handling

2007-12-23 Thread Dag-Erling Smørgrav
Ed Maste <[EMAIL PROTECTED]> writes:
> 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'm worried that your patch assumes that $PWD is present and correct,
for which there is no guarantee.  What happens if you use getcwd()
instead of getenv("PWD")?

DES
-- 
Dag-Erling Smørgrav - [EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


config(8) patch for review for src dir handling

2007-12-19 Thread Ed Maste
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 -  1.76
+++ main.c  18 Dec 2007 21:02:32 -
@@ -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
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"