~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/loader.cc

Merged in global changes from plugin-dynamic-load.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
using namespace std;
47
47
using namespace drizzled;
48
48
 
49
 
static const int REPORT_TO_LOG= 1;
50
 
static const int REPORT_TO_USER= 2;
51
 
 
52
49
typedef plugin::Manifest builtin_plugin[];
53
50
extern builtin_plugin PANDORA_BUILTIN_LIST;
54
51
static plugin::Manifest *drizzled_builtins[]=
289
286
}
290
287
 
291
288
 
292
 
static plugin::Library *plugin_dl_add(const LEX_STRING *dl, int report)
 
289
static plugin::Library *plugin_dl_add(const LEX_STRING *dl)
293
290
{
294
291
  string dlpath;
295
292
  uint32_t plugin_dir_len;
307
304
                               system_charset_info, 1) ||
308
305
      plugin_dir_len + dl->length + 1 >= FN_REFLEN)
309
306
  {
310
 
    if (report & REPORT_TO_USER)
311
 
      my_error(ER_UDF_NO_PATHS, MYF(0));
312
 
    if (report & REPORT_TO_LOG)
313
 
      errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_UDF_NO_PATHS));
314
 
    return(0);
 
307
    errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_UDF_NO_PATHS));
 
308
    return NULL;
315
309
  }
316
310
  /* If this dll is already loaded just increase ref_count. */
317
311
  if ((tmp= plugin_dl_find(dl)))
336
330
      if (*errmsg == ':') errmsg++;
337
331
      if (*errmsg == ' ') errmsg++;
338
332
    }
339
 
    if (report & REPORT_TO_USER)
340
 
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
341
 
    if (report & REPORT_TO_LOG)
342
 
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
343
 
    return(0);
 
333
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
 
334
    return NULL;
344
335
  }
345
336
 
346
337
  /* Find plugin declarations */
347
338
  if (!(sym= dlsym(plugin_dl.handle, plugin_declarations_sym)))
348
339
  {
349
340
    free_plugin_mem(&plugin_dl);
350
 
    if (report & REPORT_TO_USER)
351
 
      my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_declarations_sym);
352
 
    if (report & REPORT_TO_LOG)
353
 
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), plugin_declarations_sym);
354
 
    return(0);
 
341
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), plugin_declarations_sym);
 
342
    return NULL;
355
343
  }
356
344
 
357
345
  plugin_dl.plugins= static_cast<plugin::Manifest *>(sym);
361
349
  if (! (plugin_dl.dl.str= (char*) calloc(plugin_dl.dl.length, sizeof(char))))
362
350
  {
363
351
    free_plugin_mem(&plugin_dl);
364
 
    if (report & REPORT_TO_USER)
365
 
      my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
366
 
    if (report & REPORT_TO_LOG)
367
 
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
368
 
    return(0);
 
352
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
 
353
    return NULL;
369
354
  }
370
355
  strcpy(plugin_dl.dl.str, dl->str);
371
356
  /* Add this dll to array */
372
357
  if (! (tmp= plugin_dl_insert_or_reuse(&plugin_dl)))
373
358
  {
374
359
    free_plugin_mem(&plugin_dl);
375
 
    if (report & REPORT_TO_USER)
376
 
      my_error(ER_OUTOFMEMORY, MYF(0), sizeof(plugin::Library));
377
 
    if (report & REPORT_TO_LOG)
378
 
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY),
379
 
                    sizeof(plugin::Library));
380
 
    return(0);
 
360
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY),
 
361
                  sizeof(plugin::Library));
 
362
    return NULL;
381
363
  }
382
364
  return(tmp);
383
365
}
424
406
*/
425
407
static bool plugin_add(plugin::Registry &registry, MEM_ROOT *tmp_root,
426
408
                       const LEX_STRING *name, const LEX_STRING *dl,
427
 
                       int *argc, char **argv, int report)
 
409
                       int *argc, char **argv)
428
410
{
429
411
  plugin::Manifest *manifest;
430
412
  if (! initialized)
432
414
 
433
415
  if (registry.find(name))
434
416
  {
435
 
    if (report & REPORT_TO_USER)
436
 
      my_error(ER_UDF_EXISTS, MYF(0), name->str);
437
 
    if (report & REPORT_TO_LOG)
438
 
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UDF_EXISTS), name->str);
 
417
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UDF_EXISTS), name->str);
439
418
    return(true);
440
419
  }
441
 
  plugin::Library *library= plugin_dl_add(dl, report);
 
420
  plugin::Library *library= plugin_dl_add(dl);
442
421
  if (library == NULL)
443
422
    return true;
444
423
 
471
450
      return(false);
472
451
    }
473
452
  }
474
 
  if (report & REPORT_TO_USER)
475
 
    my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), name->str);
476
 
  if (report & REPORT_TO_LOG)
477
 
    errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), name->str);
 
453
  errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY), name->str);
478
454
err:
479
455
  plugin_dl_del(dl);
480
456
  return(true);
753
729
        }
754
730
 
755
731
        dl= name;
756
 
        if ((plugin_dl= plugin_dl_add(&dl, REPORT_TO_LOG)))
 
732
        if ((plugin_dl= plugin_dl_add(&dl)))
757
733
        {
758
734
          for (plugin= plugin_dl->plugins; plugin->name; plugin++)
759
735
          {
761
737
            name.length= strlen(name.str);
762
738
 
763
739
            free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
764
 
            if (plugin_add(plugins, tmp_root, &name, &dl,
765
 
                           argc, argv, REPORT_TO_LOG))
 
740
            if (plugin_add(plugins, tmp_root, &name, &dl, argc, argv))
766
741
              goto error;
767
742
          }
768
743
          plugin_dl_del(&dl); // reduce ref count
771
746
      else
772
747
      {
773
748
        free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
774
 
        if (plugin_add(plugins, tmp_root, &name, &dl,
775
 
                       argc, argv, REPORT_TO_LOG))
 
749
        if (plugin_add(plugins, tmp_root, &name, &dl, argc, argv))
776
750
          goto error;
777
751
      }
778
752
      name.length= dl.length= 0;