Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Drop usage of STAILQ from the frontend it is not available on all implementation of sys/queue.h
Baptiste Daroussin committed 10 years ago
commit ea1c17a258a1aff184aea5a210ad8f5c25162261
parent 6611079
3 files changed +44 -42
modified src/check.c
@@ -38,6 +38,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+
#include <utlist.h>

#include <pkg.h>

@@ -47,20 +48,19 @@ struct deps_entry {
	char *name;
	char *version;
	char *origin;
-
	STAILQ_ENTRY(deps_entry) next;
+
	struct deps_entry *next;
+
	struct deps_entry *prev;
};

-
STAILQ_HEAD(deps_head, deps_entry);
-

-
static int check_deps(struct pkgdb *db, struct pkg *pkg, struct deps_head *dh,
+
static int check_deps(struct pkgdb *db, struct pkg *pkg, struct deps_entry *dh,
    bool noinstall, struct sbuf *out);
-
static void add_missing_dep(struct pkg_dep *d, struct deps_head *dh, int *nbpkgs);
-
static void deps_free(struct deps_head *dh);
-
static int fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs);
-
static void check_summary(struct pkgdb *db, struct deps_head *dh);
+
static void add_missing_dep(struct pkg_dep *d, struct deps_entry *dh, int *nbpkgs);
+
static void deps_free(struct deps_entry *dh);
+
static int fix_deps(struct pkgdb *db, struct deps_entry *dh, int nbpkgs);
+
static void check_summary(struct pkgdb *db, struct deps_entry *dh);

