Skip to content

Commit

Permalink
libpkg: scan /usr/lib32 for system libs if needed
Browse files Browse the repository at this point in the history
Since pkg now tracks 32-bit compat shlib dependencies, we must take the
32-bit compat shlibs provided by the base system into account if not
targeting a pkgbase system.

Sponsored by:	The FreeBSD Foundation
  • Loading branch information
ifreund committed Dec 11, 2024
1 parent 0e628a4 commit 81feee9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libpkg/pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ pkg_shlib_flags_from_abi(const struct pkg_abi *shlib_abi)
* libfoo.so.1.0.0:Linux - compat Linux
* libfoo.so.1.0.0:Linux:32 - compat Linux 32
*/
static char *
char *
pkg_shlib_name_with_flags(const char *name, enum pkg_shlib_flags flags)
{
const char *compat_os = "";
Expand Down
5 changes: 5 additions & 0 deletions libpkg/private/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,11 @@ enum pkg_shlib_flags {
};
/* Determine shlib flags by comparing the shlib abi with ctx.abi */
enum pkg_shlib_flags pkg_shlib_flags_from_abi(const struct pkg_abi *shlib_abi);
/*
* Given an unadorned shlib name (e.g. libfoo.so.1.0.0) return a newly allocated
* string with the given flags appended (e.g. libfoo.so.1.0.0:Linux:32).
*/
char *pkg_shlib_name_with_flags(const char *name, enum pkg_shlib_flags flags);
int pkg_addshlib_required(struct pkg *pkg, const char *name, enum pkg_shlib_flags);
/* No checking for duplicates or filtering */
int pkg_addshlib_required_raw(struct pkg *pkg, const char *name);
Expand Down
26 changes: 17 additions & 9 deletions libpkg/system_shlibs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
#include "pkg.h"
#include "pkghash.h"
#include "private/event.h"
#include "private/pkg.h"
#include "xmalloc.h"

static int
scan_dir_for_shlibs(pkghash **shlib_list, const char *dir)
scan_dir_for_shlibs(pkghash **shlib_list, const char *dir,
enum pkg_shlib_flags flags)
{
DIR *dirp= opendir(dir);
if (dirp == NULL) {
Expand Down Expand Up @@ -58,30 +60,36 @@ scan_dir_for_shlibs(pkghash **shlib_list, const char *dir)
continue;

/* We have a valid shared library name. */
pkghash_safe_add(*shlib_list, dp->d_name, NULL, NULL);
char *full = pkg_shlib_name_with_flags(dp->d_name, flags);
pkghash_safe_add(*shlib_list, full, NULL, NULL);
free(full);
}

closedir(dirp);

return (EPKG_OK);
}

static const char *system_shlib_dirs[] = {
"/lib",
"/usr/lib",
static struct {
const char *dir;
enum pkg_shlib_flags flags;
} system_shlib_table[] = {
{"/lib", PKG_SHLIB_FLAGS_NONE },
{"/usr/lib", PKG_SHLIB_FLAGS_NONE },
{"/usr/lib32", PKG_SHLIB_FLAGS_COMPAT_32 },
};

int
scan_system_shlibs(pkghash **system_shlibs, const char *rootdir)
{
for (int i = 0; i < NELEM(system_shlib_dirs); i++) {
for (int i = 0; i < NELEM(system_shlib_table); i++) {
char *dir;
if (rootdir != NULL) {
xasprintf(&dir, "%s%s", rootdir, system_shlib_dirs[i]);
xasprintf(&dir, "%s%s", rootdir, system_shlib_table[i].dir);
} else {
dir = xstrdup(system_shlib_dirs[i]);
dir = xstrdup(system_shlib_table[i].dir);
}
int ret = scan_dir_for_shlibs(system_shlibs, dir);
int ret = scan_dir_for_shlibs(system_shlibs, dir, system_shlib_table[i].flags);
free(dir);
if (ret != EPKG_OK) {
return (ret);
Expand Down

0 comments on commit 81feee9

Please sign in to comment.