~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_plugin.cc

MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
275
275
{
276
276
  uint i;
277
277
  struct st_plugin_dl *tmp;
278
 
  DBUG_ENTER("plugin_dl_find");
279
278
  for (i= 0; i < plugin_dl_array.elements; i++)
280
279
  {
281
280
    tmp= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
283
282
        ! my_strnncoll(files_charset_info,
284
283
                       (const uchar *)dl->str, dl->length,
285
284
                       (const uchar *)tmp->dl.str, tmp->dl.length))
286
 
      DBUG_RETURN(tmp);
 
285
      return(tmp);
287
286
  }
288
 
  DBUG_RETURN(0);
 
287
  return(0);
289
288
}
290
289
 
291
290
 
293
292
{
294
293
  uint i;
295
294
  struct st_plugin_dl *tmp;
296
 
  DBUG_ENTER("plugin_dl_insert_or_reuse");
297
295
  for (i= 0; i < plugin_dl_array.elements; i++)
298
296
  {
299
297
    tmp= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
300
298
    if (! tmp->ref_count)
301
299
    {
302
300
      memcpy(tmp, plugin_dl, sizeof(struct st_plugin_dl));
303
 
      DBUG_RETURN(tmp);
 
301
      return(tmp);
304
302
    }
305
303
  }
306
304
  if (insert_dynamic(&plugin_dl_array, (uchar*)&plugin_dl))
307
 
    DBUG_RETURN(0);
 
305
    return(0);
308
306
  tmp= *dynamic_element(&plugin_dl_array, plugin_dl_array.elements - 1,
309
307
                        struct st_plugin_dl **)=
310
308
      (struct st_plugin_dl *) memdup_root(&plugin_mem_root, (uchar*)plugin_dl,
311
309
                                           sizeof(struct st_plugin_dl));
312
 
  DBUG_RETURN(tmp);
 
310
  return(tmp);
313
311
}
314
312
#endif /* HAVE_DLOPEN */
315
313
 
333
331
  uint plugin_dir_len, dummy_errors, dlpathlen;
334
332
  struct st_plugin_dl *tmp, plugin_dl;
335
333
  void *sym;
336
 
  DBUG_ENTER("plugin_dl_add");
337
334
  plugin_dir_len= strlen(opt_plugin_dir);
338
335
  /*
339
336
    Ensure that the dll doesn't have a path.
349
346
      my_error(ER_UDF_NO_PATHS, MYF(0));
350
347
    if (report & REPORT_TO_LOG)
351
348
      sql_print_error(ER(ER_UDF_NO_PATHS));
352
 
    DBUG_RETURN(0);
 
349
    return(0);
353
350
  }
354
351
  /* If this dll is already loaded just increase ref_count. */
355
352
  if ((tmp= plugin_dl_find(dl)))
356
353
  {
357
354
    tmp->ref_count++;
358
 
    DBUG_RETURN(tmp);
 
355
    return(tmp);
359
356
  }
360
357
  bzero(&plugin_dl, sizeof(plugin_dl));
361
358
  /* Compile dll path */
377
374
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
378
375
    if (report & REPORT_TO_LOG)
379
376
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
380
 
    DBUG_RETURN(0);
 
377
    return(0);
381
378
  }
382
379
  /* Determine interface version */
383
380
  if (!(sym= dlsym(plugin_dl.handle, plugin_interface_version_sym)))
387
384
      my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_interface_version_sym);
388
385
    if (report & REPORT_TO_LOG)
389
386
      sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), plugin_interface_version_sym);
390
 
    DBUG_RETURN(0);
 
387
    return(0);
391
388
  }
392
389
  plugin_dl.version= *(int *)sym;
393
390
  /* Versioning */
401
398
    if (report & REPORT_TO_LOG)
402
399
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, 0,
403
400
                      "plugin interface version mismatch");
404
 
    DBUG_RETURN(0);
 
