diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | src/vat/plugin.h | 1 | ||||
-rw-r--r-- | src/vpp/api/plugin.c | 16 | ||||
-rw-r--r-- | src/vpp/vnet/main.c | 54 |
4 files changed, 61 insertions, 16 deletions
@@ -410,14 +410,12 @@ define run @echo "WARNING: STARTUP_CONF not defined or file doesn't exist." @echo " Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n" @cd $(STARTUP_DIR) && \ - sudo $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF) \ - plugin_path $(subst $(subst ,, ),:,$(wildcard $(1)/*/lib*/vpp_plugins)) + sudo $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF) endef else define run @cd $(STARTUP_DIR) && \ - sudo $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//') \ - plugin_path $(subst $(subst ,, ),:,$(wildcard $(1)/*/lib*/vpp_plugins)) + sudo $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//') endef endif diff --git a/src/vat/plugin.h b/src/vat/plugin.h index c69186287aa..8dab168f1c1 100644 --- a/src/vat/plugin.h +++ b/src/vat/plugin.h @@ -26,6 +26,7 @@ typedef struct { u8 *name; + u8 *filename; struct stat file_info; void *handle; } plugin_info_t; diff --git a/src/vpp/api/plugin.c b/src/vpp/api/plugin.c index 95bdbe6cd7e..1506a82ddca 100644 --- a/src/vpp/api/plugin.c +++ b/src/vpp/api/plugin.c @@ -24,13 +24,13 @@ plugin_main_t vat_plugin_main; static int -load_one_plugin (plugin_main_t * pm, plugin_info_t * pi) +load_one_vat_plugin (plugin_main_t * pm, plugin_info_t * pi) { void *handle, *register_handle; clib_error_t *(*fp) (vat_main_t *); clib_error_t *error; - handle = dlopen ((char *) pi->name, RTLD_LAZY); + handle = dlopen ((char *) pi->filename, RTLD_LAZY); /* * Note: this can happen if the plugin has an undefined symbol reference, @@ -119,6 +119,7 @@ vat_load_new_plugins (plugin_main_t * pm) while ((entry = readdir (dp))) { u8 *plugin_name; + u8 *file_name; if (pm->plugin_name_filter) { @@ -128,13 +129,14 @@ vat_load_new_plugins (plugin_main_t * pm) goto next; } - plugin_name = format (0, "%s/%s%c", plugin_path[i], - entry->d_name, 0); + file_name = format (0, "%s/%s%c", plugin_path[i], entry->d_name, 0); + plugin_name = format (0, "%s%c", entry->d_name, 0); /* unreadable */ - if (stat ((char *) plugin_name, &statb) < 0) + if (stat ((char *) file_name, &statb) < 0) { ignore: + vec_free (file_name); vec_free (plugin_name); continue; } @@ -148,10 +150,12 @@ vat_load_new_plugins (plugin_main_t * pm) { vec_add2 (pm->plugin_info, pi, 1); pi->name = plugin_name; + pi->filename = file_name; pi->file_info = statb; - if (load_one_plugin (pm, pi)) + if (load_one_vat_plugin (pm, pi)) { + vec_free (file_name); vec_free (plugin_name); _vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1; continue; diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c index b330f60fafe..6e136e19201 100644 --- a/src/vpp/vnet/main.c +++ b/src/vpp/vnet/main.c @@ -20,7 +20,53 @@ #include <vnet/ethernet/ethernet.h> #include <vpp/app/version.h> #include <vpp/api/vpe_msg_enum.h> +#include <limits.h> +/* + * Load plugins from /usr/lib/vpp_plugins by default + */ +char *vlib_plugin_path = "/usr/lib/vpp_plugins"; +char *vlib_plugin_app_version = VPP_BUILD_VER; + +static void +vpp_find_plugin_path () +{ + extern char *vat_plugin_path; + char *p, path[PATH_MAX]; + int rv; + u8 *s; + + /* find executable path */ + if ((rv = readlink ("/proc/self/exe", path, PATH_MAX - 1)) == -1) + return; + + /* readlink doesn't provide null termination */ + path[rv] = 0; + + /* strip filename */ + if ((p = strrchr (path, '/')) == 0) + return; + *p = 0; + + /* strip bin/ */ + if ((p = strrchr (path, '/')) == 0) + return; + *p = 0; + + s = format (0, "%s/lib/vpp_plugins", path); +#if uword_bits == 64 + s = format (s, ":%s/lib64/vpp_plugins", path); +#endif + vec_add1 (s, 0); + vlib_plugin_path = (char *) s; + + s = format (0, "%s/lib/vpp_api_test_plugins", path); +#if uword_bits == 64 + s = format (s, ":%s/lib64/vpp_api_test_plugins", path); +#endif + vec_add1 (s, 0); + vat_plugin_path = (char *) s; +} static void vpe_main_init (vlib_main_t * vm) @@ -39,6 +85,8 @@ vpe_main_init (vlib_main_t * vm) * Create the binary api plugin hashes before loading plugins */ vat_plugin_hash_create (); + + vpp_find_plugin_path (); } /* @@ -46,12 +94,6 @@ vpe_main_init (vlib_main_t * vm) */ char *vlib_default_runtime_dir = "vpp"; -/* - * Load plugins from /usr/lib/vpp_plugins by default - */ -char *vlib_plugin_path = "/usr/lib/vpp_plugins"; -char *vlib_plugin_app_version = VPP_BUILD_VER; - int main (int argc, char *argv[]) { |