Page MenuHomeFreeBSD

whereis(1): Respect PORTSDIR variable
Needs ReviewPublic

Authored by fernape on Oct 11 2023, 11:12 AM.
Tags
None
Referenced Files
F169790365: D42156.id184795.diff
Wed, Sep 2, 2:06 PM
F169781390: D42156.id184795.diff
Wed, Sep 2, 1:28 PM
F169740149: D42156.id128545.diff
Wed, Sep 2, 10:36 AM
F169738072: D42156.diff
Wed, Sep 2, 10:28 AM
F169705415: D42156.diff
Wed, Sep 2, 8:28 AM
F169531659: D42156.id185486.diff
Tue, Sep 1, 8:18 PM
F169524641: D42156.id.diff
Tue, Sep 1, 7:45 PM
Unknown Object (File)
Tue, Sep 1, 6:53 PM

Details

Reviewers
None
Group Reviewers
Src Committers
Summary

Respect PORTSDIR variable for those who have the ports collection in a different
place than /usr/ports. PORTSDIR is a very common variable used in the ports
framework and in /etc/make.conf among other places.

Add note to manual page.
.Dd to be bumped at commit time.

Note that this same behavior can be achieved by doing something like:

export PORTSDIR=~/FreeBSD-repos/ports
whereis -S $PORTSDIR/** -f converseen

Assuming the shell is able to expand the **, but it is much less convenient.

Test Plan

Assuming the ports tree is in $HOME/FreeBSD-repos/ports and that there is no
/usr/ports, if we execute the following:

$ whereis converseen
converseen:

Apply the patch and run the following:

$ PORTSDIR=$HOME/FreeBSD-repos/ports ./whereis converseen
converseen: /home/fernape/FreeBSD-repos/ports/graphics/converseen

If we create the /usr/ports directory and populate some directories:

$ ls -R /usr/ports/
foo/      graphics/

/usr/ports/foo:
bar/

/usr/ports/foo/bar:

/usr/ports/graphics:
converseen/

/usr/ports/graphics/converseen:
Makefile   distinfo   pkg-descr  pkg-plist

and execute the same command we get the /usr/ports result as expected:

$ PORTSDIR=$HOME/FreeBSD-repos/ports ./whereis converseen
converseen: /usr/ports/graphics/converseen

Asking for all results gives both entries:

$ PORTSDIR=$HOME/FreeBSD-repos/ports ./whereis -a converseen
converseen: /usr/ports/graphics/converseen
/home/fernape/FreeBSD-repos/ports/graphics/converseen

Unsetting the variable works as expected:

$ ./whereis -a converseen
converseen: /usr/ports/graphics/converseen

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 75986
Build 72869: arc lint + arc unit

Event Timeline

delphij added inline comments.
usr.bin/whereis/whereis.c
382–383

Why not simply using b here for the assignment? (For readability you might want to set b as NULL afterward to make it explicit that the ownership is changed, but doing strdup() here seems to be redundant, and OOM situation is not handled).

Remove spurious string copy.

While here fix indentation.

fernape added inline comments.
usr.bin/whereis/whereis.c
382–383

Thanks for having a look at this. I don't see a reason to duplicate the string, and if at some point I did, I honestly do not remember.

While here, let me fix the indentation in the for loop.

ngie added inline comments.
usr.bin/whereis/whereis.c
323
328–330
334
336–337

This feels unnecessary given the prior stat call.

367–369

Please use asprintf, etc, to build paths instead of 3 separate calls.

fernape marked an inline comment as done.

Address feedback by ngie@

fernape added inline comments.
usr.bin/whereis/whereis.c
367–369

There are other (old) instances of this sequential triplet of strcat calls around. Let me know if you think we should change them as well.

usr.bin/whereis/whereis.c
317

Where is b freed after this change?

348–352

Let's get rid of an antique CVS reference while here :).

357–359

This seems a bit suspect: you could technically set the locale to "C" to get this behavior and use isupper here. Not sure why the original author thought this was the best approach to take...

367–369

There are other (old) instances of this sequential triplet of strcat calls around. Let me know if you think we should change them as well.

Sounds like a good junior cleanup task / opportunity for adding new tests (as needed!) :).