401
    return(0);
405
402
  }
406
403
  /* Find plugin declarations */
407
404
  if (!(sym= dlsym(plugin_dl.handle, plugin_declarations_sym)))
411
408
      my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_declarations_sym);
412
409
    if (report & REPORT_TO_LOG)
413
410
      sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), plugin_declarations_sym);
414
 
    DBUG_RETURN(0);
 
411
    return(0);
415
412
  }
416
413
 
417
414
  if (plugin_dl.version != MYSQL_PLUGIN_INTERFACE_VERSION)
431
428
        my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), sizeof_st_plugin_sym);
432
429
      if (report & REPORT_TO_LOG)
433
430
        sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), sizeof_st_plugin_sym);
434
 
      DBUG_RETURN(0);
 
431
      return(0);
435
432
#else
436
433
      /*
437
434
        When the following assert starts failing, we'll have to switch
456
453
        my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
457
454
      if (report & REPORT_TO_LOG)
458
455
        sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
459
 
      DBUG_RETURN(0);
 
456
      return(0);
460
457
    }
461
458
    /*
462
459
      All st_plugin fields not initialized in the plugin explicitly, are
481
478
      my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
482
479
    if (report & REPORT_TO_LOG)
483
480
      sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
484
 
    DBUG_RETURN(0);
 
481
    return(0);
485
482
  }
486
483
  plugin_dl.dl.length= copy_and_convert(plugin_dl.dl.str, plugin_dl.dl.length,
487
484
    files_charset_info, dl->str, dl->length, system_charset_info,
495
492
      my_error(ER_OUTOFMEMORY, MYF(0), sizeof(struct st_plugin_dl));
496
493
    if (report & REPORT_TO_LOG)
497
494
      sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_dl));
498
 
    DBUG_RETURN(0);
 
495
    return(0);
499
496
  }
500
 
  DBUG_RETURN(tmp);
 
497
  return(tmp);
501
498
#else
502
 
  DBUG_ENTER("plugin_dl_add");
503
499
  if (report & REPORT_TO_USER)
504
500
    my_error(ER_FEATURE_DISABLED, MYF(0), "plugin", "HAVE_DLOPEN");
505
501
  if (report & REPORT_TO_LOG)
506
502
    sql_print_error(ER(ER_FEATURE_DISABLED), "plugin", "HAVE_DLOPEN");
507
 
  DBUG_RETURN(0);
 
503
  return(0);
508
504
#endif
509
505
}
510
506
 
513
509
{
514
510
#ifdef HAVE_DLOPEN
515
511
  uint i;
516
 
  DBUG_ENTER("plugin_dl_del");
517
512
 
518
513
  for (i= 0; i < plugin_dl_array.elements; i++)
519
514
  {
533
528
      break;
534
529
    }
535
530
  }
536
 
  DBUG_VOID_RETURN;
 
531
  return;
537
532
#endif
538
533
}
539
534
 
541
536
static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int type)
542
537
{
543
538
  uint i;
544
 
  DBUG_ENTER("plugin_find_internal");
545
539
  if (! initialized)
546
 
    DBUG_RETURN(0);
 
540
    return(0);
547
541
 
548
542
  if (type == MYSQL_ANY_PLUGIN)
549
543
  {
552
546
      struct st_plugin_int *plugin= (st_plugin_int *)
553
547
        hash_search(&plugin_hash[i], (const uchar *)name->str, name->length);
554
548
      if (plugin)
555
 
        DBUG_RETURN(plugin);
 
549
        return(plugin);
556
550
    }
557
551
  }
558
552
  else
559
 
    DBUG_RETURN((st_plugin_int *)
 
553
    return((st_plugin_int *)
560
554
        hash_search(&plugin_hash[type], (const uchar *)name->str, name->length));
561
 
  DBUG_RETURN(0);
 
555
  return(0);
562
556
}
563
557
 
564
558
 
566
560
{
567
561
  SHOW_COMP_OPTION rc= SHOW_OPTION_NO;
568
562
  struct st_plugin_int *plugin;
569
 
  DBUG_ENTER("plugin_is_ready");
570
563
  if ((plugin= plugin_find_internal(name, type)))
571
564
  {
572
565
    rc= SHOW_OPTION_DISABLED;
573
566
    if (plugin->state == PLUGIN_IS_READY)
574
567
      rc= SHOW_OPTION_YES;
575
568
  }
576
 
  DBUG_RETURN(rc);
 
569
  return(rc);
577
570
}
578
571
 
579
572
 
596
589
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc CALLER_INFO_PROTO)
597
590
{
598
591
  st_plugin_int *pi= plugin_ref_to_int(rc);
599
 
  DBUG_ENTER("intern_plugin_lock");
600
592
 
601
593
  if (pi->state & (PLUGIN_IS_READY | PLUGIN_IS_UNINITIALIZED))
602
594
  {
604
596
#ifdef DBUG_OFF
605
597
    /* built-in plugins don't need ref counting */
