255
255
static void unlock_variables(THD *thd, struct system_variables *vars);
256
256
static void cleanup_variables(THD *thd, struct system_variables *vars);
257
257
static void plugin_vars_free_values(sys_var *vars);
258
static bool plugin_var_memalloc_session_update(THD *thd,
259
struct st_mysql_sys_var *var,
260
char **dest, const char *value);
261
static bool plugin_var_memalloc_global_update(THD *thd,
262
struct st_mysql_sys_var *var,
263
char **dest, const char *value);
264
static void plugin_var_memalloc_free(struct system_variables *vars);
258
265
static void restore_pluginvar_names(sys_var *first);
259
266
static void plugin_opt_set_limits(struct my_option *,
260
267
const struct st_mysql_sys_var *);
2565
2566
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
2566
2567
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
2568
char **pp= (char**) (thd->variables.dynamic_variables_ptr +
2569
*(int*)(pi->plugin_var + 1));
2570
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
2571
*(int*)(pi->plugin_var + 1))))
2572
*pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
2569
int varoff= *(int *) (pi->plugin_var + 1);
2570
char **thdvar= (char **) (thd->variables.
2571
dynamic_variables_ptr + varoff);
2572
char **sysvar= (char **) (global_system_variables.
2573
dynamic_variables_ptr + varoff);
2575
plugin_var_memalloc_session_update(thd, NULL, thdvar, *sysvar);
2676
2679
static void cleanup_variables(THD *thd, struct system_variables *vars)
2679
sys_var_pluginvar *pivar;
2684
mysql_rwlock_rdlock(&LOCK_system_variables_hash);
2685
for (idx= 0; idx < bookmark_hash.records; idx++)
2687
v= (st_bookmark*) my_hash_element(&bookmark_hash, idx);
2688
if (v->version > vars->dynamic_variables_version ||
2689
!(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
2690
!(pivar= var->cast_pluginvar()) ||
2691
v->key[0] != (pivar->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
2694
flags= pivar->plugin_var->flags;
2696
if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
2697
flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
2699
char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
2704
mysql_rwlock_unlock(&LOCK_system_variables_hash);
2682
plugin_var_memalloc_free(&thd->variables);
2706
2684
DBUG_ASSERT(vars->table_plugin == NULL);
2778
Set value for thread local variable with PLUGIN_VAR_MEMALLOC flag.
2780
@param[in] thd Thread context.
2781
@param[in] var Plugin variable.
2782
@param[in,out] dest Destination memory pointer.
2783
@param[in] value '\0'-terminated new value.
2785
Most plugin variable values are stored on dynamic_variables_ptr.
2786
Releasing memory occupied by these values is as simple as freeing
2787
dynamic_variables_ptr.
2789
An exception to the rule are PLUGIN_VAR_MEMALLOC variables, which
2790
are stored on individual memory hunks. All of these hunks has to
2791
be freed when it comes to cleanup.
2793
It may happen that a plugin was uninstalled and descriptors of
2794
it's variables are lost. In this case it is impossible to locate
2795
corresponding values.
2797
In addition to allocating and setting variable value, new element
2798
is added to dynamic_variables_allocs list. When thread is done, it
2799
has to call plugin_var_memalloc_free() to release memory used by
2800
PLUGIN_VAR_MEMALLOC variables.
2802
If var is NULL, variable update function is not called. This is
2803
needed when we take snapshot of system variables during thread
2806
@note List element and variable value are stored on the same memory
2807
hunk. List element is followed by variable value.
2809
@return Completion status
2810
@retval false Success
2811
@retval true Failure
2814
static bool plugin_var_memalloc_session_update(THD *thd,
2815
struct st_mysql_sys_var *var,
2816
char **dest, const char *value)
2819
LIST *old_element= NULL;
2820
struct system_variables *vars= &thd->variables;
2821
DBUG_ENTER("plugin_var_memalloc_session_update");
2825
size_t length= strlen(value) + 1;
2827
if (!(element= (LIST *) my_malloc(sizeof(LIST) + length, MYF(MY_WME))))
2829
memcpy(element + 1, value, length);
2830
value= (const char *) (element + 1);
2831
vars->dynamic_variables_allocs= list_add(vars->dynamic_variables_allocs,
2836
old_element= (LIST *) (*dest - sizeof(LIST));
2839
var->update(thd, var, (void **) dest, (const void *) &value);
2841
*dest= (char *) value;
2845
vars->dynamic_variables_allocs= list_delete(vars->dynamic_variables_allocs,
2847
my_free(old_element);
2854
Free all elements allocated by plugin_var_memalloc_session_update().
2856
@param[in] vars system variables structure
2858
@see plugin_var_memalloc_session_update
2861
static void plugin_var_memalloc_free(struct system_variables *vars)
2864
DBUG_ENTER("plugin_var_memalloc_free");
2865
for (root= vars->dynamic_variables_allocs; root; root= next)
2870
vars->dynamic_variables_allocs= NULL;
2876
Set value for global variable with PLUGIN_VAR_MEMALLOC flag.
2878
@param[in] thd Thread context.
2879
@param[in] var Plugin variable.
2880
@param[in,out] dest Destination memory pointer.
2881
@param[in] value '\0'-terminated new value.
2883
@return Completion status
2884
@retval false Success
2885
@retval true Failure
2888
static bool plugin_var_memalloc_global_update(THD *thd,
2889
struct st_mysql_sys_var *var,
2890
char **dest, const char *value)
2892
char *old_value= *dest;
2893
DBUG_ENTER("plugin_var_memalloc_global_update");
2895
if (value && !(value= my_strdup(value, MYF(MY_WME))))
2898
var->update(thd, var, (void **) dest, (const void *) &value);
2799
2907
bool sys_var_pluginvar::check_update_type(Item_result type)
2801
2909
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2889
2998
const void *src= var->value ? (void*)&var->save_result
2890
2999
: (void*)real_value_ptr(thd, OPT_GLOBAL);
2891
3000
mysql_mutex_unlock(&LOCK_global_system_variables);
2892
plugin_var->update(thd, plugin_var, tgt, src);
3002
if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
3003
plugin_var->flags & PLUGIN_VAR_MEMALLOC)
3004
rc= plugin_var_memalloc_session_update(thd, plugin_var, (char **) tgt,
3005
*(const char **) src);
3007
plugin_var->update(thd, plugin_var, tgt, src);
2897
3012
bool sys_var_pluginvar::global_update(THD *thd, set_var *var)
2899
3015
DBUG_ASSERT(!is_readonly());
2900
3016
mysql_mutex_assert_owner(&LOCK_global_system_variables);