Honour the logical current working directory ($PWD) when using config's

-d destdir option.  For an automounted src tree using the logical cwd
in the Makefile keeps amd(8)'s mount timeout refreshed.  Code to check
$PWD's validity cribbed from pwd(1).

Discussed on hackers@.
This commit is contained in:
Ed Maste 2008-01-08 21:10:13 +00:00
parent 9233d8f3ad
commit 3b2262e488
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=175163

View File

@ -249,9 +249,27 @@ main(int argc, char **argv)
static void
get_srcdir(void)
{
struct stat lg, phy;
char *p, *pwd;
int i;
if (realpath("../..", srcdir) == NULL)
errx(2, "Unable to find root of source tree");
if ((pwd = getenv("PWD")) != NULL && *pwd == '/' &&
(pwd = strdup(pwd)) != NULL) {
/* Remove the 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