606
598
    if (!pi->plugin_dl)
607
 
      DBUG_RETURN(pi);
 
599
      return(pi);
608
600
 
609
601
    plugin= pi;
610
602
#else
614
606
      double unlocks to aid resolving reference counting.problems.
615
607
    */
616
608
    if (!(plugin= (plugin_ref) my_malloc_ci(sizeof(pi), MYF(MY_WME))))
617
 
      DBUG_RETURN(NULL);
 
609
      return(NULL);
618
610
 
619
611
    *plugin= pi;
620
612
#endif
621
613
    pi->ref_count++;
622
 
    DBUG_PRINT("info",("thd: 0x%lx, plugin: \"%s\", ref_count: %d",
623
 
                       (long) current_thd, pi->name.str, pi->ref_count));
624
614
 
625
615
    if (lex)
626
616
      insert_dynamic(&lex->plugins, (uchar*)&plugin);
627
 
    DBUG_RETURN(plugin);
 
617
    return(plugin);
628
618
  }
629
 
  DBUG_RETURN(NULL);
 
619
  return(NULL);
630
620
}
631
621
 
632
622
 
634
624
{
635
625
  LEX *lex= thd ? thd->lex : 0;
636
626
  plugin_ref rc;
637
 
  DBUG_ENTER("plugin_lock");
638
627
  rc= my_intern_plugin_lock_ci(lex, *ptr);
639
 
  DBUG_RETURN(rc);
 
628
  return(rc);
640
629
}
641
630
 
642
631
 
646
635
  LEX *lex= thd ? thd->lex : 0;
647
636
  plugin_ref rc= NULL;
648
637
  st_plugin_int *plugin;
649
 
  DBUG_ENTER("plugin_lock_by_name");
650
638
  if ((plugin= plugin_find_internal(name, type)))
651
639
    rc= my_intern_plugin_lock_ci(lex, plugin_int_to_ref(plugin));
652
 
  DBUG_RETURN(rc);
 
640
  return(rc);
653
641
}
654
642
 
655
643
 
657
645
{
658
646
  uint i;
659
647
  struct st_plugin_int *tmp;
660
 
  DBUG_ENTER("plugin_insert_or_reuse");
661
648
  for (i= 0; i < plugin_array.elements; i++)
662
649
  {
663
650
    tmp= *dynamic_element(&plugin_array, i, struct st_plugin_int **);
664
651
    if (tmp->state == PLUGIN_IS_FREED)
665
652
    {
666
653
      memcpy(tmp, plugin, sizeof(struct st_plugin_int));
667
 
      DBUG_RETURN(tmp);
 
654
      return(tmp);
668
655
    }
669
656
  }
670
657
  if (insert_dynamic(&plugin_array, (uchar*)&plugin))
671
 
    DBUG_RETURN(0);
 
658
    return(0);
672
659
  tmp= *dynamic_element(&plugin_array, plugin_array.elements - 1,
673
660
                        struct st_plugin_int **)=
674
661
       (struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)plugin,
675
662
                                            sizeof(struct st_plugin_int));
676
 
  DBUG_RETURN(tmp);
 
663
  return(tmp);
677
664
}
678
665
 
679
666
 
687
674
{
688
675
  struct st_plugin_int tmp;
689
676
  struct st_mysql_plugin *plugin;
690
 
  DBUG_ENTER("plugin_add");
691
677
  if (plugin_find_internal(name, MYSQL_ANY_PLUGIN))
692
678
  {
693
679
    if (report & REPORT_TO_USER)
694
680
      my_error(ER_UDF_EXISTS, MYF(0), name->str);
695
681
    if (report & REPORT_TO_LOG)
696
682
      sql_print_error(ER(ER_UDF_EXISTS), name->str);
697
 
    DBUG_RETURN(TRUE);
 
683
    return(TRUE);
698
684
  }
699
685
  /* Clear the whole struct to catch future extensions. */
700
686
  bzero((char*) &tmp, sizeof(tmp));
701
687
  if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
702
 
    DBUG_RETURN(TRUE);
 
688
    return(TRUE);
703
689
  /* Find plugin by name */
704
690
  for (plugin= tmp.plugin_dl->plugins; plugin->info; plugin++)
705
691
  {
739
725
          if (!my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr))
740
726
          {
741
727
            init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
742
 
            DBUG_RETURN(FALSE);
 
728
            return(FALSE);
743
729
          }
744
730
          tmp_plugin_ptr->state= PLUGIN_IS_FREED;
745
731
        }
748
734
      }
749
735
      /* plugin was disabled */
750
736
      plugin_dl_del(dl);
751
 
      DBUG_RETURN(FALSE);
 
737
      return(FALSE);
752
738
    }
753
739
  }
754
740
  if (report & REPORT_TO_USER)
757
743
    sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), name->str);
758
744
err:
759
745
  plugin_dl_del(dl);
760
 
  DBUG_RETURN(TRUE);
 
746
  return(TRUE);
761
747
}
762
748
 
763
749
 
792
778
    }
793
779
  }
794
780
  else if (plugin->plugin->deinit)
795
 
  {
796
 
    DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
797
 
    if (plugin->plugin->deinit(plugin))
798
 
    {
799
 
      DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
800
 
                             plugin->name.str));
801
 
    }
802
 
  }
 
781
    plugin->plugin->deinit(plugin);
 
782
 
803
783
  plugin->state= PLUGIN_IS_UNINITIALIZED;
804
784
 
805
785
  /*
814
794
 
815
795
static void plugin_del(struct st_plugin_int *plugin)
816
796
{
817
 
  DBUG_ENTER("plugin_del(plugin)");
818
797
  /* Free allocated strings before deleting the plugin. */
819
798
  plugin_vars_free_values(plugin->system_vars);
820
799
  hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
826
805
  mysql_del_sys_var_chain(plugin->system_vars);
827
806
  rw_unlock(&LOCK_system_variables_hash);
828
807
  free_root(&plugin->mem_root, MYF(0));
829
 
  DBUG_VOID_RETURN;
 
808
  return;
830
809
}
831
810
 
832
811
#ifdef NOT_USED
834
813
static void plugin_del(const LEX_STRING *name)
835
814
{
836
815
  struct st_plugin_int *plugin;
837
 
  DBUG_ENTER("plugin_del(name)");
838
816
  if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
839
817
    plugin_del(plugin);
840
 
  DBUG_VOID_RETURN;
 
818
  return;
841
819
}
842
820
 
843
821
#endif
880
858
{
881
859
  int i;
882
860
  st_plugin_int *pi;
883
 
  DBUG_ENTER("intern_plugin_unlock");
884
861
 
885
862
  if (!plugin)
886
 
    DBUG_VOID_RETURN;
 
863
    return;
887
864
 
888
865
  pi= plugin_ref_to_int(plugin);
889
866
 
890
867
#ifdef DBUG_OFF
891
868
  if (!pi->plugin_dl)
892
 
    DBUG_VOID_RETURN;
 
869
    return;
893
870
#else
894
871
  my_free((uchar*) plugin, MYF(MY_WME));
895
872
#endif
896
873
 
897
 
  DBUG_PRINT("info",("unlocking plugin, name= %s, ref_count= %d",
898
 
                     pi->name.str, pi->ref_count));
899
874
  if (lex)
900
875
  {
901
876
    /*
918
893
  if (pi->state == PLUGIN_IS_DELETED && !pi->ref_count)
919
894
    reap_needed= true;
920
895
 
921
 
  DBUG_VOID_RETURN;
 
896
  return;
922
897
}
923
898
 
924
899
 
925
900
void plugin_unlock(THD *thd, plugin_ref plugin)
926
901
{
927
902
  LEX *lex= thd ? thd->lex : 0;
928
 
  DBUG_ENTER("plugin_unlock");
929
903
  if (!plugin)
930
 
    DBUG_VOID_RETURN;
 
904
    return;
931
905
  intern_plugin_unlock(lex, plugin);
932
906
  reap_plugins();
933
 
  DBUG_VOID_RETURN;
 
907
  return;
934
908
}
935
909
 
936
910
 
937
911
void plugin_unlock_list(THD *thd, plugin_ref *list, uint count)
938
912
{
939
913
  LEX *lex= thd ? thd->lex : 0;
940
 
  DBUG_ENTER("plugin_unlock_list");
941
914
  DBUG_ASSERT(list);
942
915
  while (count--)
943
916
    intern_plugin_unlock(lex, *list++);
944
917
  reap_plugins();
945
 
  DBUG_VOID_RETURN;
 
918
  return;
946
919
}
947
920
 
948
921
 
949
922
static int plugin_initialize(struct st_plugin_int *plugin)
950
923
{
951
 
  DBUG_ENTER("plugin_initialize");
952
924
 
953
925
  if (plugin_type_initialize[plugin->plugin->type])
954
926
  {
1008
980
    }
1009
981
  }
1010
982
 
1011
 
  DBUG_RETURN(0);
 
983
  return(0);
1012
984
err:
1013
 
  DBUG_RETURN(1);
 
985
  return(1);
1014
986
}
1015
987
 
1016
988
 
1051
1023
  struct st_mysql_plugin *plugin;
1052
1024
  struct st_plugin_int tmp, *plugin_ptr, **reap;
1053
1025
  MEM_ROOT tmp_root;
1054
 
  DBUG_ENTER("plugin_init");
1055
1026
 
1056
1027
  if (initialized)
1057
 
    DBUG_RETURN(0);
 
1028
    return(0);
1058
1029
 
1059
1030
  init_alloc_root(&plugin_mem_root, 4096, 4096);
1060
1031
  init_alloc_root(&tmp_root, 4096, 4096);
1171
1142
end:
1172
1143
  free_root(&tmp_root, MYF(0));
1173
1144
 
1174
 
  DBUG_RETURN(0);
 
1145
  return(0);
1175
1146
 
1176
1147
err_unlock:
1177
1148
err:
1178
1149
  free_root(&tmp_root, MYF(0));
1179
 
  DBUG_RETURN(1);
 
1150
  return(1);
1180
1151
}
1181
1152
 
1182
1153
 
1184
1155
                             struct st_plugin_int *tmp,
1185
1156
                             struct st_plugin_int **ptr)
1186
1157
{
1187
 
  DBUG_ENTER("register_builtin");
1188
1158
 
1189
1159
  tmp->state= PLUGIN_IS_UNINITIALIZED;
1190
1160
  tmp->ref_count= 0;
1191
1161
  tmp->plugin_dl= 0;
1192
1162
 
1193
1163
  if (insert_dynamic(&plugin_array, (uchar*)&tmp))
1194
 
    DBUG_RETURN(1);
 
1164
    return(1);
1195
1165
 
1196
1166
  *ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
1197
1167
                         struct st_plugin_int **)=
1199
1169
                                             sizeof(struct st_plugin_int));
1200
1170
 
1201
1171
  if (my_hash_insert(&plugin_hash[plugin->type],(uchar*) *ptr))
1202
 
    DBUG_RETURN(1);
 
1172
    return(1);
1203
1173
 
1204
 
  DBUG_RETURN(0);
 
1174
  return(0);
1205
1175
}
1206
1176
 
1207
1177
 
1223
1193
  struct st_plugin_int tmp, *ptr;
1224
1194
  bool result= true;
1225
1195
  int dummy_argc= 0;
1226
 
  DBUG_ENTER("plugin_register_builtin");
1227
1196
 
1228
1197
  bzero(&tmp, sizeof(tmp));
1229
1198
  tmp.plugin= plugin;
1241
1210
end:
1242
1211
  rw_unlock(&LOCK_system_variables_hash);
1243
1212
 
1244
 
  DBUG_RETURN(result);;
 
1213
  return(result);;
1245
1214
}
1246
1215
#endif /* NOT_USED_YET */
1247
1216
 
1257
1226
  struct st_plugin_dl *plugin_dl;
1258
1227
  struct st_mysql_plugin *plugin;
1259
1228
  char *p= buffer;
1260
 
  DBUG_ENTER("plugin_load_list");
1261
1229
  while (list)
1262
1230
  {
1263
1231
    if (p == buffer + sizeof(buffer) - 1)
1264
1232
    {
1265
1233
      sql_print_error("plugin-load parameter too long");
1266
 
      DBUG_RETURN(TRUE);
 
1234
      return(TRUE);
1267
1235
    }
1268
1236
 
1269
1237
    switch ((*(p++)= *(list++))) {
1320
1288
      continue;
1321
1289
    }
1322
1290
  }
1323
 
  DBUG_RETURN(FALSE);
 
1291
  return(FALSE);
1324
1292
error:
1325
1293
  sql_print_error("Couldn't load plugin named '%s' with soname '%s'.",
1326
1294
                  name.str, dl.str);
1327
 
  DBUG_RETURN(TRUE);
 
1295
  return(TRUE);
1328
1296
}
1329
1297
 
1330
1298
 
1333
1301
  uint i, count= plugin_array.elements, free_slots= 0;
1334
1302
  struct st_plugin_int **plugins, *plugin;
1335
1303
  struct st_plugin_dl **dl;
1336
 
  DBUG_ENTER("plugin_shutdown");
1337
1304
 
1338
1305
  if (initialized)
1339
1306
  {
1449
1416
 
1450
1417
  global_variables_dynamic_size= 0;
1451
1418
 
1452
 
  DBUG_VOID_RETURN;
 
1419
  return;
1453
1420
}
1454
1421
 
1455
1422
 
1459
1426
  uint idx, total;
1460
1427
  struct st_plugin_int *plugin, **plugins;
1461
1428
  int version=plugin_array_version;
1462
 
  DBUG_ENTER("plugin_foreach_with_mask");
1463
1429
 
1464
1430
  if (!initialized)
1465
 
    DBUG_RETURN(FALSE);
 
1431
    return(FALSE);
1466
1432
 
1467
1433
  state_mask= ~state_mask; // do it only once
1468
1434
 
1505
1471
  }
1506
1472
 
1507
1473
  my_afree(plugins);
1508
 
  DBUG_RETURN(FALSE);
 
1474
  return(FALSE);
1509
1475
err:
1510
1476
  my_afree(plugins);
1511
 
  DBUG_RETURN(TRUE);
 
1477
  return(TRUE);
1512
1478
}
1513
1479
 
1514
1480
 
1815
1781
  sys_var *var;
1816
1782
  sys_var_pluginvar *pi= NULL;
1817
1783
  plugin_ref plugin;
1818
 
  DBUG_ENTER("find_sys_var");
1819
1784
 
1820
1785
  rw_rdlock(&LOCK_system_variables_hash);
1821
1786
  if ((var= intern_find_sys_var(str, length, false)) &&
1842
1807
  */
1843
1808
  if (pi && !var)
1844
1809
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
1845
 
  DBUG_RETURN(var);
 
1810
  return(var);
1846
1811
}
1847
1812
 
1848
1813
 
2085
2050
void plugin_thdvar_init(THD *thd)
2086
2051
{
2087
2052
  plugin_ref old_table_plugin= thd->variables.table_plugin;
2088
 
  DBUG_ENTER("plugin_thdvar_init");
2089
2053
  
2090
2054
  thd->variables.table_plugin= NULL;
2091
2055
  cleanup_variables(thd, &thd->variables);
2101
2065
  thd->variables.table_plugin=
2102
2066
        my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
2103
2067
  intern_plugin_unlock(NULL, old_table_plugin);
2104
 
  DBUG_VOID_RETURN;
 
2068
  return;
2105
2069
}
2106
2070
 
2107
2071
 
2164
2128
{
2165
2129
  uint idx;
2166
2130
  plugin_ref *list;
2167
 
  DBUG_ENTER("plugin_thdvar_cleanup");
2168
2131
 
2169
2132
  unlock_variables(thd, &thd->variables);
2170
2133
  cleanup_variables(thd, &thd->variables);
2172
2135
  if ((idx= thd->lex->plugins.elements))
2173
2136
  {
2174
2137
    list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
2175
 
    DBUG_PRINT("info",("unlocking %d plugins", idx));
2176
2138
    while ((uchar*) list >= thd->lex->plugins.buffer)
2177
2139
      intern_plugin_unlock(NULL, *list--);
2178
2140
  }
2181
2143
 
2182
2144
  reset_dynamic(&thd->lex->plugins);
2183
2145
 
2184
 
  DBUG_VOID_RETURN;
 
2146
  return;
2185
2147
}
2186
2148
 
2187
2149
 
2198
2160
 
2199
2161
static void plugin_vars_free_values(sys_var *vars)
2200
2162
{
2201
 
  DBUG_ENTER("plugin_vars_free_values");
2202
2163
 
2203
2164
  for (sys_var *var= vars; var; var= var->next)
2204
2165
  {
2209
2170
    {
2210
2171
      /* Free the string from global_system_variables. */
2211
2172
      char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
2212
 
      DBUG_PRINT("plugin", ("freeing value for: '%s'  addr: 0x%lx",
2213
 
                            var->name, (long) valptr));
2214
2173
      my_free(*valptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
2215
2174
      *valptr= NULL;
2216
2175
    }
2217
2176
  }
2218
 
  DBUG_VOID_RETURN;
 
2177
  return;
2219
2178
}
2220
2179
 
2221
2180
 
2567
2526
  int index= 0, offset= 0;
2568
2527
  st_mysql_sys_var *opt, **plugin_option;
2569
2528
  st_bookmark *v;
2570
 
  DBUG_ENTER("construct_options");
2571
 
  DBUG_PRINT("plugin", ("plugin: '%s'  enabled: %d  can_disable: %d",
2572
 
                        plugin_name, **enabled, can_disable));
2573
2529
 
2574
2530
  /* support --skip-plugin-foo syntax */
2575
2531
  memcpy(name, plugin_name, namelen + 1);
2648
2604
    default:
2649
2605
      sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
2650
2606
                      opt->flags, plugin_name);
2651
 
      DBUG_RETURN(-1);
 
2607
      return(-1);
2652
2608
    };
2653
2609
  }
2654
2610
 
2711
2667
    default:
2712
2668
      sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
2713
2669
                      opt->flags, plugin_name);
2714
 
      DBUG_RETURN(-1);
 
2670
      return(-1);
2715
2671
    }
2716
2672
 
2717
2673
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_THDLOCAL))
2722
2678
    {
2723
2679
      sql_print_error("Missing variable name in plugin '%s'.",
2724
2680
                      plugin_name);
2725
 
      DBUG_RETURN(-1);
 
2681
      return(-1);
2726
2682
    }
2727
2683
 
2728
2684
    if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
2739
2695
      {
2740
2696
        sql_print_error("Thread local variable '%s' not allocated "
2741
2697
                        "in plugin '%s'.", opt->name, plugin_name);
2742
 
        DBUG_RETURN(-1);
 
2698
        return(-1);
2743
2699
      }
2744
2700
 
2745
2701
      *(int*)(opt + 1)= offset= v->offset;
2777
2733
    options+= 2;
2778
2734
  }
2779
2735
 
2780
 
  DBUG_RETURN(0);
 
2736
  return(0);
2781
2737
}
2782
2738
 
2783
2739
 
2789
2745
  my_bool dummy, can_disable;
2790
2746
  my_bool *dummy2= &dummy;
2791
2747
  uint count= EXTRA_OPTIONS;
2792
 
  DBUG_ENTER("construct_help_options");
2793
2748
 
2794
2749
  for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2) {};
2795
2750
 
2796
2751
  if (!(opts= (my_option*) alloc_root(mem_root, sizeof(my_option) * count)))
2797
 
    DBUG_RETURN(NULL);
 
2752
    return(NULL);
2798
2753
 
2799
2754
  bzero(opts, sizeof(my_option) * count);
2800
2755
 
2805
2760
      my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY");
2806
2761
 
2807
2762
  if (construct_options(mem_root, p, opts, &dummy2, can_disable))
2808
 
    DBUG_RETURN(NULL);
 
2763
    return(NULL);
2809
2764
 
2810
 
  DBUG_RETURN(opts);
 
2765
  return(opts);
2811
2766
}
2812
2767
 
2813
2768
 
2840
2795
  sys_var *v;
2841
2796
  struct st_bookmark *var;
2842
2797
  uint len, count= EXTRA_OPTIONS;
2843
 
  DBUG_ENTER("test_plugin_options");
2844
2798
  DBUG_ASSERT(tmp->plugin && tmp->name.str);
2845
2799
 
2846
2800
  for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
2855
2809
    if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
2856
2810
    {
2857
2811
      sql_print_error("Out of memory for plugin '%s'.", tmp->name.str);
2858
 
      DBUG_RETURN(-1);
 
2812
      return(-1);
2859
2813
    }
2860
2814
    bzero(opts, sizeof(my_option) * count);
2861
2815
 
2862
2816
    if (construct_options(tmp_root, tmp, opts, &enabled, can_disable))
2863
2817
    {
2864
2818
      sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
2865
 
      DBUG_RETURN(-1);
 
2819
      return(-1);
2866
2820
    }
2867
2821
 
2868
2822
    error= handle_options(argc, &argv, opts, get_one_plugin_option);
2926
2880
      }
2927
2881
      tmp->system_vars= chain.first;
2928
2882
    }
2929
 
    DBUG_RETURN(0);
 
2883
    return(0);
2930
2884
  }
2931
2885
 
2932
2886
  if (enabled_saved && global_system_variables.log_warnings)
2935
2889
err:
2936
2890
  if (opts)
2937
2891
    my_cleanup_options(opts);
2938
 
  DBUG_RETURN(error);
 
2892
  return(error);
2939
2893
}
2940
2894
 
2941
2895