158
158
static bool plugin_load_list(plugin::Registry ®istry,
159
159
MEM_ROOT *tmp_root, int *argc, char **argv,
160
160
const char *list);
161
static int test_plugin_options(MEM_ROOT *, plugin::Handle *,
161
static int test_plugin_options(MEM_ROOT *, plugin::Module *,
163
163
static bool register_builtin(plugin::Registry ®istry,
166
166
static void unlock_variables(Session *session, struct system_variables *vars);
167
167
static void cleanup_variables(Session *session, struct system_variables *vars);
168
168
static void plugin_vars_free_values(sys_var *vars);
408
static plugin::Handle *plugin_insert_or_reuse(plugin::Handle *plugin)
408
static plugin::Module *plugin_insert_or_reuse(plugin::Module *module)
410
if (insert_dynamic(&plugin_array, (unsigned char*)&plugin))
410
if (insert_dynamic(&module_array, (unsigned char*)&module))
412
plugin= *dynamic_element(&plugin_array, plugin_array.elements - 1,
412
module= *dynamic_element(&module_array, module_array.elements - 1,
481
static void plugin_del(plugin::Registry ®istry, plugin::Handle *plugin)
481
static void delete_module(plugin::Registry ®istry, plugin::Module *module)
483
if (plugin->isInited)
483
plugin::Manifest manifest= module->getManifest();
485
if (module->isInited)
485
if (plugin->getManifest().status_vars)
487
if (manifest.status_vars)
487
remove_status_vars(plugin->getManifest().status_vars);
489
remove_status_vars(manifest.status_vars);
490
if (plugin->getManifest().deinit)
491
plugin->getManifest().deinit(registry);
493
manifest.deinit(registry);
494
496
/* 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;
497
plugin_vars_free_values(module->system_vars);
498
if (module->plugin_dl)
499
plugin_dl_del(&module->plugin_dl->dl);
500
module->isInited= false;
499
501
pthread_rwlock_wrlock(&LOCK_system_variables_hash);
500
mysql_del_sys_var_chain(plugin->system_vars);
502
mysql_del_sys_var_chain(module->system_vars);
501
503
pthread_rwlock_unlock(&LOCK_system_variables_hash);
505
507
static void reap_plugins(plugin::Registry &plugins)
509
plugin::Handle *plugin;
511
plugin::Module *module;
511
count= plugin_array.elements;
513
count= module_array.elements;
513
515
for (idx= 0; idx < count; idx++)
515
plugin= *dynamic_element(&plugin_array, idx, plugin::Handle **);
516
plugin_del(plugins, plugin);
517
module= *dynamic_element(&module_array, idx, plugin::Module **);
518
delete_module(plugins, module);
518
520
drizzle_del_plugin_sysvar();
522
static void plugin_initialize_vars(plugin::Handle *plugin)
524
static void plugin_initialize_vars(plugin::Module *module)
524
if (plugin->getManifest().status_vars)
526
if (module->getManifest().status_vars)
526
add_status_vars(plugin->getManifest().status_vars); // add_status_vars makes a copy
528
add_status_vars(module->getManifest().status_vars); // add_status_vars makes a copy
530
532
set the plugin attribute of plugin's sys vars so they are pointing
531
533
to the active plugin
533
if (plugin->system_vars)
535
if (module->system_vars)
535
sys_var_pluginvar *var= plugin->system_vars->cast_pluginvar();
537
sys_var_pluginvar *var= module->system_vars->cast_pluginvar();
539
541
if (! var->getNext())
541
543
var= var->getNext()->cast_pluginvar();
547
549
static bool plugin_initialize(plugin::Registry ®istry,
548
plugin::Handle *plugin)
550
plugin::Module *module)
550
assert(plugin->isInited == false);
552
assert(module->isInited == false);
552
registry.setCurrentHandle(plugin);
553
if (plugin->getManifest().init)
554
registry.setCurrentModule(module);
555
if (module->getManifest().init)
555
if (plugin->getManifest().init(registry))
557
if (module->getManifest().init(registry))
557
559
errmsg_printf(ERRMSG_LVL_ERROR,
558
560
_("Plugin '%s' init function returned error.\n"),
559
plugin->getName().c_str());
561
module->getName().c_str());
563
registry.clearCurrentHandle();
564
plugin->isInited= true;
565
registry.clearCurrentModule();
566
module->isInited= true;
608
610
if (my_init_dynamic_array(&plugin_dl_array,
609
611
sizeof(plugin::Library *),16,16) ||
610
my_init_dynamic_array(&plugin_array,
611
sizeof(plugin::Handle *),16,16))
612
my_init_dynamic_array(&module_array,
613
sizeof(plugin::Module *),16,16))
621
623
for (manifest= *builtins; manifest->name; manifest++)
623
handle= new (std::nothrow) plugin::Handle(manifest);
625
module= new (std::nothrow) plugin::Module(manifest);
627
629
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
628
if (test_plugin_options(&tmp_root, handle, argc, argv))
630
if (test_plugin_options(&tmp_root, module, argc, argv))
631
if (register_builtin(registry, handle, &handle))
633
if (register_builtin(registry, module, &module))
634
plugin_initialize_vars(handle);
636
plugin_initialize_vars(module);
636
638
if (! (flags & PLUGIN_INIT_SKIP_INITIALIZATION))
638
if (plugin_initialize(registry, handle))
640
if (plugin_initialize(registry, module))
656
658
Now we initialize all remaining plugins
658
for (idx= 0; idx < plugin_array.elements; idx++)
660
for (idx= 0; idx < module_array.elements; idx++)
660
handle= *dynamic_element(&plugin_array, idx, plugin::Handle **);
661
if (handle->isInited == false)
662
module= *dynamic_element(&module_array, idx, plugin::Module **);
663
if (module->isInited == false)
663
plugin_initialize_vars(handle);
665
plugin_initialize_vars(module);
665
if (plugin_initialize(registry, handle))
666
plugin_del(registry, handle);
667
if (plugin_initialize(registry, module))
668
delete_module(registry, module);
683
685
static bool register_builtin(plugin::Registry ®istry,
685
plugin::Handle **ptr)
687
plugin::Module **ptr)
688
690
tmp->isInited= false;
689
691
tmp->plugin_dl= 0;
691
if (insert_dynamic(&plugin_array, (unsigned char*)&tmp))
693
if (insert_dynamic(&module_array, (unsigned char*)&tmp))
694
*ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
696
*ptr= *dynamic_element(&module_array, module_array.elements - 1,
697
699
registry.add(*ptr);
787
789
void plugin_shutdown(plugin::Registry ®istry)
790
size_t count= plugin_array.elements;
791
vector<plugin::Handle *> plugins;
792
size_t count= module_array.elements;
793
// vector<plugin::Module *> modules;
792
794
vector<plugin::Library *> dl;
1135
1137
sys_var_pluginvar *pi= NULL;
1136
plugin::Handle *plugin;
1138
plugin::Module *module;
1138
1140
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1139
1141
if ((var= intern_find_sys_var(str, length, false)) &&
1140
1142
(pi= var->cast_pluginvar()))
1142
1144
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1143
if (!(plugin= pi->plugin))
1145
if (!(module= pi->plugin))
1144
1146
var= NULL; /* failed to lock it, it must be uninstalling */
1145
else if (plugin->isInited == false)
1147
else if (module->isInited == false)
1880
static int construct_options(MEM_ROOT *mem_root, plugin::Handle *tmp,
1882
static int construct_options(MEM_ROOT *mem_root, plugin::Module *tmp,
1881
1883
my_option *options, bool can_disable)
1883
1885
const char *plugin_name= tmp->getManifest().name;
2164
2166
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,
2168
static int test_plugin_options(MEM_ROOT *tmp_root, plugin::Module *tmp,
2167
2169
int *argc, char **argv)
2169
2171
struct sys_var_chain chain= { NULL, NULL };
2287
2289
void my_print_help_inc_plugins(my_option *main_options)
2289
2291
vector<my_option> all_options;
2291
2293
MEM_ROOT mem_root;
2292
2294
my_option *opt= NULL;
2294
2296
init_alloc_root(&mem_root, 4096, 4096);
2296
2298
if (initialized)
2297
for (uint32_t idx= 0; idx < plugin_array.elements; idx++)
2299
for (uint32_t idx= 0; idx < module_array.elements; idx++)
2299
p= *dynamic_element(&plugin_array, idx, plugin::Handle **);
2301
p= *dynamic_element(&module_array, idx, plugin::Module **);
2301
2303
if (p->getManifest().system_vars == NULL)