59
59
class sys_var_pluginvar;
60
60
static vector<sys_var_pluginvar *> plugin_sysvar_vec;
62
char *opt_plugin_add= NULL;
62
63
char *opt_plugin_load= NULL;
63
const char *opt_plugin_load_default= QUOTE_ARG(PANDORA_PLUGIN_LIST);
64
const char *opt_plugin_load_default= PANDORA_PLUGIN_LIST;
64
65
char *opt_plugin_dir_ptr;
65
66
char opt_plugin_dir[FN_REFLEN];
66
67
static const char *plugin_declarations_sym= "_drizzled_plugin_declaration_";
158
159
static bool plugin_load_list(plugin::Registry ®istry,
159
160
MEM_ROOT *tmp_root, int *argc, char **argv,
160
161
const char *list);
161
static int test_plugin_options(MEM_ROOT *, plugin::Handle *,
162
static int test_plugin_options(MEM_ROOT *, plugin::Module *,
163
164
static bool register_builtin(plugin::Registry ®istry,
166
167
static void unlock_variables(Session *session, struct system_variables *vars);
167
168
static void cleanup_variables(Session *session, struct system_variables *vars);
168
169
static void plugin_vars_free_values(sys_var *vars);
321
322
/* Compile dll path */
322
323
dlpath.append(opt_plugin_dir);
323
324
dlpath.append("/");
325
dlpath.append("lib");
324
326
dlpath.append(dl->str);
327
dlpath.append("_plugin.so");
325
328
/* Open new dll handle */
326
if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
329
if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_NOW|RTLD_GLOBAL)))
328
331
const char *errmsg=dlerror();
329
332
uint32_t dlpathlen= dlpath.length();
408
static plugin::Handle *plugin_insert_or_reuse(plugin::Handle *plugin)
411
static plugin::Module *plugin_insert_or_reuse(plugin::Module *module)
410
if (insert_dynamic(&plugin_array, (unsigned char*)&plugin))
412
plugin= *dynamic_element(&plugin_array, plugin_array.elements - 1,
413
if (insert_dynamic(&module_array, (unsigned char*)&module))
415
module= *dynamic_element(&module_array, module_array.elements - 1,
481
static void plugin_del(plugin::Registry ®istry, plugin::Handle *plugin)
484
static void delete_module(plugin::Registry ®istry, plugin::Module *module)
483
if (plugin->isInited)
486
plugin::Manifest manifest= module->getManifest();
488
if (module->isInited)
485
if (plugin->getManifest().status_vars)
490
if (manifest.status_vars)
487
remove_status_vars(plugin->getManifest().status_vars);
492
remove_status_vars(manifest.status_vars);
490
if (plugin->getManifest().deinit)
491
plugin->getManifest().deinit(registry);
496
manifest.deinit(registry);
494
499
/* Free allocated strings before deleting the plugin. */
495
plugin_vars_free_values(plugin->system_vars);
496
if (plugin->plugin_dl)
497
plugin_dl_del(&plugin->plugin_dl->dl);
498
plugin->isInited= false;
500
plugin_vars_free_values(module->system_vars);
501
if (module->plugin_dl)
502
plugin_dl_del(&module->plugin_dl->dl);
503
module->isInited= false;
499
504
pthread_rwlock_wrlock(&LOCK_system_variables_hash);
500
mysql_del_sys_var_chain(plugin->system_vars);
505
mysql_del_sys_var_chain(module->system_vars);
501
506
pthread_rwlock_unlock(&LOCK_system_variables_hash);
505
510
static void reap_plugins(plugin::Registry &plugins)
509
plugin::Handle *plugin;
514
plugin::Module *module;
511
count= plugin_array.elements;
516
count= module_array.elements;
513
518
for (idx= 0; idx < count; idx++)
515
plugin= *dynamic_element(&plugin_array, idx, plugin::Handle **);
516
plugin_del(plugins, plugin);
520
module= *dynamic_element(&module_array, idx, plugin::Module **);
521
delete_module(plugins, module);
518
523
drizzle_del_plugin_sysvar();
522
static void plugin_initialize_vars(plugin::Handle *plugin)
527
static void plugin_initialize_vars(plugin::Module *module)
524
if (plugin->getManifest().status_vars)
529
if (module->getManifest().status_vars)
526
add_status_vars(plugin->getManifest().status_vars); // add_status_vars makes a copy
531
add_status_vars(module->getManifest().status_vars); // add_status_vars makes a copy
530
535
set the plugin attribute of plugin's sys vars so they are pointing
531
536
to the active plugin
533
if (plugin->system_vars)
538
if (module->system_vars)
535
sys_var_pluginvar *var= plugin->system_vars->cast_pluginvar();
540
sys_var_pluginvar *var= module->system_vars->cast_pluginvar();
539
544
if (! var->getNext())
541
546
var= var->getNext()->cast_pluginvar();
547
552
static bool plugin_initialize(plugin::Registry ®istry,
548
plugin::Handle *plugin)
553
plugin::Module *module)
550
assert(plugin->isInited == false);
555
assert(module->isInited == false);
552
registry.setCurrentHandle(plugin);
553
if (plugin->getManifest().init)
557
registry.setCurrentModule(module);
558
if (module->getManifest().init)
555
if (plugin->getManifest().init(registry))
560
if (module->getManifest().init(registry))
557
562
errmsg_printf(ERRMSG_LVL_ERROR,
558
563
_("Plugin '%s' init function returned error.\n"),
559
plugin->getName().c_str());
564
module->getName().c_str());
563
registry.clearCurrentHandle();
564
plugin->isInited= true;
568
registry.clearCurrentModule();
569
module->isInited= true;
608
613
if (my_init_dynamic_array(&plugin_dl_array,
609
614
sizeof(plugin::Library *),16,16) ||
610
my_init_dynamic_array(&plugin_array,
611
sizeof(plugin::Handle *),16,16))
615
my_init_dynamic_array(&module_array,
616
sizeof(plugin::Module *),16,16))
621
626
for (manifest= *builtins; manifest->name; manifest++)
623
handle= new (std::nothrow) plugin::Handle(manifest);
628
module= new (std::nothrow) plugin::Module(manifest);
627
632
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
628
if (test_plugin_options(&tmp_root, handle, argc, argv))
633
if (test_plugin_options(&tmp_root, module, argc, argv))
631
if (register_builtin(registry, handle, &handle))
636
if (register_builtin(registry, module, &module))
634
plugin_initialize_vars(handle);
639
plugin_initialize_vars(module);
636
641
if (! (flags & PLUGIN_INIT_SKIP_INITIALIZATION))
638
if (plugin_initialize(registry, handle))
643
if (plugin_initialize(registry, module))
646
651
if (! (flags & PLUGIN_INIT_SKIP_DYNAMIC_LOADING))
648
653
if (opt_plugin_load)
649
655
plugin_load_list(registry, &tmp_root, argc, argv, opt_plugin_load);
659
string tmp_plugin_list(opt_plugin_load_default);
662
tmp_plugin_list.push_back(',');
663
tmp_plugin_list.append(opt_plugin_add);
665
plugin_load_list(registry, &tmp_root, argc, argv, tmp_plugin_list.c_str());
652
669
if (flags & PLUGIN_INIT_SKIP_INITIALIZATION)
656
673
Now we initialize all remaining plugins
658
for (idx= 0; idx < plugin_array.elements; idx++)
675
for (idx= 0; idx < module_array.elements; idx++)
660
handle= *dynamic_element(&plugin_array, idx, plugin::Handle **);
661
if (handle->isInited == false)
677
module= *dynamic_element(&module_array, idx, plugin::Module **);
678
if (module->isInited == false)
663
plugin_initialize_vars(handle);
680
plugin_initialize_vars(module);
665
if (plugin_initialize(registry, handle))
666
plugin_del(registry, handle);
682
if (plugin_initialize(registry, module))
683
delete_module(registry, module);
683
700
static bool register_builtin(plugin::Registry ®istry,
685
plugin::Handle **ptr)
702
plugin::Module **ptr)
688
705
tmp->isInited= false;
689
706
tmp->plugin_dl= 0;
691
if (insert_dynamic(&plugin_array, (unsigned char*)&tmp))
708
if (insert_dynamic(&module_array, (unsigned char*)&tmp))
694
*ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
711
*ptr= *dynamic_element(&module_array, module_array.elements - 1,
697
714
registry.add(*ptr);
1135
1151
sys_var_pluginvar *pi= NULL;
1136
plugin::Handle *plugin;
1152
plugin::Module *module;
1138
1154
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1139
1155
if ((var= intern_find_sys_var(str, length, false)) &&
1140
1156
(pi= var->cast_pluginvar()))
1142
1158
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1143
if (!(plugin= pi->plugin))
1159
if (!(module= pi->plugin))
1144
1160
var= NULL; /* failed to lock it, it must be uninstalling */
1145
else if (plugin->isInited == false)
1161
else if (module->isInited == false)
1880
static int construct_options(MEM_ROOT *mem_root, plugin::Handle *tmp,
1896
static int construct_options(MEM_ROOT *mem_root, plugin::Module *tmp,
1881
1897
my_option *options, bool can_disable)
1883
1899
const char *plugin_name= tmp->getManifest().name;
2164
2180
Requires that a write-lock is held on LOCK_system_variables_hash
2166
static int test_plugin_options(MEM_ROOT *tmp_root, plugin::Handle *tmp,
2182
static int test_plugin_options(MEM_ROOT *tmp_root, plugin::Module *tmp,
2167
2183
int *argc, char **argv)
2169
2185
struct sys_var_chain chain= { NULL, NULL };
2287
2303
void my_print_help_inc_plugins(my_option *main_options)
2289
2305
vector<my_option> all_options;
2291
2307
MEM_ROOT mem_root;
2292
2308
my_option *opt= NULL;
2294
2310
init_alloc_root(&mem_root, 4096, 4096);
2296
2312
if (initialized)
2297
for (uint32_t idx= 0; idx < plugin_array.elements; idx++)
2313
for (uint32_t idx= 0; idx < module_array.elements; idx++)
2299
p= *dynamic_element(&plugin_array, idx, plugin::Handle **);
2315
p= *dynamic_element(&module_array, idx, plugin::Module **);
2301
2317
if (p->getManifest().system_vars == NULL)