Skip to content

Commit d61e526

Browse files
committed
MDEV-10441 Document the server_audit_loc_info variable
fix PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_NOCMDOPT plugin thdvars to work. use that for server_audit_loc_info
1 parent c91fdb6 commit d61e526

File tree

4 files changed

+69
-93
lines changed

4 files changed

+69
-93
lines changed

mysql-test/suite/plugins/r/server_audit.result

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ server_audit_file_rotate_now OFF
88
server_audit_file_rotate_size 1000000
99
server_audit_file_rotations 9
1010
server_audit_incl_users
11-
server_audit_loc_info
1211
server_audit_logging OFF
1312
server_audit_mode 0
1413
server_audit_output_type file
@@ -72,7 +71,6 @@ server_audit_file_rotate_now OFF
7271
server_audit_file_rotate_size 1000000
7372
server_audit_file_rotations 9
7473
server_audit_incl_users odin, root, dva, tri
75-
server_audit_loc_info
7674
server_audit_logging ON
7775
server_audit_mode 0
7876
server_audit_output_type file
@@ -218,7 +216,6 @@ server_audit_file_rotate_now OFF
218216
server_audit_file_rotate_size 1000000
219217
server_audit_file_rotations 9
220218
server_audit_incl_users odin, root, dva, tri
221-
server_audit_loc_info
222219
server_audit_logging ON
223220
server_audit_mode 1
224221
server_audit_output_type file

mysql-test/suite/plugins/r/thread_pool_server_audit.result

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ server_audit_file_rotate_now OFF
88
server_audit_file_rotate_size 1000000
99
server_audit_file_rotations 9
1010
server_audit_incl_users
11-
server_audit_loc_info
1211
server_audit_logging OFF
1312
server_audit_mode 0
1413
server_audit_output_type file
@@ -72,7 +71,6 @@ server_audit_file_rotate_now OFF
7271
server_audit_file_rotate_size 1000000
7372
server_audit_file_rotations 9
7473
server_audit_incl_users odin, root, dva, tri
75-
server_audit_loc_info
7674
server_audit_logging ON
7775
server_audit_mode 0
7876
server_audit_output_type file
@@ -218,7 +216,6 @@ server_audit_file_rotate_now OFF
218216
server_audit_file_rotate_size 1000000
219217
server_audit_file_rotations 9
220218
server_audit_incl_users odin, root, dva, tri
221-
server_audit_loc_info
222219
server_audit_logging ON
223220
server_audit_mode 1
224221
server_audit_output_type file

plugin/server_audit/server_audit.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,8 @@ static MYSQL_SYSVAR_UINT(query_log_limit, query_log_limit,
429429
char locinfo_ini_value[sizeof(struct connection_info)+4];
430430

431431
static MYSQL_THDVAR_STR(loc_info,
432-
PLUGIN_VAR_READONLY | PLUGIN_VAR_MEMALLOC,
433-
"Auxiliary info.", NULL, NULL,
434-
locinfo_ini_value);
432+
PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_MEMALLOC,
433+
"Internal info", NULL, NULL, locinfo_ini_value);
435434

