Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
libpkg: scan /usr/lib32 for system libs if needed
Isaac Freund committed 1 year ago
commit 189bb2ac3c849ba3e1ac2aab2f7b28470f7a17c3
parent 3882f0f
3 files changed +23 -10
modified libpkg/pkg.c
@@ -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 = "";
modified libpkg/private/pkg.h
@@ -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);
modified libpkg/system_shlibs.c
@@ -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) {
@@ -58,7 +60,9 @@ 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);
@@ -66,22 +70,26 @@ scan_dir_for_shlibs(pkghash **shlib_list, const char *dir)
	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);