36
36
#include "mysys_priv.h"
37
37
#include <mystrings/m_string.h>
38
38
#include <mystrings/m_ctype.h>
39
#include <mysys/my_dir.h>
41
43
const char *my_defaults_file=0;
42
44
const char *my_defaults_group_suffix=0;
48
50
const char *default_directories[MAX_DEFAULT_DIRS + 1];
50
52
static const char *f_extensions[]= { ".cnf", 0 };
53
static int handle_default_option(void *in_ctx, const char *group_name,
54
int handle_default_option(void *in_ctx, const char *group_name,
57
58
This structure defines the context that we pass to callback
128
129
int my_search_option_files(const char *conf_file, int *argc, char ***argv,
129
uint *args_used, Process_option_func func,
130
uint32_t *args_used, Process_option_func func,
132
133
const char **dirs, *forced_default_file, *forced_extra_defaults;
152
153
load_defaults() as otherwise we can't know the type of 'func_ctx'
155
if (my_defaults_group_suffix && func == handle_default_option)
156
if (my_defaults_group_suffix && (func == handle_default_option))
157
158
/* Handle --defaults-group-suffix= */
159
160
const char **extra_groups;
160
const uint instance_len= strlen(my_defaults_group_suffix);
161
const uint32_t instance_len= strlen(my_defaults_group_suffix);
161
162
struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
163
164
TYPELIB *group= ctx->group;
166
167
(const char**)alloc_root(ctx->alloc,
167
168
(2*group->count+1)*sizeof(char*))))
170
171
for (i= 0; i < group->count; i++)
173
174
extra_groups[i]= group->type_names[i]; /** copy group */
175
176
len= strlen(extra_groups[i]);
176
if (!(ptr= alloc_root(ctx->alloc, len+instance_len+1)))
177
if (!(ptr= (char *)alloc_root(ctx->alloc, len+instance_len+1)))
179
180
extra_groups[i+group->count]= ptr;
181
182
/** Construct new group */
182
183
memcpy(ptr, extra_groups[i], len);
183
184
memcpy(ptr+len, my_defaults_group_suffix, instance_len+1);
186
187
group->count*= 2;
187
188
group->type_names= extra_groups;
188
189
group->type_names[group->count]= 0;
191
192
if (forced_default_file)
193
194
if ((error= search_default_file_with_ext(func, func_ctx, "", "",
203
204
else if (dirname_length(conf_file))
205
if ((error= search_default_file(func, func_ctx, NullS, conf_file)) < 0)
206
if ((error= search_default_file(func, func_ctx, NULL, conf_file)) < 0)
261
261
1 - error occured
264
static int handle_default_option(void *in_ctx, const char *group_name,
264
int handle_default_option(void *in_ctx, const char *group_name,
268
268
struct handle_option_ctx *ctx= (struct handle_option_ctx *) in_ctx;
273
273
if (find_type((char *)group_name, ctx->group, 3))
275
if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
277
if (insert_dynamic(ctx->args, (uchar*) &tmp))
275
if (!(tmp= (char *)alloc_root(ctx->alloc, strlen(option) + 1)))
277
if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
387
387
if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults"))
389
389
/* remove the --no-defaults argument and return only the other arguments */
391
391
if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
392
392
(*argc + 1)*sizeof(char*))))
519
518
static char *get_argument(const char *keyword, size_t kwlen,
520
char *ptr, char *name, uint line)
519
char *ptr, char *name, uint32_t line)
524
523
/* Skip over "include / includedir keyword" and following whitespace */
526
525
for (ptr+= kwlen - 1;
527
my_isspace(&my_charset_latin1, ptr[0]);
526
my_isspace(&my_charset_utf8_general_ci, ptr[0]);
534
533
Note that my_isspace() is true for \r and \n
536
535
for (end= ptr + strlen(ptr) - 1;
537
my_isspace(&my_charset_latin1, *(end - 1));
536
my_isspace(&my_charset_utf8_general_ci, *(end - 1));
540
539
end[0]= 0; /* Cut off end space */
558
557
search_default_file_with_ext()
559
558
opt_handler Option handler function. It is used to process
560
559
every separate option.
561
handler_ctx Pointer to the structure to store actual
560
handler_ctx Pointer to the structure to store actual
562
561
parameters of the function.
563
562
dir directory to read
564
563
ext Extension for configuration file
596
595
return 0; /* Ignore wrong paths */
599
end=convert_dirname(name, dir, NullS);
598
end=convert_dirname(name, dir, NULL);
600
599
if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */
602
strxmov(end,config_file,ext,NullS);
601
sprintf(end,"%s%s",config_file,ext);
606
stpcpy(name,config_file);
605
strcpy(name,config_file);
608
607
fn_format(name,name,"","",4);
614
613
Ignore world-writable regular files.
615
614
This is mainly done to protect us to not read a file created by
616
the mysqld server, but the check is still valid in most context.
615
the mysqld server, but the check is still valid in most context.
618
617
if ((stat_info.st_mode & S_IWOTH) &&
619
618
(stat_info.st_mode & S_IFMT) == S_IFREG)
632
631
/* Ignore comment and empty lines */
633
for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++)
632
for (ptr= buff; my_isspace(&my_charset_utf8_general_ci, *ptr); ptr++)
636
635
if (*ptr == '#' || *ptr == ';' || !*ptr)
642
641
if (recursion_level >= max_recursion_level)
644
for (end= ptr + strlen(ptr) - 1;
645
my_isspace(&my_charset_latin1, *(end - 1));
643
for (end= ptr + strlen(ptr) - 1;
644
my_isspace(&my_charset_utf8_general_ci, *(end - 1));
656
655
/* skip over `!' and following whitespace */
657
for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++)
656
for (++ptr; my_isspace(&my_charset_utf8_general_ci, ptr[0]); ptr++)
660
659
if ((!strncmp(ptr, includedir_keyword,
661
660
sizeof(includedir_keyword) - 1)) &&
662
my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1]))
661
my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(includedir_keyword) - 1]))
664
663
if (!(ptr= get_argument(includedir_keyword,
665
664
sizeof(includedir_keyword),
694
693
my_dirend(search_dir);
696
695
else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
697
my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1]))
696
my_isspace(&my_charset_utf8_general_ci, ptr[sizeof(include_keyword)-1]))
699
698
if (!(ptr= get_argument(include_keyword,
700
699
sizeof(include_keyword), ptr,
721
720
/* Remove end space */
722
for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
721
for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
725
strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
724
strncpy(curr_gr, ptr, cmin((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
725
curr_gr[cmin((size_t)(end-ptr)+1, sizeof(curr_gr)-1)] = '\0';
727
727
/* signal that a new group is found */
728
728
opt_handler(handler_ctx, curr_gr, NULL);
741
741
end= remove_end_comment(ptr);
742
742
if ((value= strchr(ptr, '=')))
743
743
end= value; /* Option without argument */
744
for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
744
for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
747
strmake(stpcpy(option,"--"),ptr, (size_t) (end-ptr));
747
strncpy(strcpy(option,"--")+2,ptr,strlen(ptr)+1);
748
748
if (opt_handler(handler_ctx, curr_gr, option))
753
753
/* Remove pre- and end space */
755
for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ;
756
value_end=strend(value);
755
for (value++ ; my_isspace(&my_charset_utf8_general_ci,*value); value++) ;
756
value_end= strchr(value, '\0');
758
We don't have to test for value_end >= value as we know there is
758
We don't have to test for value_end >= value as we know there is
761
for ( ; my_isspace(&my_charset_latin1,value_end[-1]) ; value_end--) ;
761
for ( ; my_isspace(&my_charset_utf8_general_ci,value_end[-1]) ; value_end--) ;
762
762
if (value_end < value) /* Empty string */
765
765
/* remove quotes around argument */
766
766
if ((*value == '\"' || *value == '\'') && /* First char is quote */
767
767
(value + 1 < value_end ) && /* String is longer than 1 */
768
768
*value == value_end[-1] ) /* First char is equal to last char */
773
ptr=stpncpy(stpcpy(option,"--"),ptr,(size_t) (end-ptr));
773
ptr= strncpy(strcpy(option,"--")+2,ptr,(size_t) (end-ptr));
776
777
for ( ; value != value_end; value++)
877
878
pos= my_defaults_extra_file;
880
end= convert_dirname(name, pos, NullS);
881
end= convert_dirname(name, pos, NULL);
881
882
if (name[0] == FN_HOMELIB) /* Add . to filenames in home */
883
strxmov(end, conf_file, *ext, " ", NullS);
884
sprintf(end,"%s%s ",conf_file, *ext);
884
885
fputs(name,stdout);
951
952
memset(default_directories, 0, sizeof(default_directories));
952
953
ADD_DIRECTORY("/etc/");
953
ADD_DIRECTORY("/etc/mysql/");
954
ADD_DIRECTORY("/etc/drizzle/");
954
955
#if defined(DEFAULT_SYSCONFDIR)
955
956
ADD_DIRECTORY(DEFAULT_SYSCONFDIR);