Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F170942175
D42156.id185828.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D42156.id185828.diff
View Options
diff --git a/usr.bin/whereis/whereis.1 b/usr.bin/whereis/whereis.1
--- a/usr.bin/whereis/whereis.1
+++ b/usr.bin/whereis/whereis.1
@@ -72,6 +72,10 @@
.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
--- a/usr.bin/whereis/whereis.c
+++ b/usr.bin/whereis/whereis.c
@@ -32,6 +32,7 @@
* was pretty inferior in functionality.
*/
+#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -252,7 +253,7 @@
defaults(void)
{
size_t s;
- char *b, buf[BUFSIZ], *cp;
+ char *b, buf[BUFSIZ], *cp, *pp;
int nele;
FILE *p;
DIR *dir;
@@ -305,71 +306,74 @@
decolonify(b, &mandirs, &nele);
}
- /* -s defaults to precompiled list, plus subdirs of /usr/ports */
+ /* -s defaults to precompiled list, plus subdirs of /usr/ports plus
+ * subdirs of PORTSDIR
+ */
if (!sourcedirs) {
b = strdup(sourcepath);
if (b == NULL)
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 ")");
- }
- 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 path_ports;
+ cp = getenv("PORTSDIR");
+ ccharp ports_locations[2] = {PATH_PORTS, cp};
+ size_t i;
+ for (i = 0; i < nitems(ports_locations); 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)
+ continue;
+ err(EX_OSERR, "stat(%s)", path_ports);
+ }
+ if ((sb.st_mode & S_IFMT) != S_IFDIR)
+ /* The resolved path is not a directory; ignore */
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, ...). 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 (asprintf(&pp, "%s/%s", path_ports, dirp->d_name) == -1)
+ abort();
+ if (stat(pp, &sb) == -1 ||
+ (sb.st_mode & S_IFMT) != S_IFDIR ||
+ access(b, R_OK | X_OK) != 0) {
+ free(pp);
+ continue;
+ }
+ sourcedirs = realloc(sourcedirs,
+ (nele + 2) * sizeof(char *));
+ if (sourcedirs == NULL)
+ abort();
+ sourcedirs[nele++] = strdup(pp);
+ free(pp);
+ sourcedirs[nele] = NULL;
}
- sourcedirs = realloc(sourcedirs,
- (nele + 2) * sizeof(char *));
- if (sourcedirs == NULL)
- abort();
- sourcedirs[nele++] = b;
- sourcedirs[nele] = NULL;
+ closedir(dir);
}
- closedir(dir);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 8, 6:30 PM (12 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38487661
Default Alt Text
D42156.id185828.diff (4 KB)
Attached To
Mode
D42156: whereis(1): Respect PORTSDIR variable
Attached
Detach File
Event Timeline
Log In to Comment