summaryrefslogtreecommitdiff
path: root/sql/sql_plugin.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_plugin.cc')
-rw-r--r--sql/sql_plugin.cc127
1 files changed, 57 insertions, 70 deletions
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 605f96293d3..ac1524381c7 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2005, 2013, Oracle and/or its affiliates.
- Copyright (c) 2010, 2017, MariaDB Corporation.
+ Copyright (c) 2005, 2018, Oracle and/or its affiliates.
+ Copyright (c) 2010, 2018, MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,9 +40,6 @@
#include <mysql/plugin_encryption.h>
#include "sql_plugin_compat.h"
-#define REPORT_TO_LOG 1
-#define REPORT_TO_USER 2
-
#ifdef HAVE_LINK_H
#include <link.h>
#endif
@@ -333,24 +330,6 @@ bool plugin_is_forced(struct st_plugin_int *p)
p->load_option == PLUGIN_FORCE_PLUS_PERMANENT;
}
-static void report_error(int where_to, uint error, ...)
-{
- va_list args;
- DBUG_ASSERT(where_to & (REPORT_TO_USER | REPORT_TO_LOG));
- if (where_to & REPORT_TO_USER)
- {
- va_start(args, error);
- my_printv_error(error, ER(error), MYF(0), args);
- va_end(args);
- }
- if (where_to & REPORT_TO_LOG)
- {
- va_start(args, error);
- error_log_print(ERROR_LEVEL, ER_DEFAULT(error), args);
- va_end(args);
- }
-}
-
/**
Check if the provided path is valid in the sense that it does cause
a relative reference outside the directory.
@@ -523,7 +502,7 @@ static void free_plugin_mem(struct st_plugin_dl *p)
@param plugin_dl Structure where the data should be put
@param sym Reverence on version info
@param dlpath Path to the module
- @param report What errors should be reported
+ @param MyFlags Where errors should be reported (0 or ME_ERROR_LOG)
@retval FALSE OK
@retval TRUE ERROR
@@ -531,14 +510,13 @@ static void free_plugin_mem(struct st_plugin_dl *p)
#ifdef HAVE_DLOPEN
static my_bool read_mysql_plugin_info(struct st_plugin_dl *plugin_dl,
- void *sym, char *dlpath,
- int report)
+ void *sym, char *dlpath, myf MyFlags)
{
DBUG_ENTER("read_maria_plugin_info");
/* Determine interface version */
if (!sym)
{
- report_error(report, ER_CANT_FIND_DL_ENTRY, plugin_interface_version_sym);
+ my_error(ER_CANT_FIND_DL_ENTRY, MyFlags, plugin_interface_version_sym);
DBUG_RETURN(TRUE);
}
plugin_dl->mariaversion= 0;
@@ -547,14 +525,14 @@ static my_bool read_mysql_plugin_info(struct st_plugin_dl *plugin_dl,
if (plugin_dl->mysqlversion < min_plugin_interface_version ||
(plugin_dl->mysqlversion >> 8) > (MYSQL_PLUGIN_INTERFACE_VERSION >> 8))
{
- report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, ENOEXEC,
+ my_error(ER_CANT_OPEN_LIBRARY, MyFlags, dlpath, ENOEXEC,
"plugin interface version mismatch");
DBUG_RETURN(TRUE);
}
/* Find plugin declarations */
if (!(sym= dlsym(plugin_dl->handle, plugin_declarations_sym)))
{
- report_error(report, ER_CANT_FIND_DL_ENTRY, plugin_declarations_sym);
+ my_error(ER_CANT_FIND_DL_ENTRY, MyFlags, plugin_declarations_sym);
DBUG_RETURN(TRUE);
}
@@ -584,7 +562,7 @@ static my_bool read_mysql_plugin_info(struct st_plugin_dl *plugin_dl,
MYF(MY_ZEROFILL|MY_WME));
if (!cur)
{
- report_error(report, ER_OUTOFMEMORY,
+ my_error(ER_OUTOFMEMORY, MyFlags,
static_cast<int>(plugin_dl->dl.length));
DBUG_RETURN(TRUE);
}
@@ -639,15 +617,14 @@ static my_bool read_mysql_plugin_info(struct st_plugin_dl *plugin_dl,
@param plugin_dl Structure where the data should be put
@param sym Reverence on version info
@param dlpath Path to the module
- @param report what errors should be reported
+ @param MyFlags Where errors should be reported (0 or ME_ERROR_LOG)
@retval FALSE OK
@retval TRUE ERROR
*/
static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
- void *sym, char *dlpath,
- int report)
+ void *sym, char *dlpath, myf MyFlags)
{
DBUG_ENTER("read_maria_plugin_info");
@@ -658,7 +635,7 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
Actually this branch impossible because in case of absence of maria
version we try mysql version.
*/
- report_error(report, ER_CANT_FIND_DL_ENTRY,
+ my_error(ER_CANT_FIND_DL_ENTRY, MyFlags,
maria_plugin_interface_version_sym);
DBUG_RETURN(TRUE);
}
@@ -668,14 +645,14 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
if (plugin_dl->mariaversion < min_maria_plugin_interface_version ||
(plugin_dl->mariaversion >> 8) > (MARIA_PLUGIN_INTERFACE_VERSION >> 8))
{
- report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, ENOEXEC,
+ my_error(ER_CANT_OPEN_LIBRARY, MyFlags, dlpath, ENOEXEC,
"plugin interface version mismatch");
DBUG_RETURN(TRUE);
}
/* Find plugin declarations */
if (!(sym= dlsym(plugin_dl->handle, maria_plugin_declarations_sym)))
{
- report_error(report, ER_CANT_FIND_DL_ENTRY, maria_plugin_declarations_sym);
+ my_error(ER_CANT_FIND_DL_ENTRY, MyFlags, maria_plugin_declarations_sym);
DBUG_RETURN(TRUE);
}
if (plugin_dl->mariaversion != MARIA_PLUGIN_INTERFACE_VERSION)
@@ -688,7 +665,7 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
sizeof_st_plugin= *(int *)sym;
else
{
- report_error(report, ER_CANT_FIND_DL_ENTRY, maria_sizeof_st_plugin_sym);
+ my_error(ER_CANT_FIND_DL_ENTRY, MyFlags, maria_sizeof_st_plugin_sym);
DBUG_RETURN(TRUE);
}
@@ -705,7 +682,7 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
MYF(MY_ZEROFILL|MY_WME));
if (!cur)
{
- report_error(report, ER_OUTOFMEMORY,
+ my_error(ER_OUTOFMEMORY, MyFlags,
static_cast<int>(plugin_dl->dl.length));
DBUG_RETURN(TRUE);
}
@@ -731,7 +708,7 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
}
#endif /* HAVE_DLOPEN */
-static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
+static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, myf MyFlags)
{
#ifdef HAVE_DLOPEN
char dlpath[FN_REFLEN];
@@ -755,7 +732,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
system_charset_info, 1) ||
plugin_dir_len + dl->length + 1 >= FN_REFLEN)
{
- report_error(report, ER_UDF_NO_PATHS);
+ my_error(ER_UDF_NO_PATHS, MyFlags);
DBUG_RETURN(0);
}
/* If this dll is already loaded just increase ref_count. */
@@ -772,7 +749,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
/* Open new dll handle */
if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
{
- report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, errno, my_dlerror(dlpath));
+ my_error(ER_CANT_OPEN_LIBRARY, MyFlags, dlpath, errno, my_dlerror(dlpath));
goto ret;
}
dlopen_count++;
@@ -792,12 +769,12 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
dlsym(plugin_dl.handle,
plugin_interface_version_sym),
dlpath,
- report))
+ MyFlags))
goto ret;
}
else
{
- if (read_maria_plugin_info(&plugin_dl, sym, dlpath, report))
+ if (read_maria_plugin_info(&plugin_dl, sym, dlpath, MyFlags))
goto ret;
}
@@ -815,7 +792,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
my_snprintf(buf, sizeof(buf),
"service '%s' interface version mismatch",
list_of_services[i].name);
- report_error(report, ER_CANT_OPEN_LIBRARY, dlpath, ENOEXEC, buf);
+ my_error(ER_CANT_OPEN_LIBRARY, MyFlags, dlpath, ENOEXEC, buf);
goto ret;
}
tmp_backup[plugin_dl.nbackups++].save(ptr);
@@ -830,7 +807,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
if (!plugin_dl.ptr_backup)
{
restore_ptr_backup(plugin_dl.nbackups, tmp_backup);
- report_error(report, ER_OUTOFMEMORY, bytes);
+ my_error(ER_OUTOFMEMORY, MyFlags, bytes);
goto ret;
}
memcpy(plugin_dl.ptr_backup, tmp_backup, bytes);
@@ -840,7 +817,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
plugin_dl.dl.length= dl->length * files_charset_info->mbmaxlen + 1;
if (! (plugin_dl.dl.str= (char*) my_malloc(plugin_dl.dl.length, MYF(0))))
{
- report_error(report, ER_OUTOFMEMORY,
+ my_error(ER_OUTOFMEMORY, MyFlags,
static_cast<int>(plugin_dl.dl.length));
goto ret;
}
@@ -853,7 +830,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
/* Add this dll to array */
if (! (tmp= plugin_dl_insert_or_reuse(&plugin_dl)))
{
- report_error(report, ER_OUTOFMEMORY,
+ my_error(ER_OUTOFMEMORY, MyFlags,
static_cast<int>(sizeof(struct st_plugin_dl)));
goto ret;
}
@@ -866,7 +843,7 @@ ret:
#else
DBUG_ENTER("plugin_dl_add");
- report_error(report, ER_FEATURE_DISABLED, "plugin", "HAVE_DLOPEN");
+ my_error(ER_FEATURE_DISABLED, MyFlags, "plugin", "HAVE_DLOPEN");
DBUG_RETURN(0);
#endif
}
@@ -1101,7 +1078,7 @@ static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
Requires that a write-lock is held on LOCK_system_variables_hash
*/
static bool plugin_add(MEM_ROOT *tmp_root,
- const LEX_CSTRING *name, LEX_CSTRING *dl, int report)
+ const LEX_CSTRING *name, LEX_CSTRING *dl, myf MyFlags)
{
struct st_plugin_int tmp, *maybe_dupe;
struct st_maria_plugin *plugin;
@@ -1111,13 +1088,13 @@ static bool plugin_add(MEM_ROOT *tmp_root,
if (name->str && plugin_find_internal(name, MYSQL_ANY_PLUGIN))
{
- report_error(report, ER_PLUGIN_INSTALLED, name->str);
+ my_error(ER_PLUGIN_INSTALLED, MyFlags, name->str);
DBUG_RETURN(TRUE);
}
/* Clear the whole struct to catch future extensions. */
bzero((char*) &tmp, sizeof(tmp));
fix_dl_name(tmp_root, dl);
- if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
+ if (! (tmp.plugin_dl= plugin_dl_add(dl, MyFlags)))
DBUG_RETURN(TRUE);
/* Find plugin by name */
for (plugin= tmp.plugin_dl->plugins; plugin->info; plugin++)
@@ -1143,7 +1120,7 @@ static bool plugin_add(MEM_ROOT *tmp_root,
{
if (plugin->name != maybe_dupe->plugin->name)
{
- report_error(report, ER_UDF_EXISTS, plugin->name);
+ my_error(ER_UDF_EXISTS, MyFlags, plugin->name);
DBUG_RETURN(TRUE);
}
dupes++;
@@ -1160,7 +1137,7 @@ static bool plugin_add(MEM_ROOT *tmp_root,
plugin_type_names[plugin->type].str,
" plugin ", tmp.name.str,
" not supported by this version of the server", NullS);
- report_error(report, ER_CANT_OPEN_LIBRARY, dl->str, ENOEXEC, buf);
+ my_error(ER_CANT_OPEN_LIBRARY, MyFlags, dl->str, ENOEXEC, buf);
goto err;
}
@@ -1173,7 +1150,7 @@ static bool plugin_add(MEM_ROOT *tmp_root,
" is prohibited by --plugin-maturity=",
plugin_maturity_names[plugin_maturity],
NullS);
- report_error(report, ER_CANT_OPEN_LIBRARY, dl->str, EPERM, buf);
+ my_error(ER_CANT_OPEN_LIBRARY, MyFlags, dl->str, EPERM, buf);
goto err;
}
else if (plugin_maturity_map[plugin->maturity] < SERVER_MATURITY_LEVEL)
@@ -1211,7 +1188,7 @@ err:
DBUG_ASSERT(!name->str || !dupes); // dupes is ONLY for name->str == 0
if (errs == 0 && oks == 0 && !dupes) // no plugin was found
- report_error(report, ER_CANT_FIND_DL_ENTRY, name->str);
+ my_error(ER_CANT_FIND_DL_ENTRY, MyFlags, name->str);
plugin_dl_del(tmp.plugin_dl);
DBUG_RETURN(errs > 0 || oks + dupes == 0);
@@ -1870,11 +1847,11 @@ static void plugin_load(MEM_ROOT *tmp_root)
the mutex here to satisfy the assert
*/
mysql_mutex_lock(&LOCK_plugin);
- plugin_add(tmp_root, &name, &dl, REPORT_TO_LOG);
+ plugin_add(tmp_root, &name, &dl, MYF(ME_ERROR_LOG));
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
mysql_mutex_unlock(&LOCK_plugin);
}
- if (error > 0)
+ if (unlikely(error > 0))
sql_print_error(ER_THD(new_thd, ER_GET_ERRNO), my_errno,
table->file->table_type());
end_read_record(&read_record_info);
@@ -1926,7 +1903,7 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, const char *list)
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
name.str= 0; // load everything
if (plugin_add(tmp_root, (LEX_CSTRING*) &name, (LEX_CSTRING*) &dl,
- REPORT_TO_LOG))
+ MYF(ME_ERROR_LOG)))
goto error;
}
else
@@ -1934,7 +1911,7 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, const char *list)
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
mysql_mutex_lock(&LOCK_plugin);
if (plugin_add(tmp_root, (LEX_CSTRING*) &name, (LEX_CSTRING*) &dl,
- REPORT_TO_LOG))
+ MYF(ME_ERROR_LOG)))
goto error;
}
mysql_mutex_unlock(&LOCK_plugin);
@@ -2126,7 +2103,7 @@ static bool finalize_install(THD *thd, TABLE *table, const LEX_CSTRING *name,
{
if (plugin_initialize(thd->mem_root, tmp, argc, argv, false))
{
- report_error(REPORT_TO_USER, ER_CANT_INITIALIZE_UDF, name->str,
+ my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str,
"Plugin initialization function failed.");
tmp->state= PLUGIN_IS_DELETED;
return 1;
@@ -2154,7 +2131,7 @@ static bool finalize_install(THD *thd, TABLE *table, const LEX_CSTRING *name,
files_charset_info);
error= table->file->ha_write_row(table->record[0]);
reenable_binlog(thd);
- if (error)
+ if (unlikely(error))
{
table->file->print_error(error, MYF(0));
tmp->state= PLUGIN_IS_DELETED;
@@ -2189,7 +2166,7 @@ bool mysql_install_plugin(THD *thd, const LEX_CSTRING *name,
if (my_load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv, NULL))
{
- report_error(REPORT_TO_USER, ER_PLUGIN_IS_NOT_LOADED, name->str);
+ my_error(ER_PLUGIN_IS_NOT_LOADED, MYF(0), name->str);
DBUG_RETURN(TRUE);
}
@@ -2218,8 +2195,8 @@ bool mysql_install_plugin(THD *thd, const LEX_CSTRING *name,
mysql_audit_acquire_plugins(thd, event_class_mask);
mysql_mutex_lock(&LOCK_plugin);
- error= plugin_add(thd->mem_root, name, &dl, REPORT_TO_USER);
- if (error)
+ error= plugin_add(thd->mem_root, name, &dl, MYF(0));
+ if (unlikely(error))
goto err;
if (name->str)
@@ -2235,7 +2212,7 @@ bool mysql_install_plugin(THD *thd, const LEX_CSTRING *name,
}
}
- if (error)
+ if (unlikely(error))
{
reap_needed= true;
reap_plugins();
@@ -2298,7 +2275,7 @@ static bool do_uninstall(THD *thd, TABLE *table, const LEX_CSTRING *name)
tmp_disable_binlog(thd);
error= table->file->ha_delete_row(table->record[0]);
reenable_binlog(thd);
- if (error)
+ if (unlikely(error))
{
table->file->print_error(error, MYF(0));
return 1;
@@ -2330,6 +2307,16 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_CSTRING *name,
if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
DBUG_RETURN(TRUE);
+ if (!table->key_info)
+ {
+ my_printf_error(ER_UNKNOWN_ERROR,
+ "The table %s.%s has no primary key. "
+ "Please check the table definition and "
+ "create the primary key accordingly.", MYF(0),
+ table->s->db.str, table->s->table_name.str);
+ DBUG_RETURN(TRUE);
+ }
+
/*
Pre-acquire audit plugins for events that may potentially occur
during [UN]INSTALL PLUGIN.
@@ -2486,7 +2473,7 @@ bool plugin_dl_foreach(THD *thd, const LEX_CSTRING *dl,
if (dl)
{
mysql_mutex_lock(&LOCK_plugin);
- st_plugin_dl *plugin_dl= plugin_dl_add(dl, REPORT_TO_USER);
+ st_plugin_dl *plugin_dl= plugin_dl_add(dl, MYF(0));
mysql_mutex_unlock(&LOCK_plugin);
if (!plugin_dl)
@@ -2751,7 +2738,7 @@ static int check_func_set(THD *thd, struct st_mysql_sys_var *var,
goto err;
result= find_set(typelib, str, length, NULL,
&error, &error_len, &not_used);
- if (error_len)
+ if (unlikely(error_len))
goto err;
}
else
@@ -2870,7 +2857,7 @@ sys_var *find_sys_var_ex(THD *thd, const char *str, size_t length,
if (!locked)
mysql_mutex_unlock(&LOCK_plugin);
- if (!throw_error && !var)
+ if (unlikely(!throw_error && !var))
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0),
(int) (length ? length : strlen(str)), (char*) str);
DBUG_RETURN(var);
@@ -4121,7 +4108,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
error= handle_options(argc, &argv, opts, mark_changed);
(*argc)++; /* add back one for the program name */
- if (error)
+ if (unlikely(error))
{
sql_print_error("Parsing options for plugin '%s' failed.",
tmp->name.str);