From nobody Sat Aug 29 15:18:59 2026 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 4hXJnJ6SXbz6qYTl for ; Sat, 29 Aug 2026 15:19:00 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hXJnJ2pMtz4QMd for ; Sat, 29 Aug 2026 15:19:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788016740; 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=chFrphs2q2+lwF17qfiVttmZfKxuRwVLb+o1d0Mexwg=; b=BZRjY3a6Q1O/AYNG81y3CHyxCEv7THJUxBEEZu44JoMszct91E/SlJMyYCWRhigOcq9O3q sFH/RZT/uVsUdU3T02Pd6ttzRLzpLuJs/eaJYcRpLfOl7TSGCA7qYOeZ6AXUJYjrwTvynW 4et2F+7OUbqQcP9FOV8pltUalVSRGMIkFFBOE3RxdZXy21JX5qkHrlSgiK+MNiJOvzolWZ x5uTJj86PjzGq0GHAweP/ErNEz/V0LGBQbIHDN3ZdLukv/QeQ3X0mHu1tnxVRnmqKcU11/ 5tkmzI7jsokoZG6XkcIjeJcETKGRaFCJQmx2Zteh6fef9AgEdydPSZGqEByj3Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788016740; a=rsa-sha256; cv=none; b=pJ6wiqOoENMiIK1wW499nHUCKop6FwHq8cWYQ88GaHb4jIC2JARfcXf29TccaXI3AweHL0 p5FefTeffNl/4nSof9wIAM1pdJufJFE73wT2eAu0d+VPqeUZK1X0zzemkOI1tUDZLmDGGp KBYFtKD9u9T+u7jlxFYCTF4gJE1XsB0SqtcF6FULjZvw5xr+an0wktKzDbUHdu6ZWxIjGz FIIqznuUKmSq6/I8BfP7EYvH/b+e8shdwUq2N7p7bQrF2nzuQBOOsen0OFSib1s3liBg6p ysN1IjvRD02zUM5ImDZAlwPcoMyX28YaJid9yTBFsgrmTpAQGiNTrNzGPztZjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788016740; 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=chFrphs2q2+lwF17qfiVttmZfKxuRwVLb+o1d0Mexwg=; b=Uz5FnDsQ7e3r/+UapEHsaXJjHemexh2RRCeaIozbG5BZ1p+y3ff7K5TOEw+9vMAEGSF7iy LEqM9fhrN3AU/cbQahxSqFcAXH350Npb8g+Qns848BYhoOUd8BklgXxtX4mc7pHngv9jjS +dMQ8O6Sr9GU9XufoNUFKtWy0YCu82Fk95PszISMVfCpHwynIV2lr/NR0KVZsUUhv/HZ7G Ftcft05DOhLGAylgswYQjcoNWO4JhmWa7NcW0zvA+/wj0PtsQE9Kk6vNNG8sdf0YcuV3kk ts4WEXldd2Vq5tlqBor1lE53nK31P4aye4tdyadpw77jCvjDYzIZjVKrj2L19w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hXJnH3rLNzlCy for ; Sat, 29 Aug 2026 15:18:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 42fd6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 29 Aug 2026 15:18:59 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Fernando Apeste=?utf-8?Q?gu=C3=ADa?= Subject: git: edadc3f90515 - main - whereis(1): Respect PORTSDIR variable 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fernape X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: edadc3f9051595a9c2e693d8ab666a50b9e7a21a Auto-Submitted: auto-generated Date: Sat, 29 Aug 2026 15:18:59 +0000 Message-Id: <6a92f863.42fd6.5636da14@gitrepo.freebsd.org> The branch main has been updated by fernape: URL: https://cgit.FreeBSD.org/src/commit/?id=edadc3f9051595a9c2e693d8ab666a50b9e7a21a commit edadc3f9051595a9c2e693d8ab666a50b9e7a21a Author: Fernando ApesteguĂ­a AuthorDate: 2026-08-23 15:46:18 +0000 Commit: Fernando ApesteguĂ­a CommitDate: 2026-08-29 15:15:43 +0000 whereis(1): Respect PORTSDIR variable PORTSDIR is a very common variable that points to the location of a ports directory. Make whereis(1) respect this variable too. Reviewed by: arrowd@, christos@ Approved by: christos@ Differential Revision: https://reviews.freebsd.org/D56845 --- usr.bin/whereis/whereis.1 | 4 ++ usr.bin/whereis/whereis.c | 118 +++++++++++++++++++++++++--------------------- 2 files changed, 69 insertions(+), 53 deletions(-) diff --git a/usr.bin/whereis/whereis.1 b/usr.bin/whereis/whereis.1 index 90922ce61db5..1b6adaeaf077 100644 --- a/usr.bin/whereis/whereis.1 +++ b/usr.bin/whereis/whereis.1 @@ -72,6 +72,10 @@ including all the subdirectories of .Pa /usr/src and .Pa /usr/ports . +If the environment variable +.Ev PORTSDIR +is defined and points to a directory then all its subdirectories +are included in the search of program sources. .Pp The following options are available: .Bl -tag -width indent diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c index 8de56b9cf654..afc099276dfe 100644 --- a/usr.bin/whereis/whereis.c +++ b/usr.bin/whereis/whereis.c @@ -312,64 +312,76 @@ defaults(void) abort(); nele = 0; decolonify(b, &sourcedirs, &nele); - - if (stat(PATH_PORTS, &sb) == -1) { - if (errno == ENOENT) - /* no /usr/ports, we are done */ - return; - err(EX_OSERR, "stat(" PATH_PORTS ")"); + ccharp path_ports; + if ((cp = getenv("PORTSDIR")) != NULL) { + b = strdup(cp); + if (b == NULL) + abort(); } - if ((sb.st_mode & S_IFMT) != S_IFDIR) - /* /usr/ports is not a directory, ignore */ - return; - if (access(PATH_PORTS, R_OK | X_OK) != 0) - return; - if ((dir = opendir(PATH_PORTS)) == NULL) - err(EX_OSERR, "opendir" PATH_PORTS ")"); - while ((dirp = readdir(dir)) != NULL) { - /* - * Not everything below PATH_PORTS is of - * interest. First, all dot files and - * directories (e. g. .snap) can be ignored. - * Also, all subdirectories starting with a - * capital letter are not going to be - * examined, as they are used for internal - * purposes (Mk, Tools, ...). This also - * matches a possible CVS subdirectory. - * Finally, the distfiles subdirectory is also - * special, and should not be considered to - * avoid false matches. - */ - if (dirp->d_name[0] == '.' || - /* - * isupper() not used on purpose: the - * check is supposed to default to the C - * locale instead of the current user's - * locale. - */ - (dirp->d_name[0] >= 'A' && dirp->d_name[0] <= 'Z') || - strcmp(dirp->d_name, "distfiles") == 0) + ccharp ports_locations[2] = {PATH_PORTS, cp}; + int i; + for (i = 0; i < 2; i++) { + path_ports = ports_locations[i]; + if (!path_ports) continue; - if ((b = malloc(sizeof PATH_PORTS + 1 + dirp->d_namlen)) - == NULL) - abort(); - strcpy(b, PATH_PORTS); - strcat(b, "/"); - strcat(b, dirp->d_name); - if (stat(b, &sb) == -1 || - (sb.st_mode & S_IFMT) != S_IFDIR || - access(b, R_OK | X_OK) != 0) { - free(b); + if (stat(path_ports, &sb) == -1) { + if (errno == ENOENT) + /* no /usr/ports, we are done */ + continue; + err(EX_OSERR, "stat(%s)", path_ports); + } + if ((sb.st_mode & S_IFMT) != S_IFDIR) + /* This is not a directory, ignore */ + continue; + if (access(path_ports, R_OK | X_OK) != 0) continue; + if ((dir = opendir(path_ports)) == NULL) + err(EX_OSERR, "opendir %s)", path_ports); + while ((dirp = readdir(dir)) != NULL) { + /* + * Not everything below path_ports is of + * interest. First, all dot files and + * directories (e. g. .snap) can be ignored. + * Also, all subdirectories starting with a + * capital letter are not going to be + * examined, as they are used for internal + * purposes (Mk, Tools, ...). This also + * matches a possible CVS subdirectory. + * Finally, the distfiles subdirectory is also + * special, and should not be considered to + * avoid false matches. + */ + if (dirp->d_name[0] == '.' || + /* + * isupper() not used on purpose: the + * check is supposed to default to the C + * locale instead of the current user's + * locale. + */ + (dirp->d_name[0] >= 'A' && dirp->d_name[0] <= 'Z') || + strcmp(dirp->d_name, "distfiles") == 0) + continue; + if ((b = malloc(strlen(path_ports) + 1 + dirp->d_namlen)) + == NULL) + abort(); + strcpy(b, path_ports); + strcat(b, "/"); + strcat(b, dirp->d_name); + if (stat(b, &sb) == -1 || + (sb.st_mode & S_IFMT) != S_IFDIR || + access(b, R_OK | X_OK) != 0) { + free(b); + continue; + } + sourcedirs = realloc(sourcedirs, + (nele + 2) * sizeof(char *)); + if (sourcedirs == NULL) + abort(); + sourcedirs[nele++] = b; + sourcedirs[nele] = NULL; } - sourcedirs = realloc(sourcedirs, - (nele + 2) * sizeof(char *)); - if (sourcedirs == NULL) - abort(); - sourcedirs[nele++] = b; - sourcedirs[nele] = NULL; + closedir(dir); } - closedir(dir); } }