436435
static const char *syslog_facility_names[]=
437436
{

sql/sql_plugin.cc

Lines changed: 67 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,22 @@ static st_bookmark *find_bookmark(const char *plugin, const char *name,
27562756
}
27572757

27582758

2759+
static size_t var_storage_size(int flags)
2760+
{
2761+
switch (flags & PLUGIN_VAR_TYPEMASK) {
2762+
case PLUGIN_VAR_BOOL: return sizeof(my_bool);
2763+
case PLUGIN_VAR_INT: return sizeof(int);
2764+
case PLUGIN_VAR_LONG: return sizeof(long);
2765+
case PLUGIN_VAR_ENUM: return sizeof(long);
2766+
case PLUGIN_VAR_LONGLONG: return sizeof(ulonglong);
2767+
case PLUGIN_VAR_SET: return sizeof(ulonglong);
2768+
case PLUGIN_VAR_STR: return sizeof(char*);
2769+
case PLUGIN_VAR_DOUBLE: return sizeof(double);
2770+
default: DBUG_ASSERT(0); return 0;
2771+
}
2772+
}
2773+
2774+
27592775
/*
27602776
returns a bookmark for thd-local variables, creating if neccessary.
27612777
returns null for non thd-local variables.
@@ -2764,39 +2780,13 @@ static st_bookmark *find_bookmark(const char *plugin, const char *name,
27642780
static st_bookmark *register_var(const char *plugin, const char *name,
27652781
int flags)
27662782
{
2767-
uint length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
2783+
uint length= strlen(plugin) + strlen(name) + 3, size, offset, new_size;
27682784
st_bookmark *result;
27692785
char *varname, *p;
27702786

2771-
if (!(flags & PLUGIN_VAR_THDLOCAL))
2772-
return NULL;
2773-
2774-
switch (flags & PLUGIN_VAR_TYPEMASK) {
2775-
case PLUGIN_VAR_BOOL:
2776-
size= sizeof(my_bool);
2777-
break;
2778-
case PLUGIN_VAR_INT:
2779-
size= sizeof(int);
2780-
break;
2781-
case PLUGIN_VAR_LONG:
2782-
case PLUGIN_VAR_ENUM:
2783-
size= sizeof(long);
2784-
break;
2785-
case PLUGIN_VAR_LONGLONG:
2786-
case PLUGIN_VAR_SET:
2787-
size= sizeof(ulonglong);
2788-
break;
2789-
case PLUGIN_VAR_STR:
2790-
size= sizeof(char*);
2791-
break;
2792-
case PLUGIN_VAR_DOUBLE:
2793-
size= sizeof(double);
2794-
break;
2795-
default:
2796-
DBUG_ASSERT(0);
2797-
return NULL;
2798-
};
2787+
DBUG_ASSERT(flags & PLUGIN_VAR_THDLOCAL);
27992788

2789+
size= var_storage_size(flags);
28002790
varname= ((char*) my_alloca(length));
28012791
strxmov(varname + 1, plugin, "_", name, NullS);
28022792
for (p= varname + 1; *p; p++)
@@ -3005,25 +2995,17 @@ void sync_dynamic_session_variables(THD* thd, bool global_lock)
30052995
*/
30062996
for (idx= 0; idx < bookmark_hash.records; idx++)
30072997
{
3008-
sys_var_pluginvar *pi;
3009-
sys_var *var;
30102998
st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx);
30112999

30123000
if (v->version <= thd->variables.dynamic_variables_version)
30133001
continue; /* already in thd->variables */
30143002

3015-
if (!(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
3016-
!(pi= var->cast_pluginvar()) ||
3017-
v->key[0] != plugin_var_bookmark_key(pi->plugin_var->flags))
3018-
continue;
3019-
30203003
/* Here we do anything special that may be required of the data types */
30213004

3022-
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
3023-
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
3005+
if ((v->key[0] & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
3006+
v->key[0] & BOOKMARK_MEMALLOC)
30243007
{
3025-
int offset= ((thdvar_str_t *)(pi->plugin_var))->offset;
3026-
char **pp= (char**) (thd->variables.dynamic_variables_ptr + offset);
3008+
char **pp= (char**) (thd->variables.dynamic_variables_ptr + v->offset);
30273009
if (*pp)
30283010
*pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
30293011
}
@@ -3284,69 +3266,58 @@ bool sys_var_pluginvar::session_update(THD *thd, set_var *var)
32843266
return false;
32853267
}
32863268

3287-
bool sys_var_pluginvar::global_update(THD *thd, set_var *var)
3269+
static const void *var_def_ptr(st_mysql_sys_var *pv)
32883270
{
3289-
DBUG_ASSERT(!is_readonly());
3290-
mysql_mutex_assert_owner(&LOCK_global_system_variables);
3291-
3292-
void *tgt= real_value_ptr(thd, var->type);
3293-
const void *src= &var->save_result;
3294-
3295-
if (!var->value)
3296-
{
3297-
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
3271+
switch (pv->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
32983272
case PLUGIN_VAR_INT:
3299-
src= &((sysvar_uint_t*) plugin_var)->def_val;
3300-
break;
3273+
return &((sysvar_uint_t*) pv)->def_val;
33013274
case PLUGIN_VAR_LONG:
3302-
src= &((sysvar_ulong_t*) plugin_var)->def_val;
3303-
break;
3275+
return &((sysvar_ulong_t*) pv)->def_val;
33043276
case PLUGIN_VAR_LONGLONG:
3305-
src= &((sysvar_ulonglong_t*) plugin_var)->def_val;
3306-
break;
3277+
return &((sysvar_ulonglong_t*) pv)->def_val;
33073278
case PLUGIN_VAR_ENUM:
3308-
src= &((sysvar_enum_t*) plugin_var)->def_val;
3309-
break;
3279+
return &((sysvar_enum_t*) pv)->def_val;
33103280
case PLUGIN_VAR_SET:
3311-
src= &((sysvar_set_t*) plugin_var)->def_val;
3312-
break;
3281+
return &((sysvar_set_t*) pv)->def_val;
33133282
case PLUGIN_VAR_BOOL:
3314-
src= &((sysvar_bool_t*) plugin_var)->def_val;
3315-
break;
3283+
return &((sysvar_bool_t*) pv)->def_val;
33163284
case PLUGIN_VAR_STR:
3317-
src= &((sysvar_str_t*) plugin_var)->def_val;
3318-
break;
3285+
return &((sysvar_str_t*) pv)->def_val;
33193286
case PLUGIN_VAR_DOUBLE:
3320-
src= &((sysvar_double_t*) plugin_var)->def_val;
3321-
break;
3287+
return &((sysvar_double_t*) pv)->def_val;
33223288
case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
3323-
src= &((thdvar_uint_t*) plugin_var)->def_val;
3324-
break;
3289+
return &((thdvar_uint_t*) pv)->def_val;
33253290
case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
3326-
src= &((thdvar_ulong_t*) plugin_var)->def_val;
3327-
break;
3291+
return &((thdvar_ulong_t*) pv)->def_val;
33283292
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
3329-
src= &((thdvar_ulonglong_t*) plugin_var)->def_val;
3330-
break;
3293+
return &((thdvar_ulonglong_t*) pv)->def_val;
33313294
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
3332-
src= &((thdvar_enum_t*) plugin_var)->def_val;
3333-
break;
3295+
return &((thdvar_enum_t*) pv)->def_val;
33343296
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
3335-
src= &((thdvar_set_t*) plugin_var)->def_val;
3336-
break;
3297+
return &((thdvar_set_t*) pv)->def_val;
33373298
case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
3338-
src= &((thdvar_bool_t*) plugin_var)->def_val;
3339-
break;
3299+
return &((thdvar_bool_t*) pv)->def_val;
33403300
case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
3341-
src= &((thdvar_str_t*) plugin_var)->def_val;
3342-
break;
3301+
return &((thdvar_str_t*) pv)->def_val;
33433302
case PLUGIN_VAR_DOUBLE | PLUGIN_VAR_THDLOCAL:
3344-
src= &((thdvar_double_t*) plugin_var)->def_val;
3345-
break;
3303+
return &((thdvar_double_t*) pv)->def_val;
33463304
default:
33473305
DBUG_ASSERT(0);
3306+
return NULL;
33483307
}
3349-
}
3308+
}
3309+
3310+
3311+
bool sys_var_pluginvar::global_update(THD *thd, set_var *var)
3312+
{
3313+
DBUG_ASSERT(!is_readonly());
3314+
mysql_mutex_assert_owner(&LOCK_global_system_variables);
3315+
3316+
void *tgt= real_value_ptr(thd, var->type);
3317+
const void *src= &var->save_result;
3318+
3319+
if (!var->value)
3320+
src= var_def_ptr(plugin_var);
33503321

33513322
plugin_var->update(thd, plugin_var, tgt, src);
33523323
return false;
@@ -3713,7 +3684,18 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
37133684
*(int*)(opt + 1)= offset= v->offset;
37143685

37153686
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
3687+
{
3688+
char *val= global_system_variables.dynamic_variables_ptr + offset;
3689+
if (((opt->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
3690+
(opt->flags & PLUGIN_VAR_MEMALLOC))
3691+
{
3692+
char *def_val= *(char**)var_def_ptr(opt);
3693+
*(char**)val= def_val ? my_strdup(def_val, MYF(0)) : NULL;
3694+
}
3695+
else
3696+
memcpy(val, var_def_ptr(opt), var_storage_size(opt->flags));
37163697
continue;
3698+
}
37173699

37183700
optname= (char*) memdup_root(mem_root, v->key + 1,
37193701
(optnamelen= v->name_len) + 1);
@@ -3912,9 +3894,10 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
39123894
*str->value= strdup_root(mem_root, *str->value);
39133895
}
39143896

3897+
var= find_bookmark(plugin_name.str, o->name, o->flags);
39153898
if (o->flags & PLUGIN_VAR_NOSYSVAR)
39163899
continue;
3917-
if ((var= find_bookmark(plugin_name.str, o->name, o->flags)))
3900+
if (var)
39183901
v= new (mem_root) sys_var_pluginvar(&chain, var->key + 1, o, tmp);
39193902
else
39203903
{

0 commit comments

Comments
 (0)