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>
40
#include <drizzled/configmake.h>
41
44
const char *my_defaults_file=0;
42
45
const char *my_defaults_group_suffix=0;
48
51
const char *default_directories[MAX_DEFAULT_DIRS + 1];
50
53
static const char *f_extensions[]= { ".cnf", 0 };
53
static int handle_default_option(void *in_ctx, const char *group_name,
55
int handle_default_option(void *in_ctx, const char *group_name,
57
59
This structure defines the context that we pass to callback
139
141
(char **) &my_defaults_group_suffix);
141
143
if (! my_defaults_group_suffix)
142
my_defaults_group_suffix= getenv(STRINGIFY_ARG(DEFAULT_GROUP_SUFFIX_ENV));
144
my_defaults_group_suffix= getenv("DRIZZLE_GROUP_SUFFIX");
144
146
if (forced_extra_defaults)
145
147
my_defaults_extra_file= (char *) forced_extra_defaults;
147
149
if (forced_default_file)
148
150
my_defaults_file= forced_default_file;
152
154
load_defaults() as otherwise we can't know the type of 'func_ctx'
155
if (my_defaults_group_suffix && func == handle_default_option)
157
if (my_defaults_group_suffix && (func == handle_default_option))
157
159
/* Handle --defaults-group-suffix= */
159
161
const char **extra_groups;
160
const uint32_t instance_len= strlen(my_defaults_group_suffix);
162
const uint32_t instance_len= strlen(my_defaults_group_suffix);
161
163
struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
163
165
TYPELIB *group= ctx->group;
166
168
(const char**)alloc_root(ctx->alloc,
167
169
(2*group->count+1)*sizeof(char*))))
170
172
for (i= 0; i < group->count; i++)
173
175
extra_groups[i]= group->type_names[i]; /** copy group */
175
177
len= strlen(extra_groups[i]);
176
if (!(ptr= alloc_root(ctx->alloc, len+instance_len+1)))
178
if (!(ptr= (char *)alloc_root(ctx->alloc, len+instance_len+1)))
179
181
extra_groups[i+group->count]= ptr;
181
183
/** Construct new group */
182
184
memcpy(ptr, extra_groups[i], len);
183
185
memcpy(ptr+len, my_defaults_group_suffix, instance_len+1);
186
188
group->count*= 2;
187
189
group->type_names= extra_groups;
188
190
group->type_names[group->count]= 0;
191
193
if (forced_default_file)
193
195
if ((error= search_default_file_with_ext(func, func_ctx, "", "",
261
262
1 - error occured
264
static int handle_default_option(void *in_ctx, const char *group_name,
265
int handle_default_option(void *in_ctx, const char *group_name,
268
269
struct handle_option_ctx *ctx= (struct handle_option_ctx *) in_ctx;
273
274
if (find_type((char *)group_name, ctx->group, 3))
275
if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
276
if (!(tmp= (char *)alloc_root(ctx->alloc, strlen(option) + 1)))
277
278
if (insert_dynamic(ctx->args, (unsigned char*) &tmp))
279
my_stpcpy(tmp, option);
392
393
(*argc + 1)*sizeof(char*))))
394
395
res= (char**) (ptr+sizeof(alloc));
396
memset(res,0,(*argc + 1));
395
397
res[0]= **argv; /* Copy program name */
396
for (i=2 ; i < (uint) *argc ; i++)
398
for (i=2 ; i < (uint32_t) *argc ; i++)
397
399
res[i-1]=argv[0][i];
398
400
res[i-1]=0; /* End pointer */
558
559
search_default_file_with_ext()
559
560
opt_handler Option handler function. It is used to process
560
561
every separate option.
561
handler_ctx Pointer to the structure to store actual
562
handler_ctx Pointer to the structure to store actual
562
563
parameters of the function.
563
564
dir directory to read
564
565
ext Extension for configuration file
599
600
end=convert_dirname(name, dir, NULL);
600
601
if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */
602
strxmov(end,config_file,ext,NULL);
603
sprintf(end,"%s%s",config_file,ext);
606
my_stpcpy(name,config_file);
607
strcpy(name,config_file);
608
609
fn_format(name,name,"","",4);
614
615
Ignore world-writable regular files.
615
616
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.
617
the mysqld server, but the check is still valid in most context.
618
619
if ((stat_info.st_mode & S_IWOTH) &&
619
620
(stat_info.st_mode & S_IFMT) == S_IFREG)
626
if (!(fp= my_fopen(name, O_RDONLY, MYF(0))))
627
if (!(fp= fopen(name, "r")))
627
628
return 1; /* Ignore wrong files */
630
memset(buff,0,sizeof(buff));
629
631
while (fgets(buff, sizeof(buff) - 1, fp))
642
644
if (recursion_level >= max_recursion_level)
644
for (end= ptr + strlen(ptr) - 1;
646
for (end= ptr + strlen(ptr) - 1;
645
647
my_isspace(&my_charset_utf8_general_ci, *(end - 1));
669
671
if (!(search_dir= my_dir(ptr, MYF(MY_WME))))
672
for (i= 0; i < (uint) search_dir->number_off_files; i++)
674
for (i= 0; i < (uint32_t) search_dir->number_off_files; i++)
674
676
search_file= search_dir->dir_entry + i;
675
677
ext= fn_ext(search_file->name);
722
724
for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
725
strmake(curr_gr, ptr, cmin((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
727
strncpy(curr_gr, ptr, cmin((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
728
curr_gr[cmin((size_t)(end-ptr)+1, sizeof(curr_gr)-1)] = '\0';
727
730
/* signal that a new group is found */
728
731
opt_handler(handler_ctx, curr_gr, NULL);
741
744
end= remove_end_comment(ptr);
742
745
if ((value= strchr(ptr, '=')))
743
746
end= value; /* Option without argument */
744
for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) ; end--) ;
747
for ( ; my_isspace(&my_charset_utf8_general_ci,end[-1]) || end[-1]== '\n'; end--) ;
747
strmake(my_stpcpy(option,"--"),ptr, (size_t) (end-ptr));
750
strncpy(strcpy(option,"--")+2,ptr,strlen(ptr)+1);
748
751
if (opt_handler(handler_ctx, curr_gr, option))
755
758
for (value++ ; my_isspace(&my_charset_utf8_general_ci,*value); value++) ;
756
759
value_end= strchr(value, '\0');
758
We don't have to test for value_end >= value as we know there is
761
We don't have to test for value_end >= value as we know there is
761
764
for ( ; my_isspace(&my_charset_utf8_general_ci,value_end[-1]) ; value_end--) ;
762
765
if (value_end < value) /* Empty string */
765
768
/* remove quotes around argument */
766
769
if ((*value == '\"' || *value == '\'') && /* First char is quote */
767
770
(value + 1 < value_end ) && /* String is longer than 1 */
768
771
*value == value_end[-1] ) /* First char is equal to last char */
773
ptr=my_stpncpy(my_stpcpy(option,"--"),ptr,(size_t) (end-ptr));
777
memset(option,0,2+(size_t)(end-ptr)+1);
778
ptr= strncpy(strcpy(option,"--")+2,ptr,(size_t) (end-ptr));
776
783
for ( ; value != value_end; value++)
880
888
end= convert_dirname(name, pos, NULL);
881
889
if (name[0] == FN_HOMELIB) /* Add . to filenames in home */
883
strxmov(end, conf_file, *ext, " ", NULL);
891
sprintf(end,"%s%s ",conf_file, *ext);
884
892
fputs(name,stdout);
951
959
memset(default_directories, 0, sizeof(default_directories));
952
960
ADD_DIRECTORY("/etc/");
953
ADD_DIRECTORY("/etc/mysql/");
954
#if defined(DEFAULT_SYSCONFDIR)
955
ADD_DIRECTORY(DEFAULT_SYSCONFDIR);
961
ADD_DIRECTORY("/etc/drizzle/");
962
ADD_DIRECTORY(SYSCONFDIR);
957
963
ADD_COMMON_DIRECTORIES();
958
964
ADD_DIRECTORY("~/");