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