Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Automatically disable plugins if run from a static binary
Baptiste Daroussin committed 13 years ago
commit 11bbc51848f462a50dfc7fe4c536cc85686886dc
parent f19e27f
3 files changed +28 -1
modified libpkg/pkg_config.c
@@ -29,6 +29,7 @@

#include <assert.h>
#include <ctype.h>
+
#include <dlfcn.h>
#include <err.h>
#include <errno.h>
#include <stdlib.h>
@@ -503,6 +504,28 @@ pkg_config_kv_get(struct pkg_config_kv *kv, pkg_config_kv_t type)
	return (NULL);
}

+
static void
+
disable_plugins_if_static(void)
+
{
+
	void *dlh;
+
	struct pkg_config *conf;
+
	pkg_config_key k = PKG_CONFIG_ENABLE_PLUGINS;
+

+
	HASH_FIND_INT(config, &k, conf);
+

+
	if (!conf->boolean)
+
		return;
+

+
	dlh = dlopen(0, 0);
+
	dlclose(dlh);
+

+
	/* if dlh is 0 then we are in static binary */
+
	if (dlh == 0)
+
		conf->boolean = false;
+

+
	return;
+
}
+

int
pkg_init(const char *path)
{
@@ -612,6 +635,7 @@ pkg_init(const char *path)
	yaml_parser_delete(&parser);

	subst_packagesite();
+
	disable_plugins_if_static();

	parsed = true;
	return (EPKG_OK);
modified libpkg/plugins.c
@@ -383,8 +383,12 @@ pkg_plugins_init(void)
	struct pkg_config_value *v = NULL;
	char pluginfile[MAXPATHLEN];
	const char *plugdir;
+
	bool plug_enabled = false;
	int (*init_func)(struct pkg_plugin *);

+
	pkg_config_bool(PKG_CONFIG_ENABLE_PLUGINS, &plug_enabled);
+
	if (!plug_enabled)
+
		return (EPKG_OK);
	/*
	 * Discover available plugins
	 */
modified pkg/plugins.c
@@ -44,7 +44,6 @@ int
exec_plugins(int argc, char **argv)
{
	struct pkg_plugin *p = NULL;
-
	const char *plugin_name = NULL;
	int ch;
	bool list_only = true;