From nobody Wed Oct 27 09:27:45 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CF8AF18140C7; Wed, 27 Oct 2021 09:27:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HfNdY5bpdz3tKm; Wed, 27 Oct 2021 09:27:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9C4C058CC; Wed, 27 Oct 2021 09:27:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19R9Rjd5004096; Wed, 27 Oct 2021 09:27:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19R9Rjic004095; Wed, 27 Oct 2021 09:27:45 GMT (envelope-from git) Date: Wed, 27 Oct 2021 09:27:45 GMT Message-Id: <202110270927.19R9Rjic004095@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexey Dokuchaev Subject: git: ccfdf335d697 - main - crunchgen: use realpath(3) instead of ``pwd -P'' List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: danfe X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ccfdf335d6976bb0e3436b808418d14f3d150a3d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by danfe (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=ccfdf335d6976bb0e3436b808418d14f3d150a3d commit ccfdf335d6976bb0e3436b808418d14f3d150a3d Author: Alexey Dokuchaev AuthorDate: 2020-10-11 08:23:00 +0000 Commit: Alexey Dokuchaev 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