Page MenuHomeFreeBSD

pkgconf: determine the default paths dynamically
ClosedPublic

Authored by khorben on May 26 2026, 1:59 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Jul 13, 4:50 PM
Unknown Object (File)
Mon, Jul 13, 1:42 AM
Unknown Object (File)
Mon, Jul 13, 12:25 AM
Unknown Object (File)
Sun, Jul 12, 11:08 PM
Unknown Object (File)
Fri, Jul 10, 10:18 PM
Unknown Object (File)
Fri, Jul 10, 10:14 PM
Unknown Object (File)
Thu, Jul 9, 10:28 PM
Unknown Object (File)
Wed, Jul 8, 7:45 AM
Subscribers

Details

Summary

This computes the correct LOCALBASE from the environment or from the "user.localbase" sysctl, in this order.

Sponsored by: The FreeBSD Foundation

Test Plan

Tested as follows:

$ sysctl user.localbase
user.localbase: /usr/local
$ pkgconf --dump-personality
Triplet: default
DefaultSearchPaths: /usr/local/libdata/pkgconfig:/usr/libdata/pkgconfig:/usr/local/share/pkgconfig
SystemIncludePaths: /usr/include
SystemLibraryPaths: /usr/lib
$ LOCALBASE=/opt/vendor pkgconf --dump-personality
Triplet: default
DefaultSearchPaths: /opt/vendor/libdata/pkgconfig:/usr/libdata/pkgconfig:/opt/vendor/share/pkgconfig
SystemIncludePaths: /usr/include
SystemLibraryPaths: /usr/lib
$ sudo sysctl -w user.localbase=/opt/vendor2
user.localbase: /usr/local -> /opt/vendor2
$ pkgconf --dump-personality
Triplet: default
DefaultSearchPaths: /opt/vendor2/libdata/pkgconfig:/usr/libdata/pkgconfig:/opt/vendor2/share/pkgconfig
SystemIncludePaths: /usr/include
SystemLibraryPaths: /usr/lib

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

contrib/pkgconf/libpkgconf/personality.c
121

Reading this again, I think this code will never be reached, so we wouldn't even need -DLOCALBASE=... in CFLAGS.

This update takes care of PERSONALITY_PATH in addition to PKG_DEFAULT_PATH.

khorben edited the test plan for this revision. (Show Details)
contrib/pkgconf/libpkgconf/personality.c
108

Just use a stack buffer. The result will never be longer than MAXPATHLEN including the terminating null character.

129

It seems odd to use err() here, how does the rest of pkgconf deal with string handling failures?

Use a stack buffer of MAXPATHLEN for localbase, as suggested by @des.

contrib/pkgconf/libpkgconf/personality.c
129

Interestingly, I just identified two similar functions that use malloc(), check for errors, and report them: bool pkgconf_buffer_append_fmt() and bool pkgconf_buffer_append_vfmt() (true is success, false is error). But then when called from build_default_search_path() (the same place we are patching) possible errors are ignored, and the result inconsistent. I don't think there's much risk there so we could probably do the same... 🤔

contrib/pkgconf/libpkgconf/personality.c
108

this snprintf() is pointless, I would do the reverse: add str = localbase; to the other branch and pass str to pkgconf_buffer_append() below. You may want to rename localbase to buf and str to localbase.

Simplified the code obtaining LOCALBASE as per @des' suggestion. (Thanks!)

contrib/pkgconf/libpkgconf/personality.c
108
111

redundant braces

409
412

redundant braces

des requested changes to this revision.May 29 2026, 10:00 PM

please mark obsolete comments as done and fix the remaining four issues

contrib/pkgconf/libpkgconf/personality.c
111

redundant

412

redundant

This revision now requires changes to proceed.May 29 2026, 10:00 PM
khorben edited the summary of this revision. (Show Details)

Remove redundant code, as suggested by des@. (Thanks!)

khorben marked 6 inline comments as done and an inline comment as not done.Jun 1 2026, 4:04 PM
khorben marked 2 inline comments as done.
This revision is now accepted and ready to land.Jun 2 2026, 8:34 AM