24
25
#include <drizzled/parser.h>
25
26
#include <drizzled/sql_parse.h>
26
27
#include <drizzled/scheduling.h>
28
#include <drizzled/replicator.h>
29
#include <drizzled/show.h>
30
#include <drizzled/handler.h>
31
#include <drizzled/set_var.h>
32
#include <drizzled/session.h>
33
#include <drizzled/item/null.h>
30
38
#include <drizzled/error.h>
31
39
#include <drizzled/gettext.h>
61
69
{ C_STRING_WITH_LEN("CONFIGVAR") },
62
70
{ C_STRING_WITH_LEN("QCACHE") },
63
71
{ C_STRING_WITH_LEN("PARSER") },
64
{ C_STRING_WITH_LEN("SCHEDULING") }
72
{ C_STRING_WITH_LEN("SCHEDULING") },
73
{ C_STRING_WITH_LEN("REPLICATOR") }
67
76
extern int initialize_schema_table(st_plugin_int *plugin);
183
194
static void *operator new(size_t size, MEM_ROOT *mem_root)
184
195
{ return (void*) alloc_root(mem_root, (uint) size); }
185
static void operator delete(void *ptr_arg __attribute__((unused)),
186
size_t size __attribute__((unused)))
196
static void operator delete(void *, size_t)
187
197
{ TRASH(ptr_arg, size); }
189
199
sys_var_pluginvar(const char *name_arg,
199
209
TYPELIB* plugin_var_typelib(void);
200
210
unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
201
211
bool check(Session *session, set_var *var);
202
bool check_default(enum_var_type type __attribute__((unused)))
212
bool check_default(enum_var_type)
203
213
{ return is_readonly(); }
204
void set_default(Session *session,
205
enum_var_type type __attribute__((unused)));
214
void set_default(Session *session, enum_var_type);
206
215
bool update(Session *session, set_var *var);
356
367
if (report & REPORT_TO_USER)
357
368
my_error(ER_UDF_NO_PATHS, MYF(0));
358
369
if (report & REPORT_TO_LOG)
359
sql_print_error("%s",ER(ER_UDF_NO_PATHS));
370
errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_UDF_NO_PATHS));
362
373
/* If this dll is already loaded just increase ref_count. */
385
396
if (report & REPORT_TO_USER)
386
397
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
387
398
if (report & REPORT_TO_LOG)
388
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
399
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
396
407
if (report & REPORT_TO_USER)
397
408
my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_declarations_sym);
398
409
if (report & REPORT_TO_LOG)
399
sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), plugin_declarations_sym);
410
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), plugin_declarations_sym);
405
416
/* Duplicate and convert dll name */
406
417
plugin_dl.dl.length= dl->length * files_charset_info->mbmaxlen + 1;
407
if (! (plugin_dl.dl.str= (char*) my_malloc(plugin_dl.dl.length, MYF(0))))
418
if (! (plugin_dl.dl.str= (char*) malloc(plugin_dl.dl.length)))
409
420
free_plugin_mem(&plugin_dl);
410
421
if (report & REPORT_TO_USER)
411
422
my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
412
423
if (report & REPORT_TO_LOG)
413
sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
424
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
416
427
plugin_dl.dl.length= copy_and_convert(plugin_dl.dl.str, plugin_dl.dl.length,
424
435
if (report & REPORT_TO_USER)
425
436
my_error(ER_OUTOFMEMORY, MYF(0), sizeof(struct st_plugin_dl));
426
437
if (report & REPORT_TO_LOG)
427
sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_dl));
438
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_dl));
594
603
if (report & REPORT_TO_USER)
595
604
my_error(ER_UDF_EXISTS, MYF(0), name->str);
596
605
if (report & REPORT_TO_LOG)
597
sql_print_error(ER(ER_UDF_EXISTS), name->str);
606
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UDF_EXISTS), name->str);
600
609
/* Clear the whole struct to catch future extensions. */
641
650
if (report & REPORT_TO_USER)
642
651
my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), name->str);
643
652
if (report & REPORT_TO_LOG)
644
sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), name->str);
653
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), name->str);
646
655
plugin_dl_del(dl);
688
697
exit until NDB is shut down.
690
699
if (ref_check && plugin->ref_count)
691
sql_print_error(_("Plugin '%s' has ref_count=%d after deinitialization."),
700
errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' has ref_count=%d after deinitialization."),
692
701
plugin->name.str, plugin->ref_count);
702
711
plugin_dl_del(&plugin->plugin_dl->dl);
703
712
plugin->state= PLUGIN_IS_FREED;
704
713
plugin_array_version++;
705
rw_wrlock(&LOCK_system_variables_hash);
714
pthread_rwlock_wrlock(&LOCK_system_variables_hash);
706
715
mysql_del_sys_var_chain(plugin->system_vars);
707
rw_unlock(&LOCK_system_variables_hash);
716
pthread_rwlock_unlock(&LOCK_system_variables_hash);
708
717
free_root(&plugin->mem_root, MYF(0));
712
721
static void reap_plugins(void)
715
struct st_plugin_int *plugin, **reap, **list;
725
struct st_plugin_int *plugin;
720
727
reap_needed= false;
721
728
count= plugin_array.elements;
722
reap= (struct st_plugin_int **)my_alloca(sizeof(plugin)*(count+1));
725
730
for (idx= 0; idx < count; idx++)
727
732
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
728
if (plugin->state == PLUGIN_IS_DELETED && !plugin->ref_count)
730
/* change the status flag to prevent reaping by another thread */
731
plugin->state= PLUGIN_IS_DYING;
737
while ((plugin= *(--list)))
733
plugin->state= PLUGIN_IS_DYING;
738
734
plugin_deinitialize(plugin, true);
740
while ((plugin= *(--reap)))
741
735
plugin_del(plugin);
746
static void intern_plugin_unlock(LEX *lex, plugin_ref plugin)
739
static void intern_plugin_unlock(LEX *, plugin_ref plugin)
749
741
st_plugin_int *pi;
756
748
free((void *) plugin);
761
Remove one instance of this plugin from the use list.
762
We are searching backwards so that plugins locked last
763
could be unlocked faster - optimizing for LIFO semantics.
765
for (i= lex->plugins.elements - 1; i >= 0; i--)
766
if (plugin == *dynamic_element(&lex->plugins, i, plugin_ref*))
768
delete_dynamic_element(&lex->plugins, i);
774
750
assert(pi->ref_count);
872
848
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
875
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length,
876
bool not_used __attribute__((unused)))
851
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length, bool)
878
853
struct st_plugin_int *plugin= (st_plugin_int *)buff;
879
854
*length= (uint)plugin->name.length;
884
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length,
885
bool not_used __attribute__((unused)))
859
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length, bool)
887
861
struct st_bookmark *var= (st_bookmark *)buff;
888
862
*length= var->name_len + 1;
900
874
int plugin_init(int *argc, char **argv, int flags)
903
877
struct st_mysql_plugin **builtins;
904
878
struct st_mysql_plugin *plugin;
905
struct st_plugin_int tmp, *plugin_ptr, **reap;
879
struct st_plugin_int tmp, *plugin_ptr;
906
880
MEM_ROOT tmp_root;
922
896
sizeof(struct st_plugin_int *),16,16))
925
for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
899
for (idx= 0; idx < DRIZZLE_MAX_PLUGIN_TYPE_NUM; idx++)
927
if (hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
901
if (hash_init(&plugin_hash[idx], system_charset_info, 16, 0, 0,
928
902
get_plugin_hash_key, NULL, HASH_UNIQUE))
984
958
Now we initialize all remaining plugins
987
reap= (st_plugin_int **) my_alloca((plugin_array.elements+1) * sizeof(void*));
990
for (i= 0; i < plugin_array.elements; i++)
960
for (idx= 0; idx < plugin_array.elements; idx++)
992
plugin_ptr= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
962
plugin_ptr= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
993
963
if (plugin_ptr->state == PLUGIN_IS_UNINITIALIZED)
995
965
if (plugin_initialize(plugin_ptr))
997
967
plugin_ptr->state= PLUGIN_IS_DYING;
998
*(reap++)= plugin_ptr;
968
plugin_deinitialize(plugin_ptr, true);
969
plugin_del(plugin_ptr);
1004
Check if any plugins have to be reaped
1006
while ((plugin_ptr= *(--reap)))
1008
plugin_deinitialize(plugin_ptr, true);
1009
plugin_del(plugin_ptr);
1015
976
free_root(&tmp_root, MYF(0));
1131
1092
void plugin_shutdown(void)
1133
uint32_t i, count= plugin_array.elements, free_slots= 0;
1134
struct st_plugin_int **plugins, *plugin;
1135
struct st_plugin_dl **dl;
1094
uint32_t idx, free_slots= 0;
1095
size_t count= plugin_array.elements;
1096
struct st_plugin_int *plugin;
1097
vector<st_plugin_int *> plugins;
1098
vector<st_plugin_dl *> dl;
1137
1100
if (initialized)
1148
1111
while (reap_needed && (count= plugin_array.elements))
1150
1113
reap_plugins();
1151
for (i= free_slots= 0; i < count; i++)
1114
for (idx= free_slots= 0; idx < count; idx++)
1153
plugin= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
1116
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
1154
1117
switch (plugin->state) {
1155
1118
case PLUGIN_IS_READY:
1156
1119
plugin->state= PLUGIN_IS_DELETED;
1175
1138
if (count > free_slots)
1176
sql_print_warning(_("Forcing shutdown of %d plugins"),
1177
count - free_slots);
1139
errmsg_printf(ERRMSG_LVL_WARN, _("Forcing shutdown of %"PRIu64" plugins"),
1140
(uint64_t)count - free_slots);
1179
plugins= (struct st_plugin_int **) my_alloca(sizeof(void*) * (count+1));
1142
plugins.reserve(count);
1182
1145
If we have any plugins which did not die cleanly, we force shutdown
1184
for (i= 0; i < count; i++)
1147
for (idx= 0; idx < count; idx++)
1186
plugins[i]= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
1149
plugins.push_back(*dynamic_element(&plugin_array, idx,
1150
struct st_plugin_int **));
1187
1151
/* change the state to ensure no reaping races */
1188
if (plugins[i]->state == PLUGIN_IS_DELETED)
1189
plugins[i]->state= PLUGIN_IS_DYING;
1152
if (plugins[idx]->state == PLUGIN_IS_DELETED)
1153
plugins[idx]->state= PLUGIN_IS_DYING;
1193
1157
We loop through all plugins and call deinit() if they have one.
1195
for (i= 0; i < count; i++)
1196
if (!(plugins[i]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED)))
1159
for (idx= 0; idx < count; idx++)
1160
if (!(plugins[idx]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED)))
1198
sql_print_information(_("Plugin '%s' will be forced to shutdown"),
1199
plugins[i]->name.str);
1162
errmsg_printf(ERRMSG_LVL_INFO, _("Plugin '%s' will be forced to shutdown"),
1163
plugins[idx]->name.str);
1201
1165
We are forcing deinit on plugins so we don't want to do a ref_count
1202
1166
check until we have processed all the plugins.
1204
plugin_deinitialize(plugins[i], false);
1168
plugin_deinitialize(plugins[idx], false);
1208
1172
We defer checking ref_counts until after all plugins are deinitialized
1209
1173
as some may have worker threads holding on to plugin references.
1211
for (i= 0; i < count; i++)
1175
for (idx= 0; idx < count; idx++)
1213
if (plugins[i]->ref_count)
1214
sql_print_error(_("Plugin '%s' has ref_count=%d after shutdown."),
1215
plugins[i]->name.str, plugins[i]->ref_count);
1216
if (plugins[i]->state & PLUGIN_IS_UNINITIALIZED)
1217
plugin_del(plugins[i]);
1177
if (plugins[idx]->ref_count)
1178
errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' has ref_count=%d after shutdown."),
1179
plugins[idx]->name.str, plugins[idx]->ref_count);
1180
if (plugins[idx]->state & PLUGIN_IS_UNINITIALIZED)
1181
plugin_del(plugins[idx]);
1227
1191
initialized= 0;
1232
1195
/* Dispose of the memory */
1234
for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
1235
hash_free(&plugin_hash[i]);
1197
for (idx= 0; idx < DRIZZLE_MAX_PLUGIN_TYPE_NUM; idx++)
1198
hash_free(&plugin_hash[idx]);
1236
1199
delete_dynamic(&plugin_array);
1238
1201
count= plugin_dl_array.elements;
1239
dl= (struct st_plugin_dl **)my_alloca(sizeof(void*) * count);
1240
for (i= 0; i < count; i++)
1241
dl[i]= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
1242
for (i= 0; i < plugin_dl_array.elements; i++)
1243
free_plugin_mem(dl[i]);
1203
for (idx= 0; idx < count; idx++)
1204
dl.push_back(*dynamic_element(&plugin_dl_array, idx,
1205
struct st_plugin_dl **));
1206
for (idx= 0; idx < count; idx++)
1207
free_plugin_mem(dl[idx]);
1245
1208
delete_dynamic(&plugin_dl_array);
1247
1210
hash_free(&bookmark_hash);
1256
1219
bool plugin_foreach_with_mask(Session *session, plugin_foreach_func *func,
1257
1220
int type, uint32_t state_mask, void *arg)
1259
uint32_t idx, total;
1260
struct st_plugin_int *plugin, **plugins;
1224
struct st_plugin_int *plugin;
1225
vector<st_plugin_int *> plugins;
1261
1226
int version=plugin_array_version;
1263
1228
if (!initialized)
1268
1233
total= type == DRIZZLE_ANY_PLUGIN ? plugin_array.elements
1269
1234
: plugin_hash[type].records;
1271
Do the alloca out here in case we do have a working alloca:
1272
leaving the nested stack frame invalidates alloca allocation.
1274
plugins=(struct st_plugin_int **)my_alloca(total*sizeof(plugin));
1235
plugins.reserve(total);
1275
1237
if (type == DRIZZLE_ANY_PLUGIN)
1277
1239
for (idx= 0; idx < total; idx++)
1279
1241
plugin= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
1280
plugins[idx]= !(plugin->state & state_mask) ? plugin : NULL;
1242
plugins.push_back(!(plugin->state & state_mask) ? plugin : NULL);
1352
1312
default variable data check and update functions
1353
1313
****************************************************************************/
1355
static int check_func_bool(Session *session __attribute__((unused)),
1356
struct st_mysql_sys_var *var,
1315
static int check_func_bool(Session *, struct st_mysql_sys_var *var,
1357
1316
void *save, st_mysql_value *value)
1359
1318
char buff[STRING_BUFFER_USUAL_SIZE];
1451
1410
var->name, (int64_t) tmp);
1454
static int check_func_str(Session *session,
1455
struct st_mysql_sys_var *var __attribute__((unused)),
1413
static int check_func_str(Session *session, struct st_mysql_sys_var *,
1456
1414
void *save, st_mysql_value *value)
1458
1416
char buff[STRING_BUFFER_USUAL_SIZE];
1470
static int check_func_enum(Session *session __attribute__((unused)),
1471
struct st_mysql_sys_var *var,
1428
static int check_func_enum(Session *, struct st_mysql_sys_var *var,
1472
1429
void *save, st_mysql_value *value)
1474
1431
char buff[STRING_BUFFER_USUAL_SIZE];
1517
static int check_func_set(Session *session __attribute__((unused)),
1518
struct st_mysql_sys_var *var,
1474
static int check_func_set(Session *, struct st_mysql_sys_var *var,
1519
1475
void *save, st_mysql_value *value)
1521
1477
char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1540
1496
&error, &error_len, ¬_used);
1543
strmake(buff, error, cmin(sizeof(buff), (unsigned long)error_len));
1499
length= cmin(sizeof(buff), (unsigned long)error_len);
1500
strncpy(buff, error, length);
1544
1502
strvalue= buff;
1568
static void update_func_bool(Session *session __attribute__((unused)),
1569
struct st_mysql_sys_var *var __attribute__((unused)),
1526
static void update_func_bool(Session *, struct st_mysql_sys_var *,
1570
1527
void *tgt, const void *save)
1572
1529
*(bool *) tgt= *(int *) save ? 1 : 0;
1576
static void update_func_int(Session *session __attribute__((unused)),
1577
struct st_mysql_sys_var *var __attribute__((unused)),
1533
static void update_func_int(Session *, struct st_mysql_sys_var *,
1578
1534
void *tgt, const void *save)
1580
1536
*(int *)tgt= *(int *) save;
1584
static void update_func_long(Session *session __attribute__((unused)),
1585
struct st_mysql_sys_var *var __attribute__((unused)),
1540
static void update_func_long(Session *, struct st_mysql_sys_var *,
1586
1541
void *tgt, const void *save)
1588
1543
*(long *)tgt= *(long *) save;
1592
static void update_func_int64_t(Session *session __attribute__((unused)),
1593
struct st_mysql_sys_var *var __attribute__((unused)),
1547
static void update_func_int64_t(Session *, struct st_mysql_sys_var *,
1594
1548
void *tgt, const void *save)
1596
1550
*(int64_t *)tgt= *(uint64_t *) save;
1600
static void update_func_str(Session *session __attribute__((unused)), struct st_mysql_sys_var *var,
1554
static void update_func_str(Session *, struct st_mysql_sys_var *var,
1601
1555
void *tgt, const void *save)
1603
1557
char *old= *(char **) tgt;
1604
1558
*(char **)tgt= *(char **) save;
1605
1559
if (var->flags & PLUGIN_VAR_MEMALLOC)
1607
*(char **)tgt= my_strdup(*(char **) save, MYF(0));
1561
*(char **)tgt= strdup(*(char **) save);
1564
* There isn't a _really_ good thing to do here until this whole set_var
1565
* mess gets redesigned
1568
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
1621
1582
sys_var_pluginvar *pi= NULL;
1622
1583
plugin_ref plugin;
1624
rw_rdlock(&LOCK_system_variables_hash);
1585
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1625
1586
if ((var= intern_find_sys_var(str, length, false)) &&
1626
1587
(pi= var->cast_pluginvar()))
1628
rw_unlock(&LOCK_system_variables_hash);
1589
pthread_rwlock_unlock(&LOCK_system_variables_hash);
1629
1590
LEX *lex= session ? session->lex : 0;
1630
1591
if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
1631
1592
var= NULL; /* failed to lock it, it must be uninstalling */
1669
1630
pluginlen= strlen(plugin) + 1;
1670
1631
length= namelen + pluginlen + 2;
1671
varname= (char*) my_alloca(length);
1632
varname= (char*) malloc(length);
1675
strxmov(varname + 1, plugin, "_", name, NULL);
1636
sprintf(varname+1,"%s_%s",plugin,name);
1676
1637
for (p= varname + 1; *p; p++)
1731
varname= ((char*) my_alloca(length));
1732
strxmov(varname + 1, plugin, "_", name, NULL);
1692
varname= ((char*) malloc(length));
1693
sprintf(varname+1, "%s_%s", plugin, name);
1733
1694
for (p= varname + 1; *p; p++)
1754
1715
if (new_size > global_variables_dynamic_size)
1756
global_system_variables.dynamic_variables_ptr= (char*)
1757
my_realloc(global_system_variables.dynamic_variables_ptr, new_size,
1758
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1759
max_system_variables.dynamic_variables_ptr= (char*)
1760
my_realloc(max_system_variables.dynamic_variables_ptr, new_size,
1761
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1719
(char *)realloc(global_system_variables.dynamic_variables_ptr,
1722
global_system_variables.dynamic_variables_ptr= tmpptr;
1725
(char *)realloc(max_system_variables.dynamic_variables_ptr,
1728
max_system_variables.dynamic_variables_ptr= tmpptr;
1763
1731
Clear the new variable value space. This is required for string
1764
1732
variables. If their value is non-NULL, it must point to a valid
1768
1736
global_variables_dynamic_size, 0,
1769
1737
new_size - global_variables_dynamic_size);
1770
1738
memset(max_system_variables.dynamic_variables_ptr +
1771
global_variables_dynamic_size, 0,
1739
global_variables_dynamic_size, 0,
1772
1740
new_size - global_variables_dynamic_size);
1773
1741
global_variables_dynamic_size= new_size;
1819
rw_rdlock(&LOCK_system_variables_hash);
1787
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1821
session->variables.dynamic_variables_ptr= (char*)
1822
my_realloc(session->variables.dynamic_variables_ptr,
1823
global_variables_dynamic_size,
1824
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1790
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
1791
global_variables_dynamic_size)))
1793
session->variables.dynamic_variables_ptr= tmpptr;
1826
1795
if (global_lock)
1827
1796
pthread_mutex_lock(&LOCK_global_system_variables);
1918
1889
void plugin_sessionvar_init(Session *session)
1920
1891
plugin_ref old_table_plugin= session->variables.table_plugin;
1922
1893
session->variables.table_plugin= NULL;
1923
1894
cleanup_variables(session, &session->variables);
1925
1896
session->variables= global_system_variables;
1926
1897
session->variables.table_plugin= NULL;
1941
1912
Unlocks all system variables which hold a reference
1943
static void unlock_variables(Session *session __attribute__((unused)),
1944
struct system_variables *vars)
1914
static void unlock_variables(Session *, struct system_variables *vars)
1946
1916
intern_plugin_unlock(NULL, vars->table_plugin);
1947
1917
vars->table_plugin= NULL;
1996
1966
void plugin_sessionvar_cleanup(Session *session)
2001
1968
unlock_variables(session, &session->variables);
2002
1969
cleanup_variables(session, &session->variables);
2004
if ((idx= session->lex->plugins.elements))
2006
list= ((plugin_ref*) session->lex->plugins.buffer) + idx - 1;
2007
while ((unsigned char*) list >= session->lex->plugins.buffer)
2008
intern_plugin_unlock(NULL, *list--);
2011
reset_dynamic(&session->lex->plugins);
2373
2328
extern "C" bool get_one_plugin_option(int optid, const struct my_option *,
2376
bool get_one_plugin_option(int optid __attribute__((unused)),
2377
const struct my_option *opt __attribute__((unused)),
2378
char *argument __attribute__((unused)))
2331
bool get_one_plugin_option(int, const struct my_option *, char *)
2396
2349
/* support --skip-plugin-foo syntax */
2397
2350
memcpy(name, plugin_name, namelen + 1);
2398
2351
my_casedn_str(&my_charset_utf8_general_ci, name);
2399
strxmov(name + namelen + 1, "plugin-", name, NULL);
2352
sprintf(name+namelen+1, "plugin-%s", name);
2400
2353
/* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */
2402
2355
for (p= name + namelen*2 + 8; p > name; p--)
2406
2359
if (can_disable)
2408
strxmov(name + namelen*2 + 10, "Enable ", plugin_name, " plugin. "
2409
"Disable with --skip-", name," (will save memory).", NULL);
2361
sprintf(name+namelen*2+10,
2362
"Enable %s plugin. Disable with --skip-%s (will save memory).",
2411
2365
Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 +
2412
2366
20 + namelen + 20 + 1 == namelen * 4 + 67.
2503
2457
if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
2505
2459
opt->flags|= PLUGIN_VAR_READONLY;
2506
sql_print_warning(_("Server variable %s of plugin %s was forced "
2460
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
2507
2461
"to be read-only: string variable without "
2508
2462
"update_func and PLUGIN_VAR_MEMALLOC flag"),
2509
2463
opt->name, plugin_name);
2544
2498
optnamelen= strlen(opt->name);
2545
2499
optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
2546
strxmov(optname, name, "-", opt->name, NULL);
2500
sprintf(optname, "%s-%s", name, opt->name);
2547
2501
optnamelen= namelen + optnamelen + 1;
2551
2505
/* this should not fail because register_var should create entry */
2552
2506
if (!(v= find_bookmark(name, opt->name, opt->flags)))
2554
sql_print_error(_("Thread local variable '%s' not allocated "
2508
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
2555
2509
"in plugin '%s'."), opt->name, plugin_name);
2586
2540
options[1]= options[0];
2587
2541
options[1].name= p= (char*) alloc_root(mem_root, optnamelen + 8);
2588
2542
options[1].comment= 0; // hidden
2589
strxmov(p, "plugin-", optname, NULL);
2543
sprintf(p,"plugin-%s",optname);
2671
2625
if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
2673
sql_print_error(_("Out of memory for plugin '%s'."), tmp->name.str);
2627
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory for plugin '%s'."), tmp->name.str);
2676
2630
memset(opts, 0, sizeof(my_option) * count);
2678
2632
if (construct_options(tmp_root, tmp, opts, can_disable))
2680
sql_print_error(_("Bad options for plugin '%s'."), tmp->name.str);
2634
errmsg_printf(ERRMSG_LVL_ERROR, _("Bad options for plugin '%s'."), tmp->name.str);
2707
2661
len= tmp->name.length + strlen(o->name) + 2;
2708
2662
varname= (char*) alloc_root(mem_root, len);
2709
strxmov(varname, tmp->name.str, "-", o->name, NULL);
2663
sprintf(varname,"%s-%s",tmp->name.str,o->name);
2710
2664
my_casedn_str(&my_charset_utf8_general_ci, varname);
2712
2666
for (p= varname; *p; p++)