forked from osmocom/wireshark
wsutil: Initialize and store plugin personal dir
Obviate allocation on every call to get_plugins_pers_dir(). Change-Id: I089ae499f93739d490d4552f59b5db5996f7d26f Reviewed-on: https://code.wireshark.org/review/23495 Petri-Dish: João Valverde <j@v6e.pt> Reviewed-by: Michael Mann <mmann78@netscape.net> Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
parent
e7aa63746b
commit
69f0cb0cef
|
@ -475,7 +475,6 @@ static int lua_script_push_args(const int script_num) {
|
|||
/* assumes a loaded chunk's function is on top of stack */
|
||||
static void set_file_environment(const gchar* filename, const gchar* dirname) {
|
||||
const char* path;
|
||||
char* personal = get_plugins_pers_dir();
|
||||
|
||||
lua_newtable(L); /* environment for script (index 3) */
|
||||
|
||||
|
@ -502,7 +501,7 @@ static void set_file_environment(const gchar* filename, const gchar* dirname) {
|
|||
lua_pop(L, 1); /* pop the path string */
|
||||
/* prepend the various paths */
|
||||
lua_pushfstring(L, "%s" G_DIR_SEPARATOR_S "?.lua;%s" G_DIR_SEPARATOR_S "?.lua;%s" G_DIR_SEPARATOR_S "?.lua;%s",
|
||||
dirname, personal, get_plugin_dir(), path);
|
||||
dirname, get_plugins_pers_dir(), get_plugin_dir(), path);
|
||||
lua_setfield(L, -2, "path"); /* set the new string to be the path field of the package table */
|
||||
lua_setfield(L, -2, "package"); /* set the package table to be the package field of the global */
|
||||
|
||||
|
@ -515,8 +514,6 @@ static void set_file_environment(const gchar* filename, const gchar* dirname) {
|
|||
#else
|
||||
lua_setfenv(L, -2); /* pop environment and set it as the func's environment */
|
||||
#endif
|
||||
|
||||
g_free(personal);
|
||||
}
|
||||
|
||||
|
||||
|
@ -677,9 +674,7 @@ int wslua_count_plugins(void) {
|
|||
g_free(filename);
|
||||
|
||||
/* count user scripts */
|
||||
filename = get_plugins_pers_dir();
|
||||
plugins_counter += lua_load_plugins(filename, NULL, NULL, TRUE, TRUE);
|
||||
g_free(filename);
|
||||
plugins_counter += lua_load_plugins(get_plugins_pers_dir(), NULL, NULL, TRUE, TRUE);
|
||||
|
||||
/* count scripts from command line */
|
||||
plugins_counter += ex_opt_count("lua_script");
|
||||
|
@ -949,9 +944,7 @@ void wslua_init(register_cb cb, gpointer client_data) {
|
|||
g_free(filename);
|
||||
|
||||
/* load user scripts */
|
||||
filename = get_plugins_pers_dir();
|
||||
lua_load_plugins(filename, cb, client_data, FALSE, TRUE);
|
||||
g_free(filename);
|
||||
lua_load_plugins(get_plugins_pers_dir(), cb, client_data, FALSE, TRUE);
|
||||
|
||||
/* load scripts from command line */
|
||||
for (i = 0; i < ex_opt_count("lua_script"); i++) {
|
||||
|
|
|
@ -324,9 +324,7 @@ WSLUA_CONSTRUCTOR Dir_personal_plugins_path(lua_State* L) {
|
|||
|
||||
@since 1.11.3
|
||||
*/
|
||||
char* filename = get_plugins_pers_dir();
|
||||
lua_pushstring(L,filename);
|
||||
g_free(filename);
|
||||
lua_pushstring(L, get_plugins_pers_dir());
|
||||
WSLUA_RETURN(1); /* The pathname for the personal plugins directory. */
|
||||
}
|
||||
|
||||
|
|
6
tshark.c
6
tshark.c
|
@ -613,11 +613,7 @@ about_folders(void)
|
|||
|
||||
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
|
||||
/* pers plugins */
|
||||
path = get_plugins_pers_dir();
|
||||
|
||||
printf("%-21s\t%s\n", "Personal Plugins:", path);
|
||||
|
||||
g_free(path);
|
||||
printf("%-21s\t%s\n", "Personal Plugins:", get_plugins_pers_dir());
|
||||
|
||||
/* global plugins */
|
||||
printf("%-21s\t%s\n", "Global Plugins:", get_plugin_dir());
|
||||
|
|
|
@ -460,10 +460,8 @@ about_folders_page_new(void)
|
|||
|
||||
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
|
||||
/* pers plugins */
|
||||
path = get_plugins_pers_dir();
|
||||
about_folders_row(table, "Personal Plugins", path,
|
||||
about_folders_row(table, "Personal Plugins", get_plugins_pers_dir(),
|
||||
"dissector plugins");
|
||||
g_free(path);
|
||||
|
||||
/* global plugins */
|
||||
about_folders_row(table, "Global Plugins", get_plugin_dir(),
|
||||
|
|
|
@ -226,8 +226,7 @@ AboutDialog::AboutDialog(QWidget *parent) :
|
|||
|
||||
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
|
||||
/* pers plugins */
|
||||
message += about_folders_row("Personal Plugins", gchar_free_to_qstring(get_plugins_pers_dir()),
|
||||
"dissector plugins");
|
||||
message += about_folders_row("Personal Plugins", get_plugins_pers_dir(), "dissector plugins");
|
||||
|
||||
/* global plugins */
|
||||
message += about_folders_row("Global Plugins", get_plugin_dir(), "dissector plugins");
|
||||
|
|
|
@ -959,6 +959,7 @@ get_datafile_dir(void)
|
|||
* configure script.
|
||||
*/
|
||||
static char *plugin_dir = NULL;
|
||||
static char *plugin_pers_dir = NULL;
|
||||
|
||||
static void
|
||||
init_plugin_dir(void)
|
||||
|
@ -1034,6 +1035,12 @@ init_plugin_dir(void)
|
|||
}
|
||||
#endif /* HAVE_PLUGINS || HAVE_LUA */
|
||||
|
||||
static void
|
||||
init_plugin_pers_dir(void)
|
||||
{
|
||||
plugin_pers_dir = get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the directory in which the plugins are stored.
|
||||
*/
|
||||
|
@ -1048,6 +1055,15 @@ get_plugin_dir(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Get the personal plugin dir */
|
||||
const char *
|
||||
get_plugins_pers_dir(void)
|
||||
{
|
||||
if (!plugin_pers_dir)
|
||||
init_plugin_pers_dir();
|
||||
return plugin_pers_dir;
|
||||
}
|
||||
|
||||
#if defined(HAVE_EXTCAP)
|
||||
/*
|
||||
* Find the directory where the extcap hooks are stored.
|
||||
|
@ -1883,14 +1899,6 @@ get_datafile_path(const char *filename)
|
|||
}
|
||||
}
|
||||
|
||||
/* Get the personal plugin dir */
|
||||
/* Return value is malloced so the caller should g_free() it. */
|
||||
char *
|
||||
get_plugins_pers_dir(void)
|
||||
{
|
||||
return get_persconffile_path(PLUGINS_DIR_NAME, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return an error message for UNIX-style errno indications on open or
|
||||
* create operations.
|
||||
|
@ -2227,6 +2235,8 @@ free_progdirs(void)
|
|||
#if defined(HAVE_PLUGINS) || defined(HAVE_LUA)
|
||||
g_free(plugin_dir);
|
||||
plugin_dir = NULL;
|
||||
g_free(plugin_pers_dir);
|
||||
plugin_pers_dir = NULL;
|
||||
#endif
|
||||
#ifdef HAVE_EXTCAP
|
||||
g_free(extcap_dir);
|
||||
|
|
|
@ -55,6 +55,11 @@ WS_DLL_PUBLIC const char *get_progfile_dir(void);
|
|||
*/
|
||||
WS_DLL_PUBLIC const char *get_plugin_dir(void);
|
||||
|
||||
/*
|
||||
* Get the personal plugin dir.
|
||||
*/
|
||||
WS_DLL_PUBLIC const char *get_plugins_pers_dir(void);
|
||||
|
||||
/*
|
||||
* Get the directory in which extcap hooks are stored; this must not be called
|
||||
* before init_progfile_dir() is called, as they might be stored in a
|
||||
|
@ -83,12 +88,6 @@ WS_DLL_PUBLIC const char *get_datafile_dir(void);
|
|||
*/
|
||||
WS_DLL_PUBLIC char *get_datafile_path(const char *filename);
|
||||
|
||||
/*
|
||||
* Get the personal plugin dir.
|
||||
* Return value is malloced so the caller should g_free() it.
|
||||
*/
|
||||
WS_DLL_PUBLIC char *get_plugins_pers_dir(void);
|
||||
|
||||
/*
|
||||
* Get the directory in which files that, at least on UNIX, are
|
||||
* system files (such as "/etc/ethers") are stored; on Windows,
|
||||
|
|
|
@ -285,7 +285,6 @@ scan_plugins(plugin_load_failure_mode mode)
|
|||
const char *plugin_dir;
|
||||
const char *name;
|
||||
char *plugin_dir_path;
|
||||
char *plugins_pers_dir;
|
||||
WS_DIR *dir; /* scanned directory */
|
||||
WS_DIRENT *file; /* current file */
|
||||
|
||||
|
@ -353,9 +352,7 @@ scan_plugins(plugin_load_failure_mode mode)
|
|||
*/
|
||||
if (!started_with_special_privs())
|
||||
{
|
||||
plugins_pers_dir = get_plugins_pers_dir();
|
||||
plugins_scan_dir(plugins_pers_dir, mode);
|
||||
g_free(plugins_pers_dir);
|
||||
plugins_scan_dir(get_plugins_pers_dir(), mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue