~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <drizzled/server_includes.h>
17
17
#include <mysys/my_getopt.h>
18
 
 
19
 
#include <drizzled/authentication.h>
20
 
#include <drizzled/logging.h>
21
 
#include <drizzled/errmsg.h>
22
 
#include <drizzled/configvar.h>
23
 
#include <drizzled/qcache.h>
24
 
#include <drizzled/parser.h>
25
 
#include <drizzled/sql_parse.h>
26
 
#include <drizzled/scheduling.h>
27
 
 
28
 
#include <string>
29
 
 
30
 
#include <drizzled/error.h>
31
 
#include <drizzled/gettext.h>
32
 
 
 
18
#include <authentication.h>
 
19
#include <drizzled/drizzled_error_messages.h>
33
20
#define REPORT_TO_LOG  1
34
21
#define REPORT_TO_USER 2
35
22
 
36
23
#define plugin_ref_to_int(A) (A ? A[0] : NULL)
37
24
#define plugin_int_to_ref(A) &(A)
38
25
 
39
 
using namespace std;
40
 
 
41
26
extern struct st_mysql_plugin *mysqld_builtins[];
42
27
 
43
28
char *opt_plugin_load= NULL;
56
41
  { C_STRING_WITH_LEN("UDA") },
57
42
  { C_STRING_WITH_LEN("AUDIT") },
58
43
  { C_STRING_WITH_LEN("LOGGER") },
59
 
  { C_STRING_WITH_LEN("ERRMSG") },
60
 
  { C_STRING_WITH_LEN("AUTH") },
61
 
  { C_STRING_WITH_LEN("CONFIGVAR") },
62
 
  { C_STRING_WITH_LEN("QCACHE") },
63
 
  { C_STRING_WITH_LEN("PARSER") },
64
 
  { C_STRING_WITH_LEN("SCHEDULING") }
 
44
  { C_STRING_WITH_LEN("AUTH") }
65
45
};
66
46
 
67
47
extern int initialize_schema_table(st_plugin_int *plugin);
83
63
  initialize_udf,  /* UDF */
84
64
  0,  /* UDA */
85
65
  0,  /* Audit */
86
 
  logging_initializer,  /* Logger */
87
 
  errmsg_initializer,  /* Error Messages */
88
 
  authentication_initializer,  /* Auth */
89
 
  configvar_initializer,
90
 
  qcache_initializer,
91
 
  parser_initializer,
92
 
  scheduling_initializer
 
66
  0,  /* Logger */
 
67
  authentication_initializer  /* Auth */
93
68
};
94
69
 
95
70
plugin_type_init plugin_type_deinitialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
100
75
  finalize_udf,  /* UDF */
101
76
  0,  /* UDA */
102
77
  0,  /* Audit */
103
 
  logging_finalizer,  /* Logger */
104
 
  errmsg_finalizer,  /* Logger */
105
 
  authentication_finalizer,  /* Auth */
106
 
  configvar_finalizer,
107
 
  qcache_finalizer,
108
 
  parser_finalizer,
109
 
  scheduling_finalizer
 
78
  0,  /* Logger */
 
79
  authentication_finalizer  /* Auth */
110
80
};
111
81
 
112
82
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
128
98
  the following variables/structures
129
99
*/
130
100
static MEM_ROOT plugin_mem_root;
131
 
static uint32_t global_variables_dynamic_size= 0;
 
101
static uint global_variables_dynamic_size= 0;
132
102
static HASH bookmark_hash;
133
103
 
134
104
 
144
114
 
145
115
/*
146
116
  stored in bookmark_hash, this structure is never removed from the
147
 
  hash and is used to mark a single offset for a session local variable
 
117
  hash and is used to mark a single offset for a thd local variable
148
118
  even if plugins have been uninstalled and reinstalled, repeatedly.
149
119
  This structure is allocated from plugin_mem_root.
150
120
 
155
125
*/
156
126
struct st_bookmark
157
127
{
158
 
  uint32_t name_len;
 
128
  uint name_len;
159
129
  int offset;
160
 
  uint32_t version;
 
130
  uint version;
161
131
  char key[1];
162
132
};
163
133
 
192
162
  sys_var_pluginvar *cast_pluginvar() { return this; }
193
163
  bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
194
164
  bool check_type(enum_var_type type)
195
 
  { return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
 
165
  { return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
196
166
  bool check_update_type(Item_result type);
197
167
  SHOW_TYPE show_type();
198
 
  unsigned char* real_value_ptr(Session *session, enum_var_type type);
 
168
  uchar* real_value_ptr(THD *thd, enum_var_type type);
199
169
  TYPELIB* plugin_var_typelib(void);
200
 
  unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
201
 
  bool check(Session *session, set_var *var);
 
170
  uchar* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
171
  bool check(THD *thd, set_var *var);
202
172
  bool check_default(enum_var_type type __attribute__((unused)))
203
173
    { return is_readonly(); }
204
 
  void set_default(Session *session,
 
174
  void set_default(THD *thd,
205
175
                   enum_var_type type __attribute__((unused)));
206
 
  bool update(Session *session, set_var *var);
 
176
  bool update(THD *thd, set_var *var);
207
177
};
208
178
 
209
179
 
214
184
                               int *, char **);
215
185
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
216
186
                             struct st_plugin_int **);
217
 
static void unlock_variables(Session *session, struct system_variables *vars);
218
 
static void cleanup_variables(Session *session, struct system_variables *vars);
 
187
static void unlock_variables(THD *thd, struct system_variables *vars);
 
188
static void cleanup_variables(THD *thd, struct system_variables *vars);
219
189
static void plugin_vars_free_values(sys_var *vars);
220
190
static void plugin_opt_set_limits(struct my_option *options,
221
191
                                  const struct st_mysql_sys_var *opt);
228
198
 
229
199
 
230
200
/* declared in set_var.cc */
231
 
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
232
 
extern bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
 
201
extern sys_var *intern_find_sys_var(const char *str, uint length, bool no_error);
 
202
extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
233
203
                                 const char *name, int64_t val);
234
204
 
235
205
/****************************************************************************
262
232
    Lets be nice and create a temporary string since the
263
233
    buffer was too small
264
234
  */
265
 
  return current_session->strmake(res->c_ptr_quick(), res->length());
 
235
  return current_thd->strmake(res->c_ptr_quick(), res->length());
266
236
}
267
237
 
268
238
 
292
262
 
293
263
static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl)
294
264
{
295
 
  uint32_t i;
 
265
  uint i;
296
266
  struct st_plugin_dl *tmp;
297
267
  for (i= 0; i < plugin_dl_array.elements; i++)
298
268
  {
299
269
    tmp= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
300
270
    if (tmp->ref_count &&
301
271
        ! my_strnncoll(files_charset_info,
302
 
                       (const unsigned char *)dl->str, dl->length,
303
 
                       (const unsigned char *)tmp->dl.str, tmp->dl.length))
 
272
                       (const uchar *)dl->str, dl->length,
 
273
                       (const uchar *)tmp->dl.str, tmp->dl.length))
304
274
      return(tmp);
305
275
  }
306
276
  return(0);
308
278
 
309
279
static st_plugin_dl *plugin_dl_insert_or_reuse(struct st_plugin_dl *plugin_dl)
310
280
{
311
 
  uint32_t i;
 
281
  uint i;
312
282
  struct st_plugin_dl *tmp;
313
283
  for (i= 0; i < plugin_dl_array.elements; i++)
314
284
  {
319
289
      return(tmp);
320
290
    }
321
291
  }
322
 
  if (insert_dynamic(&plugin_dl_array, (unsigned char*)&plugin_dl))
 
292
  if (insert_dynamic(&plugin_dl_array, (uchar*)&plugin_dl))
323
293
    return(0);
324
294
  tmp= *dynamic_element(&plugin_dl_array, plugin_dl_array.elements - 1,
325
295
                        struct st_plugin_dl **)=
326
 
      (struct st_plugin_dl *) memdup_root(&plugin_mem_root, (unsigned char*)plugin_dl,
 
296
      (struct st_plugin_dl *) memdup_root(&plugin_mem_root, (uchar*)plugin_dl,
327
297
                                           sizeof(struct st_plugin_dl));
328
298
  return(tmp);
329
299
}
332
302
{
333
303
  if (p->handle)
334
304
    dlclose(p->handle);
335
 
  free(p->dl.str);
 
305
  my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
336
306
}
337
307
 
338
308
 
339
309
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
340
310
{
341
 
  string dlpath;
342
 
  uint32_t plugin_dir_len, dummy_errors;
 
311
  char dlpath[FN_REFLEN];
 
312
  uint plugin_dir_len, dummy_errors, dlpathlen;
343
313
  struct st_plugin_dl *tmp, plugin_dl;
344
314
  void *sym;
345
315
  plugin_dir_len= strlen(opt_plugin_dir);
346
 
  dlpath.reserve(FN_REFLEN);
347
316
  /*
348
317
    Ensure that the dll doesn't have a path.
349
318
    This is done to ensure that only approved libraries from the
357
326
    if (report & REPORT_TO_USER)
358
327
      my_error(ER_UDF_NO_PATHS, MYF(0));
359
328
    if (report & REPORT_TO_LOG)
360
 
      sql_print_error("%s",ER(ER_UDF_NO_PATHS));
 
329
      sql_print_error(ER(ER_UDF_NO_PATHS));
361
330
    return(0);
362
331
  }
363
332
  /* If this dll is already loaded just increase ref_count. */
368
337
  }
369
338
  memset(&plugin_dl, 0, sizeof(plugin_dl));
370
339
  /* Compile dll path */
371
 
  dlpath.append(opt_plugin_dir);
372
 
  dlpath.append("/");
373
 
  dlpath.append(dl->str);
 
340
  dlpathlen=
 
341
    strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS) -
 
342
    dlpath;
374
343
  plugin_dl.ref_count= 1;
375
344
  /* Open new dll handle */
376
 
  if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
 
345
  if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
377
346
  {
378
347
    const char *errmsg=dlerror();
379
 
    uint32_t dlpathlen= dlpath.length();
380
 
    if (!dlpath.compare(0, dlpathlen, errmsg))
 
348
    if (!strncmp(dlpath, errmsg, dlpathlen))
381
349
    { // if errmsg starts from dlpath, trim this prefix.
382
350
      errmsg+=dlpathlen;
383
351
      if (*errmsg == ':') errmsg++;
384
352
      if (*errmsg == ' ') errmsg++;
385
353
    }
386
354
    if (report & REPORT_TO_USER)
387
 
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
 
355
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
388
356
    if (report & REPORT_TO_LOG)
389
 
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
 
357
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
390
358
    return(0);
391
359
  }
392
360
 
434
402
 
435
403
static void plugin_dl_del(const LEX_STRING *dl)
436
404
{
437
 
  uint32_t i;
 
405
  uint i;
438
406
 
439
407
  for (i= 0; i < plugin_dl_array.elements; i++)
440
408
  {
442
410
                                               struct st_plugin_dl **);
443
411
    if (tmp->ref_count &&
444
412
        ! my_strnncoll(files_charset_info,
445
 
                       (const unsigned char *)dl->str, dl->length,
446
 
                       (const unsigned char *)tmp->dl.str, tmp->dl.length))
 
413
                       (const uchar *)dl->str, dl->length,
 
414
                       (const uchar *)tmp->dl.str, tmp->dl.length))
447
415
    {
448
416
      /* Do not remove this element, unless no other plugin uses this dll. */
449
417
      if (! --tmp->ref_count)
460
428
 
461
429
static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int type)
462
430
{
463
 
  uint32_t i;
 
431
  uint i;
464
432
  if (! initialized)
465
433
    return(0);
466
434
 
469
437
    for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
470
438
    {
471
439
      struct st_plugin_int *plugin= (st_plugin_int *)
472
 
        hash_search(&plugin_hash[i], (const unsigned char *)name->str, name->length);
 
440
        hash_search(&plugin_hash[i], (const uchar *)name->str, name->length);
473
441
      if (plugin)
474
442
        return(plugin);
475
443
    }
476
444
  }
477
445
  else
478
446
    return((st_plugin_int *)
479
 
        hash_search(&plugin_hash[type], (const unsigned char *)name->str, name->length));
 
447
        hash_search(&plugin_hash[type], (const uchar *)name->str, name->length));
480
448
  return(0);
481
449
}
482
450
 
530
498
    pi->ref_count++;
531
499
 
532
500
    if (lex)
533
 
      insert_dynamic(&lex->plugins, (unsigned char*)&plugin);
 
501
      insert_dynamic(&lex->plugins, (uchar*)&plugin);
534
502
    return(plugin);
535
503
  }
536
504
  return(NULL);
537
505
}
538
506
 
539
507
 
540
 
plugin_ref plugin_lock(Session *session, plugin_ref *ptr CALLER_INFO_PROTO)
 
508
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
541
509
{
542
 
  LEX *lex= session ? session->lex : 0;
 
510
  LEX *lex= thd ? thd->lex : 0;
543
511
  plugin_ref rc;
544
512
  rc= my_intern_plugin_lock_ci(lex, *ptr);
545
513
  return(rc);
546
514
}
547
515
 
548
516
 
549
 
plugin_ref plugin_lock_by_name(Session *session, const LEX_STRING *name, int type
 
517
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
550
518
                               CALLER_INFO_PROTO)
551
519
{
552
 
  LEX *lex= session ? session->lex : 0;
 
520
  LEX *lex= thd ? thd->lex : 0;
553
521
  plugin_ref rc= NULL;
554
522
  st_plugin_int *plugin;
555
523
  if ((plugin= plugin_find_internal(name, type)))
560
528
 
561
529
static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
562
530
{
563
 
  uint32_t i;
 
531
  uint i;
564
532
  struct st_plugin_int *tmp;
565
533
  for (i= 0; i < plugin_array.elements; i++)
566
534
  {
571
539
      return(tmp);
572
540
    }
573
541
  }
574
 
  if (insert_dynamic(&plugin_array, (unsigned char*)&plugin))
 
542
  if (insert_dynamic(&plugin_array, (uchar*)&plugin))
575
543
    return(0);
576
544
  tmp= *dynamic_element(&plugin_array, plugin_array.elements - 1,
577
545
                        struct st_plugin_int **)=
578
 
       (struct st_plugin_int *) memdup_root(&plugin_mem_root, (unsigned char*)plugin,
 
546
       (struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)plugin,
579
547
                                            sizeof(struct st_plugin_int));
580
548
  return(tmp);
581
549
}
606
574
  /* Find plugin by name */
607
575
  for (plugin= tmp.plugin_dl->plugins; plugin->name; plugin++)
