Skip to content

Commit 6cddd12

Browse files
committed
make sql_udf.cc to shorten dlerror() messages
just as sql_plugin.cc does
1 parent 2b1bbac commit 6cddd12

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed

include/my_sys.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,8 @@ void my_uuid(uchar *guid);
998998
void my_uuid2str(const uchar *guid, char *s);
999999
void my_uuid_end(void);
10001000

1001+
const char *my_dlerror(const char *dlpath);
1002+
10011003
/* character sets */
10021004
extern void my_charset_loader_init_mysys(MY_CHARSET_LOADER *loader);
10031005
extern uint get_charset_number(const char *cs_name, uint cs_flags);

mysys/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c
4141
my_atomic.c my_getncpus.c my_safehash.c my_chmod.c my_rnd.c
4242
my_uuid.c wqueue.c waiting_threads.c ma_dyncol.c
4343
my_rdtsc.c my_context.c psi_noop.c
44-
file_logger.c)
44+
file_logger.c my_dlerror.c)
4545

4646
IF (WIN32)
4747
SET (MYSYS_SOURCES ${MYSYS_SOURCES} my_winthread.c my_wincond.c my_winerr.c my_winfile.c my_windac.c my_conio.c)

mysys/my_dlerror.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright (c) 2017, MariaDB
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16+
17+
#include <my_global.h>
18+
#include <string.h>
19+
20+
const char *my_dlerror(const char *dlpath)
21+
{
22+
const char *errmsg=dlerror();
23+
size_t dlpathlen= strlen(dlpath);
24+
if (!strncmp(dlpath, errmsg, dlpathlen))
25+
{ /* if errmsg starts from dlpath, trim this prefix */
26+
errmsg+=dlpathlen;
27+
if (*errmsg == ':') errmsg++;
28+
if (*errmsg == ' ') errmsg++;
29+
}
30+
return errmsg;
31+
}

sql/sql_plugin.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
723723
{
724724
#ifdef HAVE_DLOPEN
725725
char dlpath[FN_REFLEN];
726-
uint plugin_dir_len, dummy_errors, dlpathlen, i;
726+
uint plugin_dir_len, dummy_errors, i;
727727
struct st_plugin_dl *tmp= 0, plugin_dl;
728728
void *sym;
729729
st_ptr_backup tmp_backup[array_elements(list_of_services)];
@@ -759,15 +759,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
759759
/* Open new dll handle */
760760
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
761761
{
762-
const char *errmsg=dlerror();
763-
dlpathlen= strlen(dlpath);
764-
if (!strncmp(dlpath, errmsg, dlpathlen))
765-
{ // if errmsg starts from dlpath, trim this prefix.
766-
errmsg+=dlpathlen;
767-
if (*errmsg == ':') errmsg++;
768-
if (*errmsg == ' ') errmsg++;
769-
}
770-
report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, errno, errmsg);
762+
report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, errno, my_dlerror(dlpath));
771763
goto ret;
772764
}
773765
dlopen_count++;

sql/sql_udf.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,13 @@ void udf_init()
227227
if (dl == NULL)
228228
{
229229
char dlpath[FN_REFLEN];
230-
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", tmp->dl,
231-
NullS);
230+
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", tmp->dl, NullS);
232231
(void) unpack_filename(dlpath, dlpath);
233232
if (!(dl= dlopen(dlpath, RTLD_NOW)))
234233
{
235234
/* Print warning to log */
236235
sql_print_error(ER_THD(new_thd, ER_CANT_OPEN_LIBRARY),
237-
tmp->dl, errno, dlerror());
236+
tmp->dl, errno, my_dlerror(dlpath));
238237
/* Keep the udf in the hash so that we can remove it later */
239238
continue;
240239
}
@@ -538,10 +537,10 @@ int mysql_create_function(THD *thd,udf_func *udf)
538537

539538
if (!(dl = dlopen(dlpath, RTLD_NOW)))
540539
{
540+
my_error(ER_CANT_OPEN_LIBRARY, MYF(0),
541+
udf->dl, errno, my_dlerror(dlpath));
541542
DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)",
542543
udf->dl, errno, dlerror()));
543-
my_error(ER_CANT_OPEN_LIBRARY, MYF(0),
544-
udf->dl, errno, dlerror());
545544
goto err;
546545
}
547546
new_dl=1;

0 commit comments

Comments
 (0)