The branch main has been updated by danfe (ports committer):

URL: 
https://cgit.FreeBSD.org/src/commit/?id=ccfdf335d6976bb0e3436b808418d14f3d150a3d

commit ccfdf335d6976bb0e3436b808418d14f3d150a3d
Author:     Alexey Dokuchaev <[email protected]>
AuthorDate: 2020-10-11 08:23:00 +0000
Commit:     Alexey Dokuchaev <[email protected]>
CommitDate: 2021-10-27 09:26:00 +0000

    crunchgen: use realpath(3) instead of ``pwd -P''
    
    r366466 (9c7bd4f198e1) fixed a subtle bug by stripping the trailing
    '\n' appended to the output of popen("cd %s && pwd -P", p->srcdir).
    
    Replace this cumbersome implementation with a single realpath(3) call
    which avoids spawning a shell, reading from the stream with fgets(3),
    and final strdup(3).
    
    Reviewed by:            arichardson, kevans
    Approved by:            imp
    Differential Revision:  https://reviews.freebsd.org/D26734
---
 usr.sbin/crunch/crunchgen/crunchgen.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/usr.sbin/crunch/crunchgen/crunchgen.c 
b/usr.sbin/crunch/crunchgen/crunchgen.c
index 94792c5ec50b..89d549b18b4e 100644
--- a/usr.sbin/crunch/crunchgen/crunchgen.c
+++ b/usr.sbin/crunch/crunchgen/crunchgen.c
@@ -639,7 +639,6 @@ fillin_program(prog_t *p)
 {
        char path[MAXPATHLEN];
        char line[MAXLINELEN];
-       FILE *f;
 
        snprintf(line, MAXLINELEN, "filling in parms for %s", p->name);
        status(line);
@@ -654,22 +653,9 @@ fillin_program(prog_t *p)
 
        /* Determine the actual srcdir (maybe symlinked). */
        if (p->srcdir) {
-               snprintf(line, MAXLINELEN, "cd %s && pwd -P", p->srcdir);
-               f = popen(line,"r");
-               if (!f)
-                       errx(1, "Can't execute: %s\n", line);
-
-               path[0] = '\0';
-               fgets(path, sizeof path, f);
-               if (pclose(f))
-                       errx(1, "Can't execute: %s\n", line);
-
-               if (!*path)
-                       errx(1, "Can't perform pwd on: %s\n", p->srcdir);
-
-               /* Chop off trailing newline. */
-               path[strlen(path) - 1] = '\0';
-               p->realsrcdir = strdup(path);
+               p->realsrcdir = realpath(p->srcdir, NULL);
+               if (p->realsrcdir == NULL)
+                       errx(1, "Can't resolve path: %s\n", p->srcdir);
        }
 
        /* Unless the option to make object files was specified the

Reply via email to