Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Check for OSVERSION during 'pkg add'
Marin Atanasov Nikolov committed 14 years ago
commit f569c7c42814b54a093493080160906c1bd7a9dd
parent a0cab825d7b72feca47d5ebc3d4a57a27f0be2e5
2 files changed +44 -25
modified libpkg/pkg_add.c
@@ -1,11 +1,14 @@
+
#include <sys/param.h>
#include <sys/utsname.h>

#include <archive.h>
#include <archive_entry.h>
#include <assert.h>
#include <libgen.h>
+
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+
#include <sysexits.h>
#include <errno.h>

#include "pkg.h"
@@ -15,15 +18,15 @@
static int
dep_installed(struct pkg_dep *dep, struct pkgdb *db) {
	struct pkg *p = NULL;
-
	struct pkgdb_it *it;
-
	int ret;
+
	struct pkgdb_it *it = NULL;
+
	int ret = EX_OK;

	it = pkgdb_query(db, pkg_dep_origin(dep), MATCH_EXACT);

	if (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == EPKG_OK) {
-
		ret = EPKG_OK;
+
		ret = EX_OK;
	} else {
-
		ret = EPKG_FATAL;
+
		ret = EX_IOERR;
	}

	pkgdb_it_free(it);
@@ -35,8 +38,8 @@ dep_installed(struct pkg_dep *dep, struct pkgdb *db) {
static int
do_extract(struct archive *a, struct archive_entry *ae)
{
-
	int retcode = EPKG_OK;
-
	int ret = 0;
+
	int retcode = EX_OK;
+
	int ret = EX_OK;
	char path[MAXPATHLEN + 1];
	struct stat st;

@@ -44,7 +47,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
		if (archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS) != ARCHIVE_OK) {
			pkg_emit_error("archive_read_extract(): %s",
						   archive_error_string(a));
-
			retcode = EPKG_FATAL;
+
			retcode = EX_IOERR;
			break;
		}

@@ -62,7 +65,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
			if (archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS) != ARCHIVE_OK) {
				pkg_emit_error("archive_read_extract(): %s",
							   archive_error_string(a));
-
				retcode = EPKG_FATAL;
+
				retcode = EX_IOERR;
				break;
			}
		}
@@ -71,7 +74,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
	if (ret != ARCHIVE_EOF) {
		pkg_emit_error("archive_read_next_header(): %s",
					   archive_error_string(a));
-
		retcode = EPKG_FATAL;
+
		retcode = EX_IOERR;
	}

	return (retcode);
@@ -86,20 +89,22 @@ pkg_add(struct pkgdb *db, const char *path)
int
pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
{
-
	struct archive *a;
-
	struct archive_entry *ae;
-
	struct pkgdb_it *it;
+
	struct archive *a = NULL;
+
	struct archive_entry *ae = NULL;
+
	struct pkgdb_it *it = NULL;
	struct pkg *p = NULL;
	struct pkg *pkg = NULL;
	struct pkg_dep *dep = NULL;
	struct utsname u;
	bool extract = true;
	char dpath[MAXPATHLEN + 1];
-
	const char *basedir;
-
	const char *ext;
-
	int retcode = EPKG_OK;
-
	int ret;
+
	const char *basedir = NULL;
+
	const char *ext = NULL;
+
	char *osversion = NULL;
+
	int retcode = EX_OK;
+
	int ret = EPKG_OK;

+
	assert(db != NULL);
	assert(path != NULL);

	/*
@@ -120,7 +125,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)

	if (uname(&u) != 0) {
		pkg_emit_errno("uname", "");
-
		retcode = EPKG_FATAL;
+
		retcode = EX_OSERR;
		goto cleanup;
	}

@@ -130,20 +135,31 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
	if (strcmp(u.machine, pkg_get(pkg, PKG_ARCH)) != 0) {
		pkg_emit_error("wrong architecture: %s instead of %s",
					   pkg_get(pkg, PKG_ARCH), u.machine);
-
		retcode = EPKG_FATAL;
+
		retcode = EX_CONFIG;
		goto cleanup;
	}

	/*
-
	 * TODO: check the os version
+
	 * Check for OSVERSION
	 */
+
	if (strstr(u.release, "RELEASE") == NULL)
+
		asprintf(&osversion, "%s-%d", u.release, __FreeBSD_version);
+
	else
+
		asprintf(&osversion, "%s", u.release);
+

+
	if (strcmp(osversion, pkg_get(pkg, PKG_OSVERSION)) != 0) {
+
		pkg_emit_error("wrong OSVERSION: %s instead of %s",
+
				pkg_get(pkg, PKG_OSVERSION), osversion);
+
		retcode = EX_CONFIG;
+
		goto cleanup;
+
	}

	/*
	 * Check if the package is already installed
	 */
	it = pkgdb_query(db, pkg_get(pkg, PKG_ORIGIN), MATCH_EXACT);
	if (it == NULL) {
-
		retcode = EPKG_FATAL;
+
		retcode = EX_IOERR;
		goto cleanup;
	}

@@ -152,7 +168,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)

	if (ret == EPKG_OK) {
		pkg_emit_already_installed(pkg);
-
		retcode = EPKG_INSTALLED;
+
		retcode = EX_OK;
		goto cleanup;
	} else if (ret != EPKG_END) {
		retcode = ret;
@@ -166,7 +182,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
	basedir = dirname(path);
	if ((ext = strrchr(path, '.')) == NULL) {
		pkg_emit_error("%s has no extension", path);
-
		retcode = EPKG_FATAL;
+
		retcode = EX_OSERR;
		goto cleanup;
	}

@@ -178,7 +194,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)

			if (access(dpath, F_OK) == 0) {
				if (pkg_add2(db, dpath, 0, 1) != EPKG_OK) {
-
					retcode = EPKG_FATAL;
+
					retcode = EX_OSERR;
					goto cleanup;
				}
			} else {
@@ -237,6 +253,9 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
	if (p != NULL)
		pkg_free(p);

+
	if (osversion != NULL)
+
		free(osversion);
+

	pkg_free(pkg);

	return (retcode);
modified pkg/register.c
@@ -50,9 +50,9 @@ exec_register(int argc, char **argv)
{
	struct pkg *pkg = NULL;
	struct pkgdb *db = NULL;
-
	struct utsname u = NULL;
+
	struct utsname u;

-
	regex_t preg = NULL;
+
	regex_t preg;
	regmatch_t pmatch[2];

	int ch;