pkg_install: some uname normalisation.

This commit is contained in:
Ben Gras 2010-07-22 08:28:12 +00:00
parent e8e2f6f6b9
commit 81f6039a7f

View File

@ -46,6 +46,7 @@ __RCSID("$NetBSD: perform.c,v 1.97 2010/06/16 23:02:48 joerg Exp $");
#ifdef __minix
#include <stdint.h>
#include <assert.h>
#endif
#include <sys/utsname.h>
@ -836,6 +837,26 @@ pkg_register_depends(struct pkg_task *pkg)
free(text);
}
static void
normalise_version(char *release, char *version)
{
char actual_version[20];
assert(release && version);
if(strlen(release) > 0 && strlen(version) > 0)
sprintf(actual_version, "%s.%s", release, version);
else if(strlen(release) > 0)
strcpy(actual_version, release);
else if(strlen(version) > 0)
strcpy(actual_version, version);
else
errx(EXIT_FAILURE, "no version info");
strcpy(release, actual_version);
version[0] = '\0';
}
/*
* Reduce the result from uname(3) to a canonical form.
*/
@ -848,6 +869,7 @@ normalise_platform(struct utsname *host_name)
span = strspn(host_name->release, "0123456789.");
host_name->release[span] = '\0';
#endif
normalise_version(host_name->release, host_name->version);
}
/*
@ -882,24 +904,21 @@ check_platform(struct pkg_task *pkg)
strcmp(effective_arch, pkg->buildinfo[BI_MACHINE_ARCH]) != 0)
fatal = 1;
if (strcmp(host_uname.release, pkg->buildinfo[BI_OS_RELEASE]) != 0)
fatal = 1;
normalise_version(host_uname.release, host_uname.version);
if (strcmp(host_uname.version, pkg->buildinfo[BI_OS_VERSION]) != 0)
if (strcmp(host_uname.release, pkg->buildinfo[BI_OS_RELEASE]) != 0)
fatal = 1;
if (fatal) {
warnx("Warning: package `%s' was built for a platform:",
pkg->pkgname);
warnx("%s/%s %s %s (pkg) vs. %s/%s %s %s (this host)",
warnx("%s/%s %s (pkg) vs. %s/%s %s (this host)",
pkg->buildinfo[BI_OPSYS],
pkg->buildinfo[BI_MACHINE_ARCH],
pkg->buildinfo[BI_OS_RELEASE],
pkg->buildinfo[BI_OS_VERSION],
OPSYS_NAME,
effective_arch,
host_uname.release,
host_uname.version);
host_uname.release);
if (!Force && fatal)
return -1;
}