325
329
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
327
char dlpath[FN_REFLEN];
328
uint32_t plugin_dir_len, dummy_errors, dlpathlen;
332
uint32_t plugin_dir_len, dummy_errors;
329
333
struct st_plugin_dl *tmp, plugin_dl;
331
335
plugin_dir_len= strlen(opt_plugin_dir);
336
dlpath.reserve(FN_REFLEN);
333
338
Ensure that the dll doesn't have a path.
334
339
This is done to ensure that only approved libraries from the
354
359
memset(&plugin_dl, 0, sizeof(plugin_dl));
355
360
/* Compile dll path */
357
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NULL) -
361
dlpath.append(opt_plugin_dir);
363
dlpath.append(dl->str);
359
364
plugin_dl.ref_count= 1;
360
365
/* Open new dll handle */
361
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_LAZY|RTLD_GLOBAL)))
366
if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
363
368
const char *errmsg=dlerror();
364
if (!strncmp(dlpath, errmsg, dlpathlen))
369
uint32_t dlpathlen= dlpath.length();
370
if (!dlpath.compare(0, dlpathlen, errmsg))
365
371
{ // if errmsg starts from dlpath, trim this prefix.
366
372
errmsg+=dlpathlen;
367
373
if (*errmsg == ':') errmsg++;
368
374
if (*errmsg == ' ') errmsg++;
370
376
if (report & REPORT_TO_USER)
371
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
377
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
372
378
if (report & REPORT_TO_LOG)
373
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
379
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);