MySQL 8.0.40
Source Code Documentation
|
Add all options from files named "group".cnf from the default_directories before the command line arguments. More...
#include "my_config.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "m_ctype.h"
#include "m_string.h"
#include "my_aes.h"
#include "my_alloc.h"
#include "my_byteorder.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h"
#include "my_dir.h"
#include "my_getopt.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_loglevel.h"
#include "my_macros.h"
#include "my_psi_config.h"
#include "mysql/psi/mysql_file.h"
#include "mysql_version.h"
#include "mysys/my_default_priv.h"
#include "mysys/mysys_priv.h"
#include "mysys_err.h"
#include "typelib.h"
#include <algorithm>
#include <map>
#include <string>
#include "prealloced_array.h"
Classes | |
struct | my_variable_sources |
struct | handle_option_ctx |
Macros | |
#define | MAX_DEFAULT_DIRS 6 |
#define | DEFAULT_DIRS_SIZE (MAX_DEFAULT_DIRS + 1) /* Terminate with NULL */ |
Typedefs | |
typedef Prealloced_array< char *, 100 > | My_args |
using | mysql_file_getline_ret = std::unique_ptr< char, decltype(std::free) * > |
Functions | |
static void | set_args_separator (const char **arg) |
void | set_persist_args_separator (char **arg) |
bool | my_getopt_is_ro_persist_args_separator (const char *arg) |
bool | my_getopt_is_args_separator (const char *arg) |
static int | handle_default_option (void *in_ctx, const char *group_name, const char *option, const char *cnf_file) |
static int | search_default_file (Process_option_func func, void *func_ctx, const char *dir, const char *config_file, bool is_login_file) |
static int | search_default_file_with_ext (Process_option_func func, void *func_ctx, const char *dir, const char *ext, const char *config_file, int recursion_level, bool is_login_file, bool report_os_error_on_open) |
static mysql_file_getline_ret | mysql_file_getline (char *buff, int size, MYSQL_FILE *file, bool is_login_file) |
Read one line from the specified file. More... | |
static const char ** | init_default_directories (MEM_ROOT *alloc) |
Create the list of default directories. More... | |
static char * | remove_end_comment (char *ptr) |
static int | fn_expand (const char *filename, char *result_buf) |
int | my_search_option_files (const char *conf_file, int *argc, char ***argv, uint *args_used, Process_option_func func, void *func_ctx, const char **default_directories, bool is_login_file, bool found_no_defaults) |
int | get_defaults_options (int argc, char **argv, char **defaults, char **extra_defaults, char **group_suffix, char **login_path, bool found_no_defaults) |
int | load_defaults (const char *conf_file, const char **groups, int *argc, char ***argv, MEM_ROOT *alloc) |
int | my_load_defaults (const char *conf_file, const char **groups, int *argc, char ***argv, MEM_ROOT *alloc, const char ***default_directories) |
static char * | get_argument (const char *keyword, size_t kwlen, char *ptr, char *name, uint line) |
void | my_print_default_files (const char *conf_file) |
void | print_defaults (const char *conf_file, const char **groups) |
void | init_variable_default_paths () |
Initialize all the mappings between default config file paths/ command line options/persistent config file path/login file path and corresponding enum_variable_source values. More... | |
void | update_variable_source (const char *opt_name, const char *value) |
Track all options loaded from config files and command line options along with the path from where options are loaded. More... | |
void | set_variable_source (const char *opt_name, void *value) |
This function will set value for my_option::arg_source by doing a lookup into variables_hash based on opt_name as key. More... | |
static int | add_directory (MEM_ROOT *alloc, const char *dir, const char **dirs) |
int | my_default_get_login_file (char *file_name, size_t file_name_size) |
Place the login file name in the specified buffer. More... | |
int | check_file_permissions (const char *file_name, bool is_login_file, myf flags) |
Check file permissions of the option file. More... | |
Variables | |
static std::map< string, my_variable_sources > | variables_hash |
Defines mapping between variable names (set as part of config files or command line) and its config file/source value. More... | |
static std::map< string, enum_variable_source > | default_paths |
Defines mapping between config files names and its corresponding enum values. More... | |
char | datadir_buffer [FN_REFLEN] = {0} |
Holds a reference to the directory where the persisted configuration file is located. More... | |
PSI_file_key | key_file_cnf |
PSI_memory_key | key_memory_defaults |
static const char * | args_separator = "----args-separator----" |
arguments separator More... | |
static const char * | persist_args_separator = "----persist-args-separator----" |
bool | my_getopt_use_args_separator = false |
const char * | my_defaults_file = nullptr |
const char * | my_defaults_group_suffix = nullptr |
const char * | my_defaults_extra_file = nullptr |
static const char * | my_login_path = nullptr |
static char | my_defaults_file_buffer [FN_REFLEN] |
static char | my_defaults_extra_file_buffer [FN_REFLEN] |
static bool | defaults_already_read = false |
bool | no_defaults = false |
static const char ** | default_directories = nullptr |
static const char * | f_extensions [] = {".cnf", nullptr} |
bool | my_defaults_read_login_file = true |
A global to turn off or on reading the mylogin file. More... | |
Add all options from files named "group".cnf from the default_directories before the command line arguments.
On Windows defaults will also search in the Windows directory for a file called 'group'.ini As long as the program uses the last argument for conflicting options one only have to add a call to "load_defaults" to enable use of default values. pre- and end 'blank space' are removed from options and values. The following escape sequences are recognized in values:
The following arguments are handled automatically; If used, they must be first argument on the command line! –no-defaults ; no options are read, except for the ones provided in the login file. –defaults-file=full-path-to-default-file ; Only this file will be read. –defaults-extra-file=full-path-to-default-file ; Read this file before ~/ –defaults-group-suffix ; Also read groups with concat(group, suffix) –print-defaults ; Print the modified command line and exit –login-path=login-path-name ; Read options under login-path-name from the login file.
#define DEFAULT_DIRS_SIZE (MAX_DEFAULT_DIRS + 1) /* Terminate with NULL */ |
#define MAX_DEFAULT_DIRS 6 |
typedef Prealloced_array<char *, 100> My_args |
using mysql_file_getline_ret = std::unique_ptr<char, decltype(std::free) *> |
|
static |
int check_file_permissions | ( | const char * | file_name, |
bool | is_login_file, | ||
myf | flags | ||
) |
Check file permissions of the option file.
[in] | file_name | Name of the option file. |
[in] | is_login_file | TRUE, when login file is being processed. |
[in] | flags | error handling flags |
|
static |
|
static |
int get_defaults_options | ( | int | argc, |
char ** | argv, | ||
char ** | defaults, | ||
char ** | extra_defaults, | ||
char ** | group_suffix, | ||
char ** | login_path, | ||
bool | found_no_defaults | ||
) |
|
static |
|
static |
Create the list of default directories.
The directories searched, in order, are: - Windows: GetSystemWindowsDirectory() - Windows: GetWindowsDirectory() - Windows: C:/ - Windows: Directory above where the executable is located - Unix: /etc/ - Unix: /etc/mysql/ - Unix: --sysconfdir=<path> (compile-time option) - ALL: getenv("MYSQL_HOME") - ALL: --defaults-extra-file=<path> (run-time option) - Unix: ~/
On all systems, if a directory is already in the list, it will be moved to the end of the list. This avoids reading defaults files multiple times, while ensuring the correct precedence.
alloc | MEM_ROOT where the list of directories is stored |
NULL | Failure (out of memory, probably) |
other | Pointer to NULL-terminated array of default directories |
void init_variable_default_paths | ( | ) |
Initialize all the mappings between default config file paths/ command line options/persistent config file path/login file path and corresponding enum_variable_source values.
int load_defaults | ( | const char * | conf_file, |
const char ** | groups, | ||
int * | argc, | ||
char *** | argv, | ||
MEM_ROOT * | alloc | ||
) |
int my_default_get_login_file | ( | char * | file_name, |
size_t | file_name_size | ||
) |
Place the login file name in the specified buffer.
[out] | file_name | Buffer to hold login file name |
[in] | file_name_size | Length of the buffer |
bool my_getopt_is_args_separator | ( | const char * | arg | ) |
bool my_getopt_is_ro_persist_args_separator | ( | const char * | arg | ) |
int my_load_defaults | ( | const char * | conf_file, |
const char ** | groups, | ||
int * | argc, | ||
char *** | argv, | ||
MEM_ROOT * | alloc, | ||
const char *** | default_directories | ||
) |
void my_print_default_files | ( | const char * | conf_file | ) |
int my_search_option_files | ( | const char * | conf_file, |
int * | argc, | ||
char *** | argv, | ||
uint * | args_used, | ||
Process_option_func | func, | ||
void * | func_ctx, | ||
const char ** | default_directories, | ||
bool | is_login_file, | ||
bool | found_no_defaults | ||
) |
copy group
Construct new group
copy group
Construct new group
|
static |
Read one line from the specified file.
In case of scrambled login file, the line read is first decrypted and then returned.
[out] | buff | Static buffer to store the read line. If the buffer is not enough, this function will allocate a dynamic buffer from heap. |
[in] | size | At max, size-1 bytes to be read. |
[in] | file | Source file. |
[in] | is_login_file | TRUE, when login file is being processed. |
void print_defaults | ( | const char * | conf_file, |
const char ** | groups | ||
) |
|
static |
|
static |
|
static |
|
inlinestatic |
void set_persist_args_separator | ( | char ** | arg | ) |
void set_variable_source | ( | const char * | opt_name, |
void * | value | ||
) |
This function will set value for my_option::arg_source by doing a lookup into variables_hash based on opt_name as key.
If key is present corresponding value (config file, enum value) will be set in value.
[in] | opt_name | Pointer to option name. |
[out] | value | Pointer to struct holding config file path and variable source |
void update_variable_source | ( | const char * | opt_name, |
const char * | value | ||
) |
Track all options loaded from config files and command line options along with the path from where options are loaded.
For command line options path is empty string.
Ex: /etc/my.cnf has max_connections /$datadir/mysqld.auto.cnf has max_user_connections ./mysqld –server-id=47 with this setup, variables_hash has 3 entries of the above options along with path of config files and its enum value which is as below: max_connections -> (/etc/my.cnf , enum_variable_source::GLOBAL) max_user_connections -> ($datadir/mysqld.auto.cnf , enum_variable_source::PERSISTED) server-id -> ("" , enum_variable_source::COMMAND_LINE)
[in] | opt_name | Pointer to option name. opt_name must be in the form off –XXXXXX |
[in] | value | Pointer to config file path |
|
static |
arguments separator
load_defaults() loads arguments from config file and put them before the arguments from command line, this separator is used to separate the arguments loaded from config file and arguments user provided on command line.
Options with value loaded from config file are always in the form '–option=value', while for command line options, the value can be given as the next argument. Thus we used a separator so that handle_options() can distinguish them.
Note: any other places that does not need to distinguish them should skip the separator.
The content of arguments separator does not matter, one should only check the pointer, use "----args-separator----" here to ease debug if someone misused it.
The args separator will only be added when my_getopt_use_args_seprator is set to TRUE before calling load_defaults();
See BUG#25192
char datadir_buffer[FN_REFLEN] = {0} |
Holds a reference to the directory where the persisted configuration file is located.
This usually is the data directory. This is different from mysql_real_data_home mostly because it's passed down to mysys. And is also filled in a bit differently from mysql_real_data_home by Persisted_variables_cache::init()
|
static |
|
static |
Defines mapping between config files names and its corresponding enum values.
ex: File /etc/my.cnf is mapped to enum_variable_source::GLOBAL ~/.my.cnf is mapped to enum_variable_source::USER command line options are mapped to enum_variable_source::COMMAND_LINE
|
static |
|
static |
|
extern |
PSI_memory_key key_memory_defaults |
const char* my_defaults_extra_file = nullptr |
|
static |
const char* my_defaults_file = nullptr |
|
static |
const char* my_defaults_group_suffix = nullptr |
bool my_defaults_read_login_file = true |
A global to turn off or on reading the mylogin file.
On by default
bool my_getopt_use_args_separator = false |
|
static |
bool no_defaults = false |
|
static |
|
static |
Defines mapping between variable names (set as part of config files or command line) and its config file/source value.
ex: If config file /etc/my.cnf has variables max_connections= 30 and $datadir/mysqld-auto.cnf has variables max_heap_table_size=887808 then this variable will have following key/value pair. max_connections -> (/etc/my.cnf , enum_variable_source::GLOBAL) max_heap_table_size -> ($datadir/mysqld-auto.cnf , enum_variable_source::PERSISTED)