Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add plugins code for initialization and shutdown
Marin Atanasov Nikolov committed 13 years ago
commit d346148eb7f9473fe615316829089e60b51d4e73
parent 253bb7f
4 files changed +31 -3
modified libpkg/Makefile
@@ -33,7 +33,8 @@ SRCS= backup.c \
		scripts.c \
		update.c \
		usergroup.c \
-
		utils.c
+
		utils.c \
+
		plugins.c

HAVE_GRUTILS!=	grep -q gr_copy /usr/include/libutil.h && echo yes || echo no

modified libpkg/pkg.h
@@ -260,6 +260,7 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_PORTAUDIT_SITE,
	PKG_CONFIG_SRV_MIRROR,
	PKG_CONFIG_FETCH_RETRY,
+
	PKG_CONFIG_PLUGINS_DIR
} pkg_config_key;

typedef enum {
@@ -277,6 +278,17 @@ typedef enum _pkg_stats_t {
} pkg_stats_t;

/**
+
 * Keys for accessing pkg plugins data
+
 */
+
typedef enum _pkg_plugin_key {
+
	PKG_PLUGIN_NAME = 0,
+
	PKG_PLUGIN_DESC,
+
	PKG_PLUGIN_VERSION,
+
	PKG_PLUGIN_PLUGINFILE,
+
	PKG_PLUGIN_ENABLED,
+
} pkg_plugin_key;
+

+
/**
 * Error type used everywhere by libpkg.
 */
typedef enum {
@@ -873,6 +885,13 @@ int pkg_update(const char *name, const char *packagesite, bool force);
int64_t pkgdb_stats(struct pkgdb *db, pkg_stats_t type);

/**
+
 * pkg plugins functions
+
 * @todo Document
+
 */
+
int pkg_plugin_init(void);
+
int pkg_plugin_shutdown(void);
+

+
/**
 * Get the value of a configuration key
 */
int pkg_config_string(pkg_config_key key, const char **value);
modified libpkg/pkg_config.c
@@ -173,9 +173,9 @@ static struct config_entry c[] = {
		"3",
		{ NULL }
	},
-
	[PKG_PLUGINS_DIR] = {
+
	[PKG_CONFIG_PLUGINS_DIR] = {
		STRING,
-
		"PKG_PLUGINS_DIR"
+
		"PKG_PLUGINS_DIR",
		"/usr/local/etc/pkg/plugins",
		{ NULL }
	},
@@ -476,6 +476,7 @@ pkg_init(const char *path)
	yaml_document_delete(&doc);
	yaml_parser_delete(&parser);

+

	parsed = true;
	return (EPKG_OK);
}
modified pkg/main.c
@@ -242,6 +242,9 @@ main(int argc, char **argv)
	if (pkg_init(NULL) != EPKG_OK)
		errx(EX_SOFTWARE, "Cannot parse configuration file!");

+
	if (pkg_plugin_init() != EPKG_OK)
+
		errx(EX_SOFTWARE, "Plugins cannot be loaded");
+

	if (version > 1) {
		printf("version: "PKGVERSION""GITHASH"\n");
		pkg_config_string(PKG_CONFIG_ABI, &buf);
@@ -280,6 +283,7 @@ main(int argc, char **argv)
			printf("Repository: %s\n", buf ? buf : "none");
		}
		pkg_shutdown();
+
		pkg_plugin_shutdown();
		exit(EX_OK);
	}

@@ -305,6 +309,7 @@ main(int argc, char **argv)

	if (command == NULL) {
		pkg_shutdown();
+
		pkg_plugin_shutdown();
		usage();
		return (ret); /* Not reached but makes scanbuild happy */
	}
@@ -324,6 +329,8 @@ main(int argc, char **argv)
	}

	pkg_shutdown();
+
	pkg_plugin_shutdown();
+
	
	return (ret);
}