Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Define OSMAJOR as the OS major version, and add it to CFLAGS when compiling libpkg sources.
Matthew Seaman committed 12 years ago
commit dd7596eb4a2b60830753c0400b129707ec8c1045
parent 923e171
3 files changed +54 -1
modified libpkg/Makefile
@@ -238,6 +238,7 @@ LIBPKGCFLAGS+= -DDEFAULT_MIRROR_TYPE=${DEFAULT_MIRROR_TYPE} \
		-I${.CURDIR}/../external/libucl/include \
		-I${.CURDIR}/../external/libyaml/include \
		-DPREFIX=\"${PREFIX}\" \
+
		-DOSMAJOR=${OSMAJOR} \
		-Wno-pointer-sign
.if !exists(/usr/lib/libelf.so)
LIBPKGCFLAGS+=	-I${.CURDIR}/../external/libelf \
@@ -333,7 +334,8 @@ DEBUG_FLAGS+= -pg
	(cd ${.CURDIR}/../external/libelf ; m4 -D SRCDIR=${.CURDIR}/../external/libelf ${.IMPSRC}) > ${.TARGET}

# Workaround 8.3/8.4 bug
-
OSVERSION!=    /sbin/sysctl -n kern.osreldate
+
OSVERSION!=	/sbin/sysctl -n kern.osreldate
+
OSMAJOR=	${OSVERSION:C/([0-9]*)[0-9]{5}/\1/}

.if ${OSNAME} == FreeBSD && ${OSVERSION} < 901000
.c.o:
modified libpkg/pkg.h.in
@@ -340,6 +340,8 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_DBDIR,
	PKG_CONFIG_CACHEDIR,
	PKG_CONFIG_PORTSDIR,
+
	PKG_CONFIG_INDEXDIR,
+
	PKG_CONFIG_INDEXFILE,
	PKG_CONFIG_REPOKEY,
	PKG_CONFIG_HANDLE_RC_SCRIPTS,
	PKG_CONFIG_ASSUME_ALWAYS_YES,
@@ -1499,6 +1501,7 @@ typedef int(*pkg_event_cb)(void *, struct pkg_event *);

void pkg_event_register(pkg_event_cb cb, void *data);

+
bool pkg_compled_for_same_os_major(void);
int pkg_init(const char *, const char *);
int pkg_initialized(void);
void pkg_shutdown(void);
modified libpkg/pkg_config.c
@@ -27,6 +27,7 @@

#include <assert.h>
#include <sys/socket.h>
+
#include <sys/utsname.h>
#include <sys/un.h>
#include <ctype.h>
#include <dirent.h>
@@ -34,6 +35,8 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+
#include <limits.h>
+
#include <osreldate.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
@@ -47,6 +50,15 @@
#define ABI_VAR_STRING "${ABI}"
#define REPO_NAME_PREFIX "repo-"

+
#if defined(OSMAJOR)
+
/* Oh ye gods of ANSI C, why is this so flipping arcane? */
+
#define STRINGIFY(X)	TEXT(X)
+
#define TEXT(X)		#X
+
#define INDEXFILE	"INDEX-" STRINGIFY(OSMAJOR)
+
#else
+
#define INDEXFILE	INDEX
+
#endif
+

int eventpipe = -1;

struct config_entry {
@@ -94,6 +106,18 @@ static struct config_entry c[] = {
#endif
		"Location of the ports collection",
	},
+
	[PKG_CONFIG_INDEXDIR] = {
+
		PKG_CONFIG_STRING,
+
		"INDEXDIR",
+
		NULL,		/* Default to PORTSDIR unless defined */
+
		"Location of the ports INDEX",
+
	},
+
	[PKG_CONFIG_INDEXFILE] = {
+
		PKG_CONFIG_STRING,
+
		"INDEXFILE"
+
		INDEXFILE,
+
		"Filename of the ports INDEX",
+
	},
	[PKG_CONFIG_REPOKEY] = {
		PKG_CONFIG_STRING,
		"PUBKEY",
@@ -933,6 +957,30 @@ load_repositories(const char *repodir)
		load_repo_files(pkg_config_value(v));
}

+
bool
+
pkg_compiled_for_same_os_major(void)
+
{
+
#ifdef OSMAJOR
+
	struct utsname	u;
+
	int		osmajor;
+

+
	/* Are we running the same OS major version as the one we were
+
	 * compiled under? */
+

+
	if (uname(&u) != 0) {
+
		pkg_emit_error("Cannot determine OS version number");
+
		return (true);	/* Can't tell, so assume yes  */
+
	}
+

+
	osmajor = (int) strtol(u.release, NULL, 10);
+

+
	return (osmajor == OSMAJOR);
+

+
#else
+
	return (true);		/* Can't tell, so assume yes  */
+
#endif
+
}
+


int
pkg_init(const char *path, const char *reposdir)