From nobody Sat Nov 30 21:24:46 2024 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 4Y133L71bYz5fhBc; Sat, 30 Nov 2024 21:24:46 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y133L1tqsz4bYd; Sat, 30 Nov 2024 21:24:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733001886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cDwLWf2tIcXTUJ4cPxuP1Nk7R0g6TABkqNs6AxJ7i8Y=; b=gaI4Y748H4HL41eLTFKap3BR2uDO6yqPdOyFJcsOlO9YZDI1AJCtfYPuGt1Yh4f2G7aeh7 0X6SLMp1nSQOkUpHG2GSXZn32qcR0eE/FLg8mR1tBwY7Zv+8StyeO6TLSIdjISBXF1SlWY jFRySmgn65CRw4eONl99TCMu+ike+GCIw0KQigLT4s27f8bXQm//W/9no/QKlyCM1Kykys +qgD4UE4i6wbmnpa7ElcOZJ++AlFCaaKQyBbEzoD+AjzrM9EHj6r/UtJvVoNGKHRb/l1QY S2g6XUNYaABdC8b62P6sHafnZRwTO8mE81PSt6aA+tk06BitLPQXgFK1VfEAJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733001886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cDwLWf2tIcXTUJ4cPxuP1Nk7R0g6TABkqNs6AxJ7i8Y=; b=v3d4GFgBtfQrI7VW4W5Q5BA2o5TVGzhaDkXFaYIi7YHuIrM5ooxsOqEIlWVV6VcvLIfL2l iSgykpT5YktHLtRLVo/P6gHSKSDY2GCpLDRUH2YURj2sbcrECcXvox8WGPCkVlsHDzAQBU cYgBc4HrPGsHDyvgLhGF2Bv5Rd+Bd9rt0NolM5Eic4JjSEwO98kPRL+7VXrFWCMU3veZ9+ jFvgLdtnahI/pMI07PQxV6qLJV+Gb0KwVQEhtvy3sR2mjKSPUi7AFnxK4u4NylbEb+dtjV pxHMxCJBOndz4+KQAD+kDihuJ5xjkpovnUEqJo9+kwyC8QAUqzGBIZ6QgMXH4w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733001886; a=rsa-sha256; cv=none; b=wr63obkIGMP3JUzf4Is8PO4Gp/oHu+FTZaOiVSM+dfkg5FWfc7JrjpvuAQiRrzR+9ZTv7P 6Br/oxllBF18N7yrkvuDzZJzpzsLZKz//WUApw9XSR9XnLPnQDXmXljAM9NRPq4yZ+JHAf WnhiQMZpGqm+93lIucueP2rs7J9kg6U0voYRVvnS0a81ZJbDOaHj2HymmICb8zl1hkOMtH pv+sn0ry+jGuOkMe37bVe7JA/xwVHZ1xXAHXL594uOi3M6FuWlxnn71wDsQ/Gh6fShJovO uGjrWVsXpl5K1rPBp1ZVffI/RTGZMpOwoMIEdPW1zK3a4UUbbcVOGaCwnoSkiw== 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 4Y133L1VpBzPyr; Sat, 30 Nov 2024 21:24:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4AULOktq057996; Sat, 30 Nov 2024 21:24:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AULOk9M057993; Sat, 30 Nov 2024 21:24:46 GMT (envelope-from git) Date: Sat, 30 Nov 2024 21:24:46 GMT Message-Id: <202411302124.4AULOk9M057993@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 6ce090af2832 - stable/13 - grep: Fix various bugs in recursive tree handling 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6ce090af28326d9c25a4258278a69952b41e2091 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=6ce090af28326d9c25a4258278a69952b41e2091 commit 6ce090af28326d9c25a4258278a69952b41e2091 Author: John Baldwin AuthorDate: 2024-09-04 19:53:17 +0000 Commit: John Baldwin CommitDate: 2024-11-30 20:43:20 +0000 grep: Fix various bugs in recursive tree handling The -OpS options were effectively ignored due to a collection of bugs in the use of fts(3): - fts_open(3) requires one of FTS_PHYSICAL or FTS_LOGICAL to be specified, but in the -O case, only FTS_COMFOLLOW was given. Fix this to use FTS_COMFOLLOW | FTS_PHYSICAL. - The switch on the entry type returned by fts_read() did not check for symbolic links, so symbolic links fell into the default case and were always passed to procfile() even when -p was given. Fix this by adding cases in the switch statement to explicitly ignore FTS_SL. - FTS_NOSTAT was passed to fts_open(), so fts_open() couldn't detect symbolic links when FTS_PHYSICAL was passed, instead both regular files and symbolic links were returned as FTS_NSOK entries. Fix by only using FTS_NOSTAT with FTS_LOGICAL. While here, fix a few other nits: - Treat FTS_NS as an error like FTS_DNR and FTS_ERR. - Just ignore FTS_DP. The logic to skip descending into skipped directories is only relevant when a directory is first visited, not after the directory has been visited. - Use warnc instead of warnx + strerror. PR: 280676 Reviewed by: kevans MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D46255 (cherry picked from commit 77eb877714d69ee0279d70eb3331920fba90db95) --- usr.bin/grep/util.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index e3cf6e3cb4d8..63ee6f191180 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -136,16 +136,16 @@ grep_tree(char **argv) /* This switch effectively initializes 'fts_flags' */ switch(linkbehave) { case LINK_EXPLICIT: - fts_flags = FTS_COMFOLLOW; + fts_flags = FTS_COMFOLLOW | FTS_PHYSICAL; break; case LINK_SKIP: fts_flags = FTS_PHYSICAL; break; default: - fts_flags = FTS_LOGICAL; + fts_flags = FTS_LOGICAL | FTS_NOSTAT; } - fts_flags |= FTS_NOSTAT | FTS_NOCHDIR; + fts_flags |= FTS_NOCHDIR; fts = fts_open((argv[0] == NULL) ? __DECONST(char * const *, wd) : argv, fts_flags, NULL); @@ -154,15 +154,13 @@ grep_tree(char **argv) while (errno = 0, (p = fts_read(fts)) != NULL) { switch (p->fts_info) { case FTS_DNR: - /* FALLTHROUGH */ case FTS_ERR: + case FTS_NS: file_err = true; if(!sflag) - warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); + warnc(p->fts_errno, "%s", p->fts_path); break; case FTS_D: - /* FALLTHROUGH */ - case FTS_DP: if (dexclude || dinclude) if (!dir_matching(p->fts_name) || !dir_matching(p->fts_path)) @@ -173,6 +171,17 @@ grep_tree(char **argv) warnx("warning: %s: recursive directory loop", p->fts_path); break; + case FTS_DP: + break; + case FTS_SL: + /* + * Skip symlinks for LINK_EXPLICIT and + * LINK_SKIP. Note that due to FTS_COMFOLLOW, + * symlinks on the command line are followed + * for LINK_EXPLICIT and not reported as + * symlinks. + */ + break; default: /* Check for file exclusion/inclusion */ ok = true;