static int
-
check_deps(struct pkgdb *db, struct pkg *p, struct deps_head *dh, bool noinstall, struct sbuf *out)
+
check_deps(struct pkgdb *db, struct pkg *p, struct deps_entry *dh, bool noinstall, struct sbuf *out)
{
	struct pkg_dep *dep = NULL;
	struct pkgdb_it *it;
@@ -119,7 +119,7 @@ check_deps(struct pkgdb *db, struct pkg *p, struct deps_head *dh, bool noinstall
}

static void
-
add_missing_dep(struct pkg_dep *d, struct deps_head *dh, int *nbpkgs)
+
add_missing_dep(struct pkg_dep *d, struct deps_entry *dh, int *nbpkgs)
{
	struct deps_entry *e = NULL;
	const char *name = NULL;
@@ -129,9 +129,10 @@ add_missing_dep(struct pkg_dep *d, struct deps_head *dh, int *nbpkgs)
	/* do not add duplicate entries in the queue */
	name = pkg_dep_name(d);

-
	STAILQ_FOREACH(e, dh, next)
+
	DL_FOREACH(dh, e) {
		if (strcmp(e->name, name) == 0)
			return;
+
	}

	if ((e = calloc(1, sizeof(struct deps_entry))) == NULL)
		err(1, "calloc(deps_entry)");
@@ -142,17 +143,16 @@ add_missing_dep(struct pkg_dep *d, struct deps_head *dh, int *nbpkgs)

	(*nbpkgs)++;

-
	STAILQ_INSERT_TAIL(dh, e, next);
+
	DL_APPEND(dh, e);
}

static void
-
deps_free(struct deps_head *dh)
+
deps_free(struct deps_entry *dh)
{
-
	struct deps_entry *e = NULL;
+
	struct deps_entry *e, *etmp;

-
	while (!STAILQ_EMPTY(dh)) {
-
		e = STAILQ_FIRST(dh);
-
		STAILQ_REMOVE_HEAD(dh, next);
+
	DL_FOREACH_SAFE(dh, e, etmp) {
+
		DL_DELETE(dh, e);
		free(e->name);
		free(e->version);
		free(e->origin);
@@ -161,7 +161,7 @@ deps_free(struct deps_head *dh)
}

static int
-
fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs)
+
fix_deps(struct pkgdb *db, struct deps_entry *dh, int nbpkgs)
{
	struct pkg_jobs *jobs = NULL;
	struct deps_entry *e = NULL;
@@ -176,7 +176,7 @@ fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs)
	if ((pkgs = calloc(nbpkgs, sizeof (char *))) == NULL)
		err(1, "calloc()");

-
	STAILQ_FOREACH(e, dh, next)
+
	DL_FOREACH(dh, e)
		pkgs[i++] = e->name;

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
@@ -229,7 +229,7 @@ cleanup:
}

static void
-
check_summary(struct pkgdb *db, struct deps_head *dh)
+
check_summary(struct pkgdb *db, struct deps_entry *dh)
{
	struct deps_entry *e = NULL;
	struct pkg *pkg = NULL;
@@ -240,7 +240,7 @@ check_summary(struct pkgdb *db, struct deps_head *dh)

	printf(">>> Summary of actions performed:\n\n");
		
-
	STAILQ_FOREACH(e, dh, next) {
+
	DL_FOREACH(dh, e) {
		if ((it = pkgdb_query(db, e->name, MATCH_EXACT)) == NULL)
			return;
		
@@ -308,7 +308,7 @@ exec_check(int argc, char **argv)
		{ NULL,			0,		NULL,	0   },
	};

-
	struct deps_head dh = STAILQ_HEAD_INITIALIZER(dh);
+
	struct deps_entry *dh = NULL;

	processed = 0;

@@ -455,7 +455,7 @@ exec_check(int argc, char **argv)
			if (dcheck) {
				if (!quiet && verbose)
					printf(" dependencies...");
-
				nbpkgs += check_deps(db, pkg, &dh, noinstall, out);
+
				nbpkgs += check_deps(db, pkg, dh, noinstall, out);
				if (noinstall && nbpkgs > 0) {
					rc = EX_UNAVAILABLE;
				}
@@ -527,9 +527,9 @@ exec_check(int argc, char **argv)
			printf(">>> Found %d issue(s) in the package database.\n\n", nbpkgs);
			if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY,
					PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) {
-
				ret = fix_deps(db, &dh, nbpkgs);
+
				ret = fix_deps(db, dh, nbpkgs);
				if (ret == EPKG_OK)
-
					check_summary(db, &dh);
+
					check_summary(db, dh);
				else if (ret == EPKG_ENODB) {
					db = NULL;
					rc = EX_IOERR;
@@ -553,7 +553,7 @@ cleanup:
		progressbar_stop();
	if (msg != NULL)
		sbuf_delete(msg);
-
	deps_free(&dh);
+
	deps_free(dh);
	pkg_free(pkg);
	pkgdb_release_lock(db, PKGDB_LOCK_ADVISORY);
	pkgdb_close(db);
modified src/create.c
@@ -46,16 +46,17 @@
#include <pkg.h>
#include <string.h>
#include <unistd.h>
+
#include <utlist.h>
#include <sysexits.h>

#include "pkgcli.h"

struct pkg_entry {
	struct pkg *pkg;
-
	STAILQ_ENTRY(pkg_entry) next;
+
	struct pkg_entry *next;
+
	struct pkg_entry *prev;
};
-

-
STAILQ_HEAD(pkg_head, pkg_entry);
+
struct pkg_entry *pkg_head = NULL;

void
usage_create(void)
@@ -85,8 +86,7 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
	    PKG_LOAD_USERS | PKG_LOAD_GROUPS | PKG_LOAD_SHLIBS_REQUIRED |
	    PKG_LOAD_PROVIDES | PKG_LOAD_REQUIRES |
	    PKG_LOAD_SHLIBS_PROVIDED | PKG_LOAD_ANNOTATIONS;
-
	struct pkg_head head = STAILQ_HEAD_INITIALIZER(head);
-
	struct pkg_entry *e = NULL;
+
	struct pkg_entry *e = NULL, *etmp;
	char pkgpath[MAXPATHLEN];
	const char *format = NULL;
	bool foundone;
@@ -133,7 +133,7 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
				err(1, "malloc(pkg_entry)");
			e->pkg = pkg;
			pkg = NULL;
-
			STAILQ_INSERT_TAIL(&head, e, next);
+
			DL_APPEND(pkg_head, e);
			foundone = true;
		}
		if (!foundone) {
@@ -147,9 +147,8 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
			retcode++;
	}

-
	while (!STAILQ_EMPTY(&head)) {
-
		e = STAILQ_FIRST(&head);
-
		STAILQ_REMOVE_HEAD(&head, next);
+
	DL_FOREACH_SAFE(pkg_head, e, etmp) {
+
		DL_DELETE(pkg_head, e);

		if (!overwrite) {
			pkg_snprintf(pkgpath, sizeof(pkgpath), "%S/%n-%v.%S",
modified src/main.c
@@ -51,6 +51,7 @@
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
+
#include <utlist.h>
#include <unistd.h>
#ifdef HAVE_LIBJAIL
#include <jail.h>
@@ -119,13 +120,14 @@ static struct commands {

static const unsigned int cmd_len = NELEM(cmd);

-
static STAILQ_HEAD(, plugcmd) plugins = STAILQ_HEAD_INITIALIZER(plugins);
struct plugcmd {
	const char *name;
	const char *desc;
	int (*exec)(int argc, char **argv);
-
	STAILQ_ENTRY(plugcmd) next;
+
	struct plugcmd *next;
+
	struct plugcmd *prev;
};
+
static struct plugcmd *plugins = NULL;

typedef int (register_cmd)(int idx, const char **name, const char **desc, int (**exec)(int argc, char **argv));
typedef int (nb_cmd)(void);
@@ -202,8 +204,9 @@ usage(const char *conffile, const char *reposdir, FILE *out, enum pkg_usage_reas

			fprintf(out, "\nCommands provided by plugins:\n");

-
			STAILQ_FOREACH(c, &plugins, next)
-
			fprintf(out, "\t%-15s%s\n", c->name, c->desc);
+
			DL_FOREACH(plugins, c) {
+
				fprintf(out, "\t%-15s%s\n", c->name, c->desc);
+
			}
		}
		fprintf(out, "\nFor more information on the different commands"
					" see 'pkg help <command>'.\n");
@@ -252,7 +255,7 @@ exec_help(int argc, char **argv)
	plugins_enabled = pkg_object_bool(pkg_config_get("PKG_ENABLE_PLUGINS"));

	if (plugins_enabled) {
-
		STAILQ_FOREACH(c, &plugins, next) {
+
		DL_FOREACH(plugins, c) {
			if (strcmp(c->name, argv[1]) == 0) {
				if (asprintf(&manpage, "/usr/bin/man pkg-%s", c->name) == -1)
					errx(EX_SOFTWARE, "cannot allocate memory");
@@ -763,7 +766,7 @@ main(int argc, char **argv)
				for (j = 0; j < n ; j++) {
					c = malloc(sizeof(struct plugcmd));
					reg(j, &c->name, &c->desc, &c->exec);
-
					STAILQ_INSERT_TAIL(&plugins, c, next);
+
					DL_APPEND(plugins, c);
				}
			}
		}
@@ -829,7 +832,7 @@ main(int argc, char **argv)
		/* Check if a plugin provides the requested command */
		ret = EPKG_FATAL;
		if (plugins_enabled) {
-
			STAILQ_FOREACH(c, &plugins, next) {
+
			DL_FOREACH(plugins, c) {
				if (strcmp(c->name, argv[0]) == 0) {
					plugin_found = true;
					ret = c->exec(argc, argv);