Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
OS: make more os specific behaviour dynamic
Baptiste Daroussin committed 1 year ago
commit 74f7b9167ba04ed00a9dddb1a6643133cd400844
parent 41519b7
5 files changed +23 -33
modified libpkg/elfhints.c
@@ -315,9 +315,8 @@ int shlib_list_from_rpath(const char *rpath_str, const char *dirpath)
int
shlib_list_from_elf_hints(const char *hintsfile)
{
-
#if defined __FreeBSD__ || defined __DragonFly__
-
	read_elf_hints(hintsfile, 1);
-
#endif
+
	if (ctx.oi->ostype == OS_FREEBSD || ctx.oi->ostype == OS_DRAGONFLY)
+
		read_elf_hints(hintsfile, 1);

	return (scan_dirs_for_shlibs(&shlibs, ndirs, dirs, true));
}
modified libpkg/pkg_config.c
@@ -1114,8 +1114,7 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)
		strlcpy(oi.abi, envabi, sizeof(oi.abi));
		pkg_arch_to_legacy(oi.abi, oi.altabi, sizeof(oi.abi));
	}
-
	if (oi.ostype == OS_FREEBSD)
-
		ctx.osversion = oi.osversion;
+
	ctx.oi = &oi;
	if (parsed != false) {
		pkg_emit_error("pkg_init() must only be called once");
		err = EPKG_FATAL;
@@ -1414,9 +1413,6 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)

	dbg(1, "pkg initialized");

-
	if (oi.ostype == OS_FREEBSD)
-
		ctx.osversion = pkg_object_int(pkg_config_get("OSVERSION"));
-

	/* Start the event pipe */
	evpipe = pkg_object_string(pkg_config_get("EVENT_PIPE"));
	if (evpipe != NULL)
modified libpkg/pkg_create.c
@@ -565,13 +565,10 @@ fixup_abi(struct pkg *pkg, const char *rootdir, bool testing)

	/* if no arch autodetermine it */
	if (pkg->abi == NULL) {
-
#ifdef __FreeBSD__
-
		char *osversion;
-
		xasprintf(&osversion, "%d", ctx.osversion);
-
		pkg_kv_add(&pkg->annotations, "FreeBSD_version", osversion, "annotation");
-
#endif
-
		arch = pkg_object_string(pkg_config_get("ABI"));
-
		pkg->abi = xstrdup(arch);
+
		if (ctx.oi->ostype == OS_FREEBSD) {
+
			pkg_kv_add(&pkg->annotations, "FreeBSD_version", xstrdup(ctx.oi->str_osversion), "annotation");
+
		}
+
		pkg->abi = xstrdup(ctx.oi->abi);
		defaultarch = true;
	}

modified libpkg/private/pkg.h
@@ -136,6 +136,19 @@ struct pkg_stringlist_iterator {
	void *cur;
};

+
struct os_info {
+
	int osversion;
+
	int ostype;
+
	char *name;
+
	char *version;
+
	char *version_major;
+
	char *version_minor;
+
	char *arch;
+
	char abi[BUFSIZ];
+
	char altabi[BUFSIZ];
+
	char str_osversion[BUFSIZ];
+
};
+

struct pkg_ctx {
	int eventpipe;
	int64_t debug_level;
@@ -163,6 +176,7 @@ struct pkg_ctx {
	bool defer_triggers;
	bool repo_accept_legacy_pkg;
	ip_version_t ip;
+
	struct os_info *oi;
	bool ischrooted;
};

@@ -624,19 +638,6 @@ typedef enum {
	PKG_RC_STOP
} pkg_rc_attr;

-
struct os_info {
-
	int osversion;
-
	int ostype;
-
	char *name;
-
	char *version;
-
	char *version_major;
-
	char *version_minor;
-
	char *arch;
-
	char abi[BUFSIZ];
-
	char altabi[BUFSIZ];
-
	char str_osversion[BUFSIZ];
-
};
-

int pkg_get_myarch_with_legacy(struct os_info *);

/**
modified libpkg/utils.c
@@ -358,7 +358,8 @@ is_valid_abi(const char *arch, bool emit_error) {
bool
is_valid_os_version(struct pkg *pkg)
{
-
#ifdef __FreeBSD__
+
	if (ctx.oi->ostype != OS_FREEBSD)
+
		return (true);
	const char *fbsd_version;
	const char *errstr = NULL;
	int fbsdver;
@@ -405,10 +406,6 @@ is_valid_os_version(struct pkg *pkg)
		}
	}
	return (true);
-
#else
-
	return (true);
-
#endif
-

}

void