~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to sql/sql_plugin.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-02-14 23:59:22 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120214235922-cux5uek1e5l0hje9
Tags: 5.5.20-0ubuntu1
* New upstream release.
* d/mysql-server-5.5.mysql.upstart: Fix stop on to make sure mysql is
  fully stopped before shutdown commences. (LP: #688541) Also simplify
  start on as it is redundant.
* d/control: Depend on upstart version which has apparmor profile load
  script to prevent failure on upgrade from lucid to precise.
  (LP: #907465)
* d/apparmor-profile: need to allow /run since that is the true path
  of /var/run files. (LP: #917542)
* d/control: mysql-server-5.5 has files in it that used to be owned
  by libmysqlclient-dev, so it must break/replace it. (LP: #912487)
* d/rules, d/control: 5.5.20 Fixes segfault on tests with gcc 4.6,
  change compiler back to system default.
* d/rules: Turn off embedded libedit/readline.(Closes: #659566)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 *);
2300
2307
static void update_func_str(THD *thd, struct st_mysql_sys_var *var,
2301
2308
                             void *tgt, const void *save)
2302
2309
{
2303
 
  char *old= *(char **) tgt;
2304
 
  *(char **)tgt= *(char **) save;
2305
 
  if (var->flags & PLUGIN_VAR_MEMALLOC)
2306
 
  {
2307
 
    *(char **)tgt= my_strdup(*(char **) save, MYF(0));
2308
 
    my_free(old);
2309
 
  }
 
2310
  *(char **) tgt= *(char **) save;
2310
2311
}
2311
2312
 
2312
2313
 
2565
2566
      if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
2566
2567
          pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
2567
2568
      {
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);
 
2574
         *thdvar= NULL;
 
2575
         plugin_var_memalloc_session_update(thd, NULL, thdvar, *sysvar);
2573
2576
      }
2574
2577
    }
2575
2578
 
2675
2678
*/
2676
2679
static void cleanup_variables(THD *thd, struct system_variables *vars)
2677
2680
{
2678
 
  st_bookmark *v;
2679
 
  sys_var_pluginvar *pivar;
2680
 
  sys_var *var;
2681
 
  int flags;
2682
 
  uint idx;
2683
 
 
2684
 
  mysql_rwlock_rdlock(&LOCK_system_variables_hash);
2685
 
  for (idx= 0; idx < bookmark_hash.records; idx++)
2686
 
  {
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))
2692
 
      continue;
2693
 
 
2694
 
    flags= pivar->plugin_var->flags;
2695
 
 
2696
 
    if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
2697
 
        flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
2698
 
    {
2699
 
      char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
2700
 
      my_free(*ptr);
2701
 
      *ptr= NULL;
2702
 
    }
2703
 
  }
2704
 
  mysql_rwlock_unlock(&LOCK_system_variables_hash);
 
2681
  if (thd)
 
2682
    plugin_var_memalloc_free(&thd->variables);
2705
2683
 
2706
2684
  DBUG_ASSERT(vars->table_plugin == NULL);
2707
2685
 
2796
2774
}
2797
2775
 
2798
2776
 
 
2777
/**
 
2778
  Set value for thread local variable with PLUGIN_VAR_MEMALLOC flag.
 
2779
 
 
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.
 
2784
 
 
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.
 
2788
 
 
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.
 
2792
 
 
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.
 
2796
 
 
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.
 
2801
 
 
2802
  If var is NULL, variable update function is not called. This is
 
2803
  needed when we take snapshot of system variables during thread
 
2804
  initialization.
 
2805
 
 
2806
  @note List element and variable value are stored on the same memory
 
2807
  hunk. List element is followed by variable value.
 
2808
 
 
2809
  @return Completion status
 
2810
  @retval false Success
 
2811
  @retval true  Failure
 
2812
*/
 
2813
 
 
2814
static bool plugin_var_memalloc_session_update(THD *thd,
 
2815
                                               struct st_mysql_sys_var *var,
 
2816
                                               char **dest, const char *value)
 
2817
 
 
2818
{
 
2819
  LIST *old_element= NULL;
 
2820
  struct system_variables *vars= &thd->variables;
 
2821
  DBUG_ENTER("plugin_var_memalloc_session_update");
 
2822
 
 
2823
  if (value)
 
2824
  {
 
2825
    size_t length= strlen(value) + 1;
 
2826
    LIST *element;
 
2827
    if (!(element= (LIST *) my_malloc(sizeof(LIST) + length, MYF(MY_WME))))
 
2828
      DBUG_RETURN(true);
 
2829
    memcpy(element + 1, value, length);
 
2830
    value= (const char *) (element + 1);
 
2831
    vars->dynamic_variables_allocs= list_add(vars->dynamic_variables_allocs,
 
2832
                                             element);
 
2833
  }
 
2834
 
 
2835
  if (*dest)
 
2836
    old_element= (LIST *) (*dest - sizeof(LIST));
 
2837
 
 
2838
  if (var)
 
2839
    var->update(thd, var, (void **) dest, (const void *) &value);
 
2840
  else
 
2841
    *dest= (char *) value;
 
2842
 
 
2843
  if (old_element)
 
2844
  {
 
2845
    vars->dynamic_variables_allocs= list_delete(vars->dynamic_variables_allocs,
 
2846
                                                old_element);
 
2847
    my_free(old_element);
 
2848
  }
 
2849
  DBUG_RETURN(false);
 
2850
}
 
2851
 
 
2852
 
 
2853
/**
 
2854
  Free all elements allocated by plugin_var_memalloc_session_update().
 
2855
 
 
2856
  @param[in]     vars  system variables structure
 
2857
 
 
2858
  @see plugin_var_memalloc_session_update
 
2859
*/
 
2860
 
 
2861
static void plugin_var_memalloc_free(struct system_variables *vars)
 
2862
{
 
2863
  LIST *next, *root;
 
2864
  DBUG_ENTER("plugin_var_memalloc_free");
 
2865
  for (root= vars->dynamic_variables_allocs; root; root= next)
 
2866
  {
 
2867
    next= root->next;
 
2868
    my_free(root);
 
2869
  }
 
2870
  vars->dynamic_variables_allocs= NULL;
 
2871
  DBUG_VOID_RETURN;
 
2872
}
 
2873
 
 
2874
 
 
2875
/**
 
2876
  Set value for global variable with PLUGIN_VAR_MEMALLOC flag.
 
2877
 
 
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.
 
2882
 
 
2883
  @return Completion status
 
2884
  @retval false Success
 
2885
  @retval true  Failure
 
2886
*/
 
2887
 
 
2888
static bool plugin_var_memalloc_global_update(THD *thd,
 
2889
                                              struct st_mysql_sys_var *var,
 
2890
                                              char **dest, const char *value)
 
2891
{
 
2892
  char *old_value= *dest;
 
2893
  DBUG_ENTER("plugin_var_memalloc_global_update");
 
2894
 
 
2895
  if (value && !(value= my_strdup(value, MYF(MY_WME))))
 
2896
    DBUG_RETURN(true);
 
2897
 
 
2898
  var->update(thd, var, (void **) dest, (const void *) &value);
 
2899
 
 
2900
  if (old_value)
 
2901
    my_free(old_value);
 
2902
 
 
2903
  DBUG_RETURN(false);
 
2904
}
 
2905
 
 
2906
 
2799
2907
bool sys_var_pluginvar::check_update_type(Item_result type)
2800
2908
{
2801
2909
  switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2880
2988
 
2881
2989
bool sys_var_pluginvar::session_update(THD *thd, set_var *var)
2882
2990
{
 
2991
  bool rc= false;
2883
2992
  DBUG_ASSERT(!is_readonly());
2884
2993
  DBUG_ASSERT(plugin_var->flags & PLUGIN_VAR_THDLOCAL);
2885
2994
  DBUG_ASSERT(thd == current_thd);
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);
2893
 
 
2894
 
  return false;
 
3001
 
 
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);
 
3006
  else 
 
3007
    plugin_var->update(thd, plugin_var, tgt, src);
 
3008
 
 
3009
  return rc;
2895
3010
}
2896
3011
 
2897
3012
bool sys_var_pluginvar::global_update(THD *thd, set_var *var)
2898
3013
{
 
3014
  bool rc= false;
2899
3015
  DBUG_ASSERT(!is_readonly());
2900
3016
  mysql_mutex_assert_owner(&LOCK_global_system_variables);
2901
3017
 
2952
3068
    }
2953
3069
  }
2954
3070
 
2955
 
  plugin_var->update(thd, plugin_var, tgt, src);
 
3071
  if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
 
3072
      plugin_var->flags & PLUGIN_VAR_MEMALLOC)
 
3073
    rc= plugin_var_memalloc_global_update(thd, plugin_var, (char **) tgt,
 
3074
                                          *(const char **) src);
 
3075
  else 
 
3076
    plugin_var->update(thd, plugin_var, tgt, src);
2956
3077
 
2957
 
  return false;
 
3078
  return rc;
2958
3079
}
2959
3080
 
2960
3081