diff options
author | emaste <emaste@FreeBSD.org> | 2008-01-08 21:10:13 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2008-01-08 21:10:13 +0000 |
commit | 23d78439c96372baa4a3c2847df65f8e11455ae7 (patch) | |
tree | 4f40cc2e18518d6faea86b59f6cabf42d0dad045 | |
parent | 7eb385c2d8022032727eafe8b8ff36a386939680 (diff) | |
download | FreeBSD-src-23d78439c96372baa4a3c2847df65f8e11455ae7.zip FreeBSD-src-23d78439c96372baa4a3c2847df65f8e11455ae7.tar.gz |
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@.
-rw-r--r-- | usr.sbin/config/main.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index a3b300a..d1ca9bf 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -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 |