uint my_get_large_page_size_int(void) { MYSQL_FILE *f; uint size = 0; char buf[256]; DBUG_ENTER("my_get_large_page_size_int"); if (!(f= mysql_file_fopen(key_file_proc_meminfo, "/proc/meminfo", O_RDONLY, MYF(MY_WME)))) goto finish; while (mysql_file_fgets(buf, sizeof(buf), f)) if (sscanf(buf, "Hugepagesize: %u kB", &size)) break; mysql_file_fclose(f, MYF(MY_WME)); finish: DBUG_RETURN(size * 1024); }
static int search_default_file_with_ext(Process_option_func opt_handler, void *handler_ctx, const char *dir, const char *ext, const char *config_file, int recursion_level) { char name[FN_REFLEN + 10], buff[4096], curr_gr[4096], *ptr, *end, **tmp_ext; char *value, option[4096+2], tmp[FN_REFLEN]; static const char includedir_keyword[]= "includedir"; static const char include_keyword[]= "include"; const int max_recursion_level= 10; MYSQL_FILE *fp; uint line=0; my_bool found_group=0; uint i; MY_DIR *search_dir; FILEINFO *search_file; if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3) return 0; /* Ignore wrong paths */ if (dir) { end=convert_dirname(name, dir, NullS); if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */ *end++='.'; strxmov(end,config_file,ext,NullS); } else { strmov(name,config_file); } fn_format(name,name,"","",4); #if !defined(__WIN__) { MY_STAT stat_info; if (!my_stat(name,&stat_info,MYF(0))) return 1; /* Ignore world-writable regular files. This is mainly done to protect us to not read a file created by the mysqld server, but the check is still valid in most context. */ if ((stat_info.st_mode & S_IWOTH) && (stat_info.st_mode & S_IFMT) == S_IFREG) { fprintf(stderr, "Warning: World-writable config file '%s' is ignored\n", name); return 0; } } #endif if (!(fp= mysql_file_fopen(key_file_cnf, name, O_RDONLY, MYF(0)))) return 1; /* Ignore wrong files */ while (mysql_file_fgets(buff, sizeof(buff) - 1, fp)) { line++; /* Ignore comment and empty lines */ for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++) {} if (*ptr == '#' || *ptr == ';' || !*ptr) continue; /* Configuration File Directives */ if (*ptr == '!') { if (recursion_level >= max_recursion_level) { for (end= ptr + strlen(ptr) - 1; my_isspace(&my_charset_latin1, *(end - 1)); end--) {} end[0]= 0; fprintf(stderr, "Warning: skipping '%s' directive as maximum include" "recursion level was reached in file %s at line %d\n", ptr, name, line); continue; } /* skip over `!' and following whitespace */ for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++) {} if ((!strncmp(ptr, includedir_keyword, sizeof(includedir_keyword) - 1)) && my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1])) { if (!(ptr= get_argument(includedir_keyword, sizeof(includedir_keyword), ptr, name, line))) goto err; if (!(search_dir= my_dir(ptr, MYF(MY_WME)))) goto err; for (i= 0; i < (uint) search_dir->number_of_files; i++) { search_file= search_dir->dir_entry + i; ext= fn_ext(search_file->name); /* check extension */ for (tmp_ext= (char**) f_extensions; *tmp_ext; tmp_ext++) { if (!strcmp(ext, *tmp_ext)) break; } if (*tmp_ext) { fn_format(tmp, search_file->name, ptr, "", MY_UNPACK_FILENAME | MY_SAFE_PATH); search_default_file_with_ext(opt_handler, handler_ctx, "", "", tmp, recursion_level + 1); } } my_dirend(search_dir); } else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) && my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1])) { if (!(ptr= get_argument(include_keyword, sizeof(include_keyword), ptr, name, line))) goto err; search_default_file_with_ext(opt_handler, handler_ctx, "", "", ptr, recursion_level + 1); } continue; } if (*ptr == '[') /* Group name */ { found_group=1; if (!(end=(char *) strchr(++ptr,']'))) { fprintf(stderr, "error: Wrong group definition in config file: %s at line %d\n", name,line); goto err; } /* Remove end space */ for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ; end[0]=0; strmake(curr_gr, ptr, MY_MIN((size_t) (end-ptr)+1, sizeof(curr_gr)-1)); /* signal that a new group is found */ opt_handler(handler_ctx, curr_gr, NULL); continue; } if (!found_group) { fprintf(stderr, "error: Found option without preceding group in config file: %s at line: %d\n", name,line); goto err; } end= remove_end_comment(ptr); if ((value= strchr(ptr, '='))) end= value; /* Option without argument */ for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ; if (!value) { strmake(strmov(option,"--"),ptr, (size_t) (end-ptr)); if (opt_handler(handler_ctx, curr_gr, option)) goto err; } else { /* Remove pre- and end space */ char *value_end; for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ; value_end=strend(value); /* We don't have to test for value_end >= value as we know there is an '=' before */ for ( ; my_isspace(&my_charset_latin1,value_end[-1]) ; value_end--) ; if (value_end < value) /* Empty string */ value_end=value; /* remove quotes around argument */ if ((*value == '\"' || *value == '\'') && /* First char is quote */ (value + 1 < value_end ) && /* String is longer than 1 */ *value == value_end[-1] ) /* First char is equal to last char */ { value++; value_end--; } ptr=strnmov(strmov(option,"--"),ptr,(size_t) (end-ptr)); *ptr++= '='; for ( ; value != value_end; value++) { if (*value == '\\' && value != value_end-1) { switch(*++value) { case 'n': *ptr++='\n'; break; case 't': *ptr++= '\t'; break; case 'r': *ptr++ = '\r'; break; case 'b': *ptr++ = '\b'; break; case 's': *ptr++= ' '; /* space */ break; case '\"': *ptr++= '\"'; break; case '\'': *ptr++= '\''; break; case '\\': *ptr++= '\\'; break; default: /* Unknown; Keep '\' */ *ptr++= '\\'; *ptr++= *value; break; } } else *ptr++= *value; } *ptr=0; if (opt_handler(handler_ctx, curr_gr, option)) goto err; } } mysql_file_fclose(fp, MYF(0)); return(0); err: mysql_file_fclose(fp, MYF(0)); return -1; /* Fatal error */ }