608
576
  {
609
 
    uint32_t name_len= strlen(plugin->name);
610
 
    if (plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
 
577
    uint name_len= strlen(plugin->name);
 
578
    if (plugin->type >= 0 && plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
611
579
        ! my_strnncoll(system_charset_info,
612
 
                       (const unsigned char *)name->str, name->length,
613
 
                       (const unsigned char *)plugin->name,
 
580
                       (const uchar *)name->str, name->length,
 
581
                       (const uchar *)plugin->name,
614
582
                       name_len))
615
583
    {
616
584
      struct st_plugin_int *tmp_plugin_ptr;
625
593
        if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
626
594
        {
627
595
          plugin_array_version++;
628
 
          if (!my_hash_insert(&plugin_hash[plugin->type], (unsigned char*)tmp_plugin_ptr))
 
596
          if (!my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr))
629
597
          {
630
598
            init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
631
599
            return(false);
686
654
  plugin->state= PLUGIN_IS_UNINITIALIZED;
687
655
 
688
656
  /*
689
 
    We do the check here because NDB has a worker Session which doesn't
 
657
    We do the check here because NDB has a worker THD which doesn't
690
658
    exit until NDB is shut down.
691
659
  */
692
660
  if (ref_check && plugin->ref_count)
699
667
{
700
668
  /* Free allocated strings before deleting the plugin. */
701
669
  plugin_vars_free_values(plugin->system_vars);
702
 
  hash_delete(&plugin_hash[plugin->plugin->type], (unsigned char*)plugin);
 
670
  hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
703
671
  if (plugin->plugin_dl)
704
672
    plugin_dl_del(&plugin->plugin_dl->dl);
705
673
  plugin->state= PLUGIN_IS_FREED;
713
681
 
714
682
static void reap_plugins(void)
715
683
{
716
 
  uint32_t count, idx;
 
684
  uint count, idx;
717
685
  struct st_plugin_int *plugin, **reap, **list;
718
686
 
719
687
  if (!reap_needed)
755
723
 
756
724
  pi= plugin_ref_to_int(plugin);
757
725
 
758
 
  free((unsigned char*) plugin);
 
726
  my_free((uchar*) plugin, MYF(MY_WME));
759
727
 
760
728
  if (lex)
761
729
  {
783
751
}
784
752
 
785
753
 
786
 
void plugin_unlock(Session *session, plugin_ref plugin)
 
754
void plugin_unlock(THD *thd, plugin_ref plugin)
787
755
{
788
 
  LEX *lex= session ? session->lex : 0;
 
756
  LEX *lex= thd ? thd->lex : 0;
789
757
  if (!plugin)
790
758
    return;
791
759
  intern_plugin_unlock(lex, plugin);
793
761
}
794
762
 
795
763
 
796
 
void plugin_unlock_list(Session *session, plugin_ref *list, uint32_t count)
 
764
void plugin_unlock_list(THD *thd, plugin_ref *list, uint count)
797
765
{
798
 
  LEX *lex= session ? session->lex : 0;
 
766
  LEX *lex= thd ? thd->lex : 0;
799
767
  assert(list);
800
768
  while (count--)
801
769
    intern_plugin_unlock(lex, *list++);
870
838
}
871
839
 
872
840
 
873
 
extern "C" unsigned char *get_plugin_hash_key(const unsigned char *, size_t *, bool);
874
 
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
875
 
 
876
 
 
877
 
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length,
 
841
extern "C" uchar *get_plugin_hash_key(const uchar *, size_t *, bool);
 
842
extern "C" uchar *get_bookmark_hash_key(const uchar *, size_t *, bool);
 
843
 
 
844
 
 
845
uchar *get_plugin_hash_key(const uchar *buff, size_t *length,
878
846
                           bool not_used __attribute__((unused)))
879
847
{
880
848
  struct st_plugin_int *plugin= (st_plugin_int *)buff;
881
849
  *length= (uint)plugin->name.length;
882
 
  return((unsigned char *)plugin->name.str);
 
850
  return((uchar *)plugin->name.str);
883
851
}
884
852
 
885
853
 
886
 
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length,
 
854
uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
887
855
                             bool not_used __attribute__((unused)))
888
856
{
889
857
  struct st_bookmark *var= (st_bookmark *)buff;
890
858
  *length= var->name_len + 1;
891
 
  return (unsigned char*) var->key;
 
859
  return (uchar*) var->key;
892
860
}
893
861
 
894
862
 
901
869
*/
902
870
int plugin_init(int *argc, char **argv, int flags)
903
871
{
904
 
  uint32_t i;
 
872
  uint i;
905
873
  struct st_mysql_plugin **builtins;
906
874
  struct st_mysql_plugin *plugin;
907
875
  struct st_plugin_int tmp, *plugin_ptr, **reap;
1034
1002
  tmp->ref_count= 0;
1035
1003
  tmp->plugin_dl= 0;
1036
1004
 
1037
 
  if (insert_dynamic(&plugin_array, (unsigned char*)&tmp))
 
1005
  if (insert_dynamic(&plugin_array, (uchar*)&tmp))
1038
1006
    return(1);
1039
1007
 
1040
1008
  *ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
1041
1009
                         struct st_plugin_int **)=
1042
 
        (struct st_plugin_int *) memdup_root(&plugin_mem_root, (unsigned char*)tmp,
 
1010
        (struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)tmp,
1043
1011
                                             sizeof(struct st_plugin_int));
1044
1012
 
1045
 
  if (my_hash_insert(&plugin_hash[plugin->type],(unsigned char*) *ptr))
 
1013
  if (my_hash_insert(&plugin_hash[plugin->type],(uchar*) *ptr))
1046
1014
    return(1);
1047
1015
 
1048
1016
  return(0);
1132
1100
 
1133
1101
void plugin_shutdown(void)
1134
1102
{
1135
 
  uint32_t i, count= plugin_array.elements, free_slots= 0;
 
1103
  uint i, count= plugin_array.elements, free_slots= 0;
1136
1104
  struct st_plugin_int **plugins, *plugin;
1137
1105
  struct st_plugin_dl **dl;
1138
1106
 
1255
1223
}
1256
1224
 
1257
1225
 
1258
 
bool plugin_foreach_with_mask(Session *session, plugin_foreach_func *func,
1259
 
                       int type, uint32_t state_mask, void *arg)
 
1226
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
 
1227
                       int type, uint state_mask, void *arg)
1260
1228
{
1261
 
  uint32_t idx, total;
 
1229
  uint idx, total;
1262
1230
  struct st_plugin_int *plugin, **plugins;
1263
1231
  int version=plugin_array_version;
1264
1232
 
1295
1263
  {
1296
1264
    if (unlikely(version != plugin_array_version))
1297
1265
    {
1298
 
      for (uint32_t i=idx; i < total; i++)
 
1266
      for (uint i=idx; i < total; i++)
1299
1267
        if (plugins[i] && plugins[i]->state & state_mask)
1300
1268
          plugins[i]=0;
1301
1269
    }
1302
1270
    plugin= plugins[idx];
1303
1271
    /* It will stop iterating on first engine error when "func" returns true */
1304
 
    if (plugin && func(session, plugin_int_to_ref(plugin), arg))
 
1272
    if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
1305
1273
        goto err;
1306
1274
  }
1307
1275
 
1324
1292
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1325
1293
 
1326
1294
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1327
 
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
 
1295
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
1328
1296
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1329
 
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
 
1297
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
1330
1298
 
1331
1299
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1332
 
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
 
1300
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
1333
1301
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1334
 
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
 
1302
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
1335
1303
 
1336
1304
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1337
1305
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1340
1308
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1341
1309
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1342
1310
 
1343
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
1344
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
1345
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
1346
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
1347
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
1348
 
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
 
1311
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int_t, int);
 
1312
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_long_t, long);
 
1313
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
 
1314
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint_t, uint);
 
1315
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
 
1316
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
1349
1317
 
1350
 
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
 
1318
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
1351
1319
 
1352
1320
 
1353
1321
/****************************************************************************
1354
1322
  default variable data check and update functions
1355
1323
****************************************************************************/
1356
1324
 
1357
 
static int check_func_bool(Session *session __attribute__((unused)),
 
1325
static int check_func_bool(THD *thd __attribute__((unused)),
1358
1326
                           struct st_mysql_sys_var *var,
1359
1327
                           void *save, st_mysql_value *value)
1360
1328
{
1394
1362
}
1395
1363
 
1396
1364
 
1397
 
static int check_func_int(Session *session, struct st_mysql_sys_var *var,
 
1365
static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
1398
1366
                          void *save, st_mysql_value *value)
1399
1367
{
1400
1368
  bool fixed;
1404
1372
  plugin_opt_set_limits(&options, var);
1405
1373
 
1406
1374
  if (var->flags & PLUGIN_VAR_UNSIGNED)
1407
 
    *(uint32_t *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
 
1375
    *(uint *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1408
1376
                                                   &fixed);
1409
1377
  else
1410
1378
    *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1411
1379
 
1412
 
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1380
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1413
1381
                              var->name, (int64_t) tmp);
1414
1382
}
1415
1383
 
1416
1384
 
1417
 
static int check_func_long(Session *session, struct st_mysql_sys_var *var,
 
1385
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
1418
1386
                          void *save, st_mysql_value *value)
1419
1387
{
1420
1388
  bool fixed;
1429
1397
  else
1430
1398
    *(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
1431
1399
 
1432
 
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1400
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1433
1401
                              var->name, (int64_t) tmp);
1434
1402
}
1435
1403
 
1436
1404
 
1437
 
static int check_func_int64_t(Session *session, struct st_mysql_sys_var *var,
 
1405
static int check_func_int64_t(THD *thd, struct st_mysql_sys_var *var,
1438
1406
                               void *save, st_mysql_value *value)
1439
1407
{
1440
1408
  bool fixed;
1449
1417
  else
1450
1418
    *(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
1451
1419
 
1452
 
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1420
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1453
1421
                              var->name, (int64_t) tmp);
1454
1422
}
1455
1423
 
1456
 
static int check_func_str(Session *session,
 
1424
static int check_func_str(THD *thd,
1457
1425
                          struct st_mysql_sys_var *var __attribute__((unused)),
1458
1426
                          void *save, st_mysql_value *value)
1459
1427
{
1463
1431
 
1464
1432
  length= sizeof(buff);
1465
1433
  if ((str= value->val_str(value, buff, &length)))
1466
 
    str= session->strmake(str, length);
 
1434
    str= thd->strmake(str, length);
1467
1435
  *(const char**)save= str;
1468
1436
  return 0;
1469
1437
}
1470
1438
 
1471
1439
 
1472
 
static int check_func_enum(Session *session __attribute__((unused)),
 
1440
static int check_func_enum(THD *thd __attribute__((unused)),
1473
1441
                           struct st_mysql_sys_var *var,
1474
1442
                           void *save, st_mysql_value *value)
1475
1443
{
1480
1448
  long result;
1481
1449
  int length;
1482
1450
 
1483
 
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
1484
 
    typelib= ((sessionvar_enum_t*) var)->typelib;
 
1451
  if (var->flags & PLUGIN_VAR_THDLOCAL)
 
1452
    typelib= ((thdvar_enum_t*) var)->typelib;
1485
1453
  else
1486
1454
    typelib= ((sysvar_enum_t*) var)->typelib;
1487
1455
 
1516
1484
}
1517
1485
 
1518
1486
 
1519
 
static int check_func_set(Session *session __attribute__((unused)),
 
1487
static int check_func_set(THD *thd __attribute__((unused)),
1520
1488
                          struct st_mysql_sys_var *var,
1521
1489
                          void *save, st_mysql_value *value)
1522
1490
{
1524
1492
  const char *strvalue= "NULL", *str;
1525
1493
  TYPELIB *typelib;
1526
1494
  uint64_t result;
1527
 
  uint32_t error_len;
 
1495
  uint error_len;
1528
1496
  bool not_used;
1529
1497
  int length;
1530
1498
 
1531
 
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
1532
 
    typelib= ((sessionvar_set_t*) var)->typelib;
 
1499
  if (var->flags & PLUGIN_VAR_THDLOCAL)
 
1500
    typelib= ((thdvar_set_t*) var)->typelib;
1533
1501
  else
1534
1502
    typelib= ((sysvar_set_t*)var)->typelib;
1535
1503
 
1542
1510
                     &error, &error_len, &not_used);
1543
1511
    if (error_len)
1544
1512
    {
1545
 
      strmake(buff, error, cmin(sizeof(buff), (unsigned long)error_len));
 
1513
      strmake(buff, error, min(sizeof(buff), (unsigned long)error_len));
1546
1514
      strvalue= buff;
1547
1515
      goto err;
1548
1516
    }
1551
1519
  {
1552
1520
    if (value->val_int(value, (int64_t *)&result))
1553
1521
      goto err;
1554
 
    if (unlikely((result >= (1UL << typelib->count)) &&
 
1522
    if (unlikely((result >= (1ULL << typelib->count)) &&
1555
1523
                 (typelib->count < sizeof(long)*8)))
1556
1524
    {
1557
1525
      llstr(result, buff);
1567
1535
}
1568
1536
 
1569
1537
 
1570
 
static void update_func_bool(Session *session __attribute__((unused)),
 
1538
static void update_func_bool(THD *thd __attribute__((unused)),
1571
1539
                             struct st_mysql_sys_var *var __attribute__((unused)),
1572
1540
                             void *tgt, const void *save)
1573
1541
{
1575
1543
}
1576
1544
 
1577
1545
 
1578
 
static void update_func_int(Session *session __attribute__((unused)),
 
1546
static void update_func_int(THD *thd __attribute__((unused)),
1579
1547
                            struct st_mysql_sys_var *var __attribute__((unused)),
1580
1548
                             void *tgt, const void *save)
1581
1549
{
1583
1551
}
1584
1552
 
1585
1553
 
1586
 
static void update_func_long(Session *session __attribute__((unused)),
 
1554
static void update_func_long(THD *thd __attribute__((unused)),
1587
1555
                             struct st_mysql_sys_var *var __attribute__((unused)),
1588
1556
                             void *tgt, const void *save)
1589
1557
{
1591
1559
}
1592
1560
 
1593
1561
 
1594
 
static void update_func_int64_t(Session *session __attribute__((unused)),
 
1562
static void update_func_int64_t(THD *thd __attribute__((unused)),
1595
1563
                                 struct st_mysql_sys_var *var __attribute__((unused)),
1596
1564
                                 void *tgt, const void *save)
1597
1565
{
1599
1567
}
1600
1568
 
1601
1569
 
1602
 
static void update_func_str(Session *session __attribute__((unused)), struct st_mysql_sys_var *var,
 
1570
static void update_func_str(THD *thd __attribute__((unused)), struct st_mysql_sys_var *var,
1603
1571
                             void *tgt, const void *save)
1604
1572
{
1605
1573
  char *old= *(char **) tgt;
1607
1575
  if (var->flags & PLUGIN_VAR_MEMALLOC)
1608
1576
  {
1609
1577
    *(char **)tgt= my_strdup(*(char **) save, MYF(0));
1610
 
    free(old);
 
1578
    my_free(old, MYF(0));
1611
1579
  }
1612
1580
}
1613
1581
 
1617
1585
****************************************************************************/
1618
1586
 
1619
1587
 
1620
 
sys_var *find_sys_var(Session *session, const char *str, uint32_t length)
 
1588
sys_var *find_sys_var(THD *thd, const char *str, uint length)
1621
1589
{
1622
1590
  sys_var *var;
1623
1591
  sys_var_pluginvar *pi= NULL;
1628
1596
      (pi= var->cast_pluginvar()))
1629
1597
  {
1630
1598
    rw_unlock(&LOCK_system_variables_hash);
1631
 
    LEX *lex= session ? session->lex : 0;
 
1599
    LEX *lex= thd ? thd->lex : 0;
1632
1600
    if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
1633
1601
      var= NULL; /* failed to lock it, it must be uninstalling */
1634
1602
    else
1660
1628
static st_bookmark *find_bookmark(const char *plugin, const char *name, int flags)
1661
1629
{
1662
1630
  st_bookmark *result= NULL;
1663
 
  uint32_t namelen, length, pluginlen= 0;
 
1631
  uint namelen, length, pluginlen= 0;
1664
1632
  char *varname, *p;
1665
1633
 
1666
 
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
 
1634
  if (!(flags & PLUGIN_VAR_THDLOCAL))
1667
1635
    return NULL;
1668
1636
 
1669
1637
  namelen= strlen(name);
1674
1642
 
1675
1643
  if (plugin)
1676
1644
  {
1677
 
    strxmov(varname + 1, plugin, "_", name, NULL);
 
1645
    strxmov(varname + 1, plugin, "_", name, NullS);
1678
1646
    for (p= varname + 1; *p; p++)
1679
1647
      if (*p == '-')
1680
1648
        *p= '_';
1685
1653
  varname[0]= flags & PLUGIN_VAR_TYPEMASK;
1686
1654
 
1687
1655
  result= (st_bookmark*) hash_search(&bookmark_hash,
1688
 
                                     (const unsigned char*) varname, length - 1);
 
1656
                                     (const uchar*) varname, length - 1);
1689
1657
 
1690
1658
  my_afree(varname);
1691
1659
  return result;
1693
1661
 
1694
1662
 
1695
1663
/*
1696
 
  returns a bookmark for session-local variables, creating if neccessary.
1697
 
  returns null for non session-local variables.
 
1664
  returns a bookmark for thd-local variables, creating if neccessary.
 
1665
  returns null for non thd-local variables.
1698
1666
  Requires that a write lock is obtained on LOCK_system_variables_hash
1699
1667
*/
1700
1668
static st_bookmark *register_var(const char *plugin, const char *name,
1701
1669
                                 int flags)
1702
1670
{
1703
 
  uint32_t length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
 
1671
  uint length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
1704
1672
  st_bookmark *result;
1705
1673
  char *varname, *p;
1706
1674
 
1707
 
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
 
1675
  if (!(flags & PLUGIN_VAR_THDLOCAL))
1708
1676
    return NULL;
1709
1677
 
1710
1678
  switch (flags & PLUGIN_VAR_TYPEMASK) {
1731
1699
  };
1732
1700
 
1733
1701
  varname= ((char*) my_alloca(length));
1734
 
  strxmov(varname + 1, plugin, "_", name, NULL);
 
1702
  strxmov(varname + 1, plugin, "_", name, NullS);
1735
1703
  for (p= varname + 1; *p; p++)
1736
1704
    if (*p == '-')
1737
1705
      *p= '_';
1785
1753
    result->version= global_system_variables.dynamic_variables_version;
1786
1754
 
1787
1755
    /* this should succeed because we have already checked if a dup exists */
1788
 
    if (my_hash_insert(&bookmark_hash, (unsigned char*) result))
 
1756
    if (my_hash_insert(&bookmark_hash, (uchar*) result))
1789
1757
    {
1790
1758
      fprintf(stderr, "failed to add placeholder to hash");
1791
1759
      assert(0);
1797
1765
 
1798
1766
 
1799
1767
/*
1800
 
  returns a pointer to the memory which holds the session-local variable or
1801
 
  a pointer to the global variable if session==null.
 
1768
  returns a pointer to the memory which holds the thd-local variable or
 
1769
  a pointer to the global variable if thd==null.
1802
1770
  If required, will sync with global variables if the requested variable
1803
1771
  has not yet been allocated in the current thread.
1804
1772
*/
1805
 
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
 
1773
static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
1806
1774
{
1807
1775
  assert(offset >= 0);
1808
1776
  assert((uint)offset <= global_system_variables.dynamic_variables_head);
1809
1777
 
1810
 
  if (!session)
1811
 
    return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
 
1778
  if (!thd)
 
1779
    return (uchar*) global_system_variables.dynamic_variables_ptr + offset;
1812
1780
 
1813
1781
  /*
1814
1782
    dynamic_variables_head points to the largest valid offset
1815
1783
  */
1816
 
  if (!session->variables.dynamic_variables_ptr ||
1817
 
      (uint)offset > session->variables.dynamic_variables_head)
 
1784
  if (!thd->variables.dynamic_variables_ptr ||
 
1785
      (uint)offset > thd->variables.dynamic_variables_head)
1818
1786
  {
1819
 
    uint32_t idx;
 
1787
    uint idx;
1820
1788
 
1821
1789
    rw_rdlock(&LOCK_system_variables_hash);
1822
1790
 
1823
 
    session->variables.dynamic_variables_ptr= (char*)
1824
 
      my_realloc(session->variables.dynamic_variables_ptr,
 
1791
    thd->variables.dynamic_variables_ptr= (char*)
 
1792
      my_realloc(thd->variables.dynamic_variables_ptr,
1825
1793
                 global_variables_dynamic_size,
1826
1794
                 MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1827
1795
 
1830
1798
 
1831
1799
    safe_mutex_assert_owner(&LOCK_global_system_variables);
1832
1800
 
1833
 
    memcpy(session->variables.dynamic_variables_ptr +
1834
 
             session->variables.dynamic_variables_size,
 
1801
    memcpy(thd->variables.dynamic_variables_ptr +
 
1802
             thd->variables.dynamic_variables_size,
1835
1803
           global_system_variables.dynamic_variables_ptr +
1836
 
             session->variables.dynamic_variables_size,
 
1804
             thd->variables.dynamic_variables_size,
1837
1805
           global_system_variables.dynamic_variables_size -
1838
 
             session->variables.dynamic_variables_size);
 
1806
             thd->variables.dynamic_variables_size);
1839
1807
 
1840
1808
    /*
1841
1809
      now we need to iterate through any newly copied 'defaults'
1847
1815
      sys_var *var;
1848
1816
      st_bookmark *v= (st_bookmark*) hash_element(&bookmark_hash,idx);
1849
1817
 
1850
 
      if (v->version <= session->variables.dynamic_variables_version ||
 
1818
      if (v->version <= thd->variables.dynamic_variables_version ||
1851
1819
          !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
1852
1820
          !(pi= var->cast_pluginvar()) ||
1853
1821
          v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1858
1826
      if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1859
1827
          pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1860
1828
      {
1861
 
         char **pp= (char**) (session->variables.dynamic_variables_ptr +
 
1829
         char **pp= (char**) (thd->variables.dynamic_variables_ptr +
1862
1830
                             *(int*)(pi->plugin_var + 1));
1863
1831
         if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1864
1832
                             *(int*)(pi->plugin_var + 1))))
1869
1837
    if (global_lock)
1870
1838
      pthread_mutex_unlock(&LOCK_global_system_variables);
1871
1839
 
1872
 
    session->variables.dynamic_variables_version=
 
1840
    thd->variables.dynamic_variables_version=
1873
1841
           global_system_variables.dynamic_variables_version;
1874
 
    session->variables.dynamic_variables_head=
 
1842
    thd->variables.dynamic_variables_head=
1875
1843
           global_system_variables.dynamic_variables_head;
1876
 
    session->variables.dynamic_variables_size=
 
1844
    thd->variables.dynamic_variables_size=
1877
1845
           global_system_variables.dynamic_variables_size;
1878
1846
 
1879
1847
    rw_unlock(&LOCK_system_variables_hash);
1880
1848
  }
1881
 
  return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1882
 
}
1883
 
 
1884
 
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1885
 
{
1886
 
  return (bool *)intern_sys_var_ptr(a_session, offset, true);
1887
 
}
1888
 
 
1889
 
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1890
 
{
1891
 
  return (int *)intern_sys_var_ptr(a_session, offset, true);
1892
 
}
1893
 
 
1894
 
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1895
 
{
1896
 
  return (long *)intern_sys_var_ptr(a_session, offset, true);
1897
 
}
1898
 
 
1899
 
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1900
 
{
1901
 
  return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1902
 
}
1903
 
 
1904
 
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1905
 
{
1906
 
  return (char **)intern_sys_var_ptr(a_session, offset, true);
1907
 
}
1908
 
 
1909
 
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
1910
 
{
1911
 
  return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
1912
 
}
1913
 
 
1914
 
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
1915
 
{
1916
 
  return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
1917
 
}
1918
 
 
1919
 
 
1920
 
void plugin_sessionvar_init(Session *session)
1921
 
{
1922
 
  plugin_ref old_table_plugin= session->variables.table_plugin;
1923
 
  
1924
 
  session->variables.table_plugin= NULL;
1925
 
  cleanup_variables(session, &session->variables);
1926
 
  
1927
 
  session->variables= global_system_variables;
1928
 
  session->variables.table_plugin= NULL;
 
1849
  return (uchar*)thd->variables.dynamic_variables_ptr + offset;
 
1850
}
 
1851
 
 
1852
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
 
1853
{
 
1854
  return (bool *)intern_sys_var_ptr(a_thd, offset, true);
 
1855
}
 
1856
 
 
1857
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
 
1858
{
 
1859
  return (int *)intern_sys_var_ptr(a_thd, offset, true);
 
1860
}
 
1861
 
 
1862
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
 
1863
{
 
1864
  return (long *)intern_sys_var_ptr(a_thd, offset, true);
 
1865
}
 
1866
 
 
1867
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
 
1868
{
 
1869
  return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
 
1870
}
 
1871
 
 
1872
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
 
1873
{
 
1874
  return (char **)intern_sys_var_ptr(a_thd, offset, true);
 
1875
}
 
1876
 
 
1877
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
 
1878
{
 
1879
  return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
 
1880
}
 
1881
 
 
1882
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
 
1883
{
 
1884
  return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
 
1885
}
 
1886
 
 
1887
 
 
1888
void plugin_thdvar_init(THD *thd)
 
1889
{
 
1890
  plugin_ref old_table_plugin= thd->variables.table_plugin;
 
1891
  
 
1892
  thd->variables.table_plugin= NULL;
 
1893
  cleanup_variables(thd, &thd->variables);
 
1894
  
 
1895
  thd->variables= global_system_variables;
 
1896
  thd->variables.table_plugin= NULL;
1929
1897
 
1930
1898
  /* we are going to allocate these lazily */
1931
 
  session->variables.dynamic_variables_version= 0;
1932
 
  session->variables.dynamic_variables_size= 0;
1933
 
  session->variables.dynamic_variables_ptr= 0;
 
1899
  thd->variables.dynamic_variables_version= 0;
 
1900
  thd->variables.dynamic_variables_size= 0;
 
1901
  thd->variables.dynamic_variables_ptr= 0;
1934
1902
 
1935
 
  session->variables.table_plugin=
 
1903
  thd->variables.table_plugin=
1936
1904
        my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1937
1905
  intern_plugin_unlock(NULL, old_table_plugin);
1938
1906
  return;
1942
1910
/*
1943
1911
  Unlocks all system variables which hold a reference
1944
1912
*/
1945
 
static void unlock_variables(Session *session __attribute__((unused)),
 
1913
static void unlock_variables(THD *thd __attribute__((unused)),
1946
1914
                             struct system_variables *vars)
1947
1915
{
1948
1916
  intern_plugin_unlock(NULL, vars->table_plugin);
1956
1924
  Unlike plugin_vars_free_values() it frees all variables of all plugins,
1957
1925
  it's used on shutdown.
1958
1926
*/
1959
 
static void cleanup_variables(Session *session, struct system_variables *vars)
 
1927
static void cleanup_variables(THD *thd, struct system_variables *vars)
1960
1928
{
1961
1929
  st_bookmark *v;
1962
1930
  sys_var_pluginvar *pivar;
1963
1931
  sys_var *var;
1964
1932
  int flags;
1965
 
  uint32_t idx;
 
1933
  uint idx;
1966
1934
 
1967
1935
  rw_rdlock(&LOCK_system_variables_hash);
1968
1936
  for (idx= 0; idx < bookmark_hash.records; idx++)
1977
1945
    flags= pivar->plugin_var->flags;
1978
1946
 
1979
1947
    if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1980
 
        flags & PLUGIN_VAR_SessionLOCAL && flags & PLUGIN_VAR_MEMALLOC)
 
1948
        flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1981
1949
    {
1982
 
      char **ptr= (char**) pivar->real_value_ptr(session, OPT_SESSION);
1983
 
      free(*ptr);
 
1950
      char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
 
1951
      my_free(*ptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1984
1952
      *ptr= NULL;
1985
1953
    }
1986
1954
  }
1988
1956
 
1989
1957
  assert(vars->table_plugin == NULL);
1990
1958
 
1991
 
  free(vars->dynamic_variables_ptr);
 
1959
  my_free(vars->dynamic_variables_ptr, MYF(MY_ALLOW_ZERO_PTR));
1992
1960
  vars->dynamic_variables_ptr= NULL;
1993
1961
  vars->dynamic_variables_size= 0;
1994
1962
  vars->dynamic_variables_version= 0;
1995
1963
}
1996
1964
 
1997
1965
 
1998
 
void plugin_sessionvar_cleanup(Session *session)
 
1966
void plugin_thdvar_cleanup(THD *thd)
1999
1967
{
2000
 
  uint32_t idx;
 
1968
  uint idx;
2001
1969
  plugin_ref *list;
2002
1970
 
2003
 
  unlock_variables(session, &session->variables);
2004
 
  cleanup_variables(session, &session->variables);
 
1971
  unlock_variables(thd, &thd->variables);
 
1972
  cleanup_variables(thd, &thd->variables);
2005
1973
 
2006
 
  if ((idx= session->lex->plugins.elements))
 
1974
  if ((idx= thd->lex->plugins.elements))
2007
1975
  {
2008
 
    list= ((plugin_ref*) session->lex->plugins.buffer) + idx - 1;
2009
 
    while ((unsigned char*) list >= session->lex->plugins.buffer)
 
1976
    list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
 
1977
    while ((uchar*) list >= thd->lex->plugins.buffer)
2010
1978
      intern_plugin_unlock(NULL, *list--);
2011
1979
  }
2012
1980
 
2013
 
  reset_dynamic(&session->lex->plugins);
 
1981
  reset_dynamic(&thd->lex->plugins);
2014
1982
 
2015
1983
  return;
2016
1984
}
2039
2007
    {
2040
2008
      /* Free the string from global_system_variables. */
2041
2009
      char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
2042
 
      free(*valptr);
 
2010
      my_free(*valptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
2043
2011
      *valptr= NULL;
2044
2012
    }
2045
2013
  }
2087
2055
}
2088
2056
 
2089
2057
 
2090
 
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, enum_var_type type)
 
2058
uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
2091
2059
{
2092
 
  assert(session || (type == OPT_GLOBAL));
2093
 
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
 
2060
  assert(thd || (type == OPT_GLOBAL));
 
2061
  if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
2094
2062
  {
2095
2063
    if (type == OPT_GLOBAL)
2096
 
      session= NULL;
 
2064
      thd= NULL;
2097
2065
 
2098
 
    return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
 
2066
    return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
2099
2067
  }
2100
 
  return *(unsigned char**) (plugin_var+1);
 
2068
  return *(uchar**) (plugin_var+1);
2101
2069
}
2102
2070
 
2103
2071
 
2104
2072
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
2105
2073
{
2106
 
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
 
2074
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
2107
2075
  case PLUGIN_VAR_ENUM:
2108
2076
    return ((sysvar_enum_t *)plugin_var)->typelib;
2109
2077
  case PLUGIN_VAR_SET:
2110
2078
    return ((sysvar_set_t *)plugin_var)->typelib;
2111
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2112
 
    return ((sessionvar_enum_t *)plugin_var)->typelib;
2113
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2114
 
    return ((sessionvar_set_t *)plugin_var)->typelib;
 
2079
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
 
2080
    return ((thdvar_enum_t *)plugin_var)->typelib;
 
2081
  case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
 
2082
    return ((thdvar_set_t *)plugin_var)->typelib;
2115
2083
  default:
2116
2084
    return NULL;
2117
2085
  }
2119
2087
}
2120
2088
 
2121
2089
 
2122
 
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type,
 
2090
uchar* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
2123
2091
                                    LEX_STRING *base __attribute__((unused)))
2124
2092
{
2125
 
  unsigned char* result;
 
2093
  uchar* result;
2126
2094
 
2127
 
  result= real_value_ptr(session, type);
 
2095
  result= real_value_ptr(thd, type);
2128
2096
 
2129
2097
  if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2130
 
    result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
 
2098
    result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result);
2131
2099
  else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
2132
2100
  {
2133
2101
    char buffer[STRING_BUFFER_USUAL_SIZE];
2134
2102
    String str(buffer, sizeof(buffer), system_charset_info);
2135
2103
    TYPELIB *typelib= plugin_var_typelib();
2136
2104
    uint64_t mask= 1, value= *(uint64_t*) result;
2137
 
    uint32_t i;
 
2105
    uint i;
2138
2106
 
2139
2107
    str.length(0);
2140
2108
    for (i= 0; i < typelib->count; i++, mask<<=1)
2145
2113
      str.append(',');
2146
2114
    }
2147
2115
 
2148
 
    result= (unsigned char*) "";
 
2116
    result= (uchar*) "";
2149
2117
    if (str.length())
2150
 
      result= (unsigned char*) session->strmake(str.ptr(), str.length()-1);
 
2118
      result= (uchar*) thd->strmake(str.ptr(), str.length()-1);
2151
2119
  }
2152
2120
  return result;
2153
2121
}
2154
2122
 
2155
2123
 
2156
 
bool sys_var_pluginvar::check(Session *session, set_var *var)
 
2124
bool sys_var_pluginvar::check(THD *thd, set_var *var)
2157
2125
{
2158
2126
  st_item_value_holder value;
2159
2127
  assert(is_readonly() || plugin_var->check);
2165
2133
  value.item= var->value;
2166
2134
 
2167
2135
  return is_readonly() ||
2168
 
         plugin_var->check(session, plugin_var, &var->save_result, &value);
 
2136
         plugin_var->check(thd, plugin_var, &var->save_result, &value);
2169
2137
}
2170
2138
 
2171
2139
 
2172
 
void sys_var_pluginvar::set_default(Session *session, enum_var_type type)
 
2140
void sys_var_pluginvar::set_default(THD *thd, enum_var_type type)
2173
2141
{
2174
2142
  const void *src;
2175
2143
  void *tgt;
2180
2148
    return;
2181
2149
 
2182
2150
  pthread_mutex_lock(&LOCK_global_system_variables);
2183
 
  tgt= real_value_ptr(session, type);
 
2151
  tgt= real_value_ptr(thd, type);
2184
2152
  src= ((void **) (plugin_var + 1) + 1);
2185
2153
 
2186
 
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
 
2154
  if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
2187
2155
  {
2188
2156
    if (type != OPT_GLOBAL)
2189
 
      src= real_value_ptr(session, OPT_GLOBAL);
 
2157
      src= real_value_ptr(thd, OPT_GLOBAL);
2190
2158
    else
2191
2159
    switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2192
2160
        case PLUGIN_VAR_INT:
2193
 
          src= &((sessionvar_uint_t*) plugin_var)->def_val;
 
2161
          src= &((thdvar_uint_t*) plugin_var)->def_val;
2194
2162
          break;
2195
2163
        case PLUGIN_VAR_LONG:
2196
 
          src= &((sessionvar_ulong_t*) plugin_var)->def_val;
 
2164
          src= &((thdvar_ulong_t*) plugin_var)->def_val;
2197
2165
          break;
2198
2166
        case PLUGIN_VAR_LONGLONG:
2199
 
          src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
 
2167
          src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
2200
2168
          break;
2201
2169
        case PLUGIN_VAR_ENUM:
2202
 
          src= &((sessionvar_enum_t*) plugin_var)->def_val;
 
2170
          src= &((thdvar_enum_t*) plugin_var)->def_val;
2203
2171
          break;
2204
2172
        case PLUGIN_VAR_SET:
2205
 
          src= &((sessionvar_set_t*) plugin_var)->def_val;
 
2173
          src= &((thdvar_set_t*) plugin_var)->def_val;
2206
2174
          break;
2207
2175
        case PLUGIN_VAR_BOOL:
2208
 
          src= &((sessionvar_bool_t*) plugin_var)->def_val;
 
2176
          src= &((thdvar_bool_t*) plugin_var)->def_val;
2209
2177
          break;
2210
2178
        case PLUGIN_VAR_STR:
2211
 
          src= &((sessionvar_str_t*) plugin_var)->def_val;
 
2179
          src= &((thdvar_str_t*) plugin_var)->def_val;
2212
2180
          break;
2213
2181
        default:
2214
2182
          assert(0);
2215
2183
        }
2216
2184
  }
2217
2185
 
2218
 
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2219
 
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2220
 
              session == current_session);
 
2186
  /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
 
2187
  assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
 
2188
              thd == current_thd);
2221
2189
 
2222
 
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
 
2190
  if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL)
2223
2191
  {
2224
 
    plugin_var->update(session, plugin_var, tgt, src);
 
2192
    plugin_var->update(thd, plugin_var, tgt, src);
2225
2193
    pthread_mutex_unlock(&LOCK_global_system_variables);
2226
2194
  }
2227
2195
  else
2228
2196
  {
2229
2197
    pthread_mutex_unlock(&LOCK_global_system_variables);
2230
 
    plugin_var->update(session, plugin_var, tgt, src);
 
2198
    plugin_var->update(thd, plugin_var, tgt, src);
2231
2199
  }
2232
2200
}
2233
2201
 
2234
2202
 
2235
 
bool sys_var_pluginvar::update(Session *session, set_var *var)
 
2203
bool sys_var_pluginvar::update(THD *thd, set_var *var)
2236
2204
{
2237
2205
  void *tgt;
2238
2206
 
2239
2207
  assert(is_readonly() || plugin_var->update);
2240
2208
 
2241
 
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2242
 
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2243
 
              session == current_session);
 
2209
  /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
 
2210
  assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
 
2211
              thd == current_thd);
2244
2212
 
2245
2213
  if (is_readonly())
2246
2214
    return 1;
2247
2215
 
2248
2216
  pthread_mutex_lock(&LOCK_global_system_variables);
2249
 
  tgt= real_value_ptr(session, var->type);
 
2217
  tgt= real_value_ptr(thd, var->type);
2250
2218
 
2251
 
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
 
2219
  if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL)
2252
2220
  {
2253
2221
    /* variable we are updating has global scope, so we unlock after updating */
2254
 
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
 
2222
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2255
2223
    pthread_mutex_unlock(&LOCK_global_system_variables);
2256
2224
  }
2257
2225
  else
2258
2226
  {
2259
2227
    pthread_mutex_unlock(&LOCK_global_system_variables);
2260
 
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
 
2228
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2261
2229
  }
2262
2230
 return 0;
2263
2231
}
2277
2245
  options->sub_size= 0;
2278
2246
 
2279
2247
  switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
2280
 
                        PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
 
2248
                        PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL)) {
2281
2249
  /* global system variables */
2282
2250
  case PLUGIN_VAR_INT:
2283
2251
    OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
2309
2277
    options->typelib= ((sysvar_set_t*) opt)->typelib;
2310
2278
    options->def_value= ((sysvar_set_t*) opt)->def_val;
2311
2279
    options->min_value= options->block_size= 0;
2312
 
    options->max_value= (1UL << options->typelib->count) - 1;
 
2280
    options->max_value= (1ULL << options->typelib->count) - 1;
2313
2281
    break;
2314
2282
  case PLUGIN_VAR_BOOL:
2315
2283
    options->var_type= GET_BOOL;
2321
2289
    options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
2322
2290
    break;
2323
2291
  /* threadlocal variables */
2324
 
  case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
2325
 
    OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
2326
 
    break;
2327
 
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2328
 
    OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
2329
 
    break;
2330
 
  case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
2331
 
    OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
2332
 
    break;
2333
 
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2334
 
    OPTION_SET_LIMITS(GET_ULONG, options, (sessionvar_ulong_t*) opt);
2335
 
    break;
2336
 
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
2337
 
    OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
2338
 
    break;
2339
 
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2340
 
    OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
2341
 
    break;
2342
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
 
2292
  case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
 
2293
    OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
 
2294
    break;
 
2295
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
 
2296
    OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
 
2297
    break;
 
2298
  case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
 
2299
    OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
 
2300
    break;
 
2301
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
 
2302
    OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
 
2303
    break;
 
2304
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
 
2305
    OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
 
2306
    break;
 
2307
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
 
2308
    OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
 
2309
    break;
 
2310
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2343
2311
    options->var_type= GET_ENUM;
2344
 
    options->typelib= ((sessionvar_enum_t*) opt)->typelib;
2345
 
    options->def_value= ((sessionvar_enum_t*) opt)->def_val;
 
2312
    options->typelib= ((thdvar_enum_t*) opt)->typelib;
 
2313
    options->def_value= ((thdvar_enum_t*) opt)->def_val;
2346
2314
    options->min_value= options->block_size= 0;
2347
2315
    options->max_value= options->typelib->count - 1;
2348
2316
    break;
2349
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
 
2317
  case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
2350
2318
    options->var_type= GET_SET;
2351
 
    options->typelib= ((sessionvar_set_t*) opt)->typelib;
2352
 
    options->def_value= ((sessionvar_set_t*) opt)->def_val;
 
2319
    options->typelib= ((thdvar_set_t*) opt)->typelib;
 
2320
    options->def_value= ((thdvar_set_t*) opt)->def_val;
2353
2321
    options->min_value= options->block_size= 0;
2354
 
    options->max_value= (1UL << options->typelib->count) - 1;
 
2322
    options->max_value= (1ULL << options->typelib->count) - 1;
2355
2323
    break;
2356
 
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
 
2324
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
2357
2325
    options->var_type= GET_BOOL;
2358
 
    options->def_value= ((sessionvar_bool_t*) opt)->def_val;
 
2326
    options->def_value= ((thdvar_bool_t*) opt)->def_val;
2359
2327
    break;
2360
 
  case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
 
2328
  case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
2361
2329
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2362
2330
                        GET_STR_ALLOC : GET_STR);
2363
 
    options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
 
2331
    options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
2364
2332
    break;
2365
2333
  default:
2366
2334
    assert(0);
2387
2355
                             my_option *options, bool can_disable)
2388
2356
{
2389
2357
  const char *plugin_name= tmp->plugin->name;
2390
 
  uint32_t namelen= strlen(plugin_name), optnamelen;
2391
 
  uint32_t buffer_length= namelen * 4 + (can_disable ? 75 : 10);
 
2358
  uint namelen= strlen(plugin_name), optnamelen;
 
2359
  uint buffer_length= namelen * 4 + (can_disable ? 75 : 10);
2392
2360
  char *name= (char*) alloc_root(mem_root, buffer_length) + 1;
2393
2361
  char *optname, *p;
2394
2362
  int index= 0, offset= 0;
2398
2366
  /* support --skip-plugin-foo syntax */
2399
2367
  memcpy(name, plugin_name, namelen + 1);
2400
2368
  my_casedn_str(&my_charset_utf8_general_ci, name);
2401
 
  strxmov(name + namelen + 1, "plugin-", name, NULL);
 
2369
  strxmov(name + namelen + 1, "plugin-", name, NullS);
2402
2370
  /* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */
2403
2371
 
2404
2372
  for (p= name + namelen*2 + 8; p > name; p--)
2408
2376
  if (can_disable)
2409
2377
  {
2410
2378
    strxmov(name + namelen*2 + 10, "Enable ", plugin_name, " plugin. "
2411
 
            "Disable with --skip-", name," (will save memory).", NULL);
 
2379
            "Disable with --skip-", name," (will save memory).", NullS);
2412
2380
    /*
2413
2381
      Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 +
2414
2382
      20 + namelen + 20 + 1 == namelen * 4 + 67.
2435
2403
       plugin_option && *plugin_option; plugin_option++, index++)
2436
2404
  {
2437
2405
    opt= *plugin_option;
2438
 
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
 
2406
    if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
2439
2407
      continue;
2440
2408
    if (!(register_var(name, opt->name, opt->flags)))
2441
2409
      continue;
2442
2410
    switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2443
2411
    case PLUGIN_VAR_BOOL:
2444
 
      (((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
 
2412
      (((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2445
2413
      break;
2446
2414
    case PLUGIN_VAR_INT:
2447
 
      (((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
 
2415
      (((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2448
2416
      break;
2449
2417
    case PLUGIN_VAR_LONG:
2450
 
      (((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
 
2418
      (((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2451
2419
      break;
2452
2420
    case PLUGIN_VAR_LONGLONG:
2453
 
      (((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
 
2421
      (((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2454
2422
      break;
2455
2423
    case PLUGIN_VAR_STR:
2456
 
      (((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
 
2424
      (((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2457
2425
      break;
2458
2426
    case PLUGIN_VAR_ENUM:
2459
 
      (((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
 
2427
      (((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2460
2428
      break;
2461
2429
    case PLUGIN_VAR_SET:
2462
 
      (((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
 
2430
      (((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2463
2431
      break;
2464
2432
    default:
2465
2433
      sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
2530
2498
      return(-1);
2531
2499
    }
2532
2500
 
2533
 
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
 
2501
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_THDLOCAL))
2534
2502
                    == PLUGIN_VAR_NOCMDOPT)
2535
2503
      continue;
2536
2504
 
2541
2509
      return(-1);
2542
2510
    }
2543
2511
 
2544
 
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
 
2512
    if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
2545
2513
    {
2546
2514
      optnamelen= strlen(opt->name);
2547
2515
      optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
2548
 
      strxmov(optname, name, "-", opt->name, NULL);
 
2516
      strxmov(optname, name, "-", opt->name, NullS);
2549
2517
      optnamelen= namelen + optnamelen + 1;
2550
2518
    }
2551
2519
    else
2579
2547
 
2580
2548
    plugin_opt_set_limits(options, opt);
2581
2549
 
2582
 
    if (opt->flags & PLUGIN_VAR_SessionLOCAL)
 
2550
    if (opt->flags & PLUGIN_VAR_THDLOCAL)
2583
2551
      options->value= options->u_max_value= (char**)
2584
2552
        (global_system_variables.dynamic_variables_ptr + offset);
2585
2553
    else
2588
2556
    options[1]= options[0];
2589
2557
    options[1].name= p= (char*) alloc_root(mem_root, optnamelen + 8);
2590
2558
    options[1].comment= 0; // hidden
2591
 
    strxmov(p, "plugin-", optname, NULL);
 
2559
    strxmov(p, "plugin-", optname, NullS);
2592
2560
 
2593
2561
    options+= 2;
2594
2562
  }
2603
2571
  st_mysql_sys_var **opt;
2604
2572
  my_option *opts;
2605
2573
  bool can_disable;
2606
 
  uint32_t count= EXTRA_OPTIONS;
 
2574
  uint count= EXTRA_OPTIONS;
2607
2575
 
2608
2576
  for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2) {};
2609
2577
 
2655
2623
  st_mysql_sys_var *o;
2656
2624
  sys_var *v;
2657
2625
  struct st_bookmark *var;
2658
 
  uint32_t len, count= EXTRA_OPTIONS;
 
2626
  uint len, count= EXTRA_OPTIONS;
2659
2627
  assert(tmp->plugin && tmp->name.str);
2660
2628
 
2661
2629
  for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
2708
2676
      {
2709
2677
        len= tmp->name.length + strlen(o->name) + 2;
2710
2678
        varname= (char*) alloc_root(mem_root, len);
2711
 
        strxmov(varname, tmp->name.str, "-", o->name, NULL);
 
2679
        strxmov(varname, tmp->name.str, "-", o->name, NullS);
2712
2680
        my_casedn_str(&my_charset_utf8_general_ci, varname);
2713
2681
 
2714
2682
        for (p= varname; *p; p++)
2760
2728
}
2761
2729
 
2762
2730
 
2763
 
void my_print_help_inc_plugins(my_option *main_options, uint32_t size)
 
2731
void my_print_help_inc_plugins(my_option *main_options, uint size)
2764
2732
{
2765
2733
  DYNAMIC_ARRAY all_options;
2766
2734
  struct st_plugin_int *p;
2771
2739
  my_init_dynamic_array(&all_options, sizeof(my_option), size, size/4);
2772
2740
 
2773
2741
  if (initialized)
2774
 
    for (uint32_t idx= 0; idx < plugin_array.elements; idx++)
 
2742
    for (uint idx= 0; idx < plugin_array.elements; idx++)
2775
2743
    {
2776
2744
      p= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
2777
2745
 
2782
2750
      /* Only options with a non-NULL comment are displayed in help text */
2783
2751
      for (;opt->id; opt++)
2784
2752
        if (opt->comment)
2785
 
          insert_dynamic(&all_options, (unsigned char*) opt);
 
2753
          insert_dynamic(&all_options, (uchar*) opt);
2786
2754
    }
2787
2755
 
2788
2756
  for (;main_options->id; main_options++)
2789
 
    insert_dynamic(&all_options, (unsigned char*) main_options);
 
2757
    insert_dynamic(&all_options, (uchar*) main_options);
2790
2758
 
2791
2759
  sort_dynamic(&all_options, (qsort_cmp) option_cmp);
2792
2760
 
2793
2761
  /* main_options now points to the empty option terminator */
2794
 
  insert_dynamic(&all_options, (unsigned char*) main_options);
 
2762
  insert_dynamic(&all_options, (uchar*) main_options);
2795
2763
 
2796
2764
  my_print_help((my_option*) all_options.buffer);
2797
2765
  my_print_variables((my_option*) all_options.buffer);