Commit f7f9c5c1 authored by unknown's avatar unknown

Merge tulin@bk-internal.mysql.com:/home/bk/mysql-4.1

into poseidon.ndb.mysql.com:/home/tomas/mysql-4.1
parents 8dee7c7e 13cf98b5
...@@ -53,14 +53,14 @@ struct LocalConfig { ...@@ -53,14 +53,14 @@ struct LocalConfig {
void printUsage() const; void printUsage() const;
void setError(int lineNumber, const char * _msg); void setError(int lineNumber, const char * _msg);
bool readConnectString(const char *); bool readConnectString(const char *, const char *info);
bool readFile(const char * file, bool &fopenError); bool readFile(const char * file, bool &fopenError);
bool parseLine(char * line, int lineNumber); bool parseLine(char * line, int lineNumber);
bool parseNodeId(const char *buf); bool parseNodeId(const char *buf);
bool parseHostName(const char *buf); bool parseHostName(const char *buf);
bool parseFileName(const char *buf); bool parseFileName(const char *buf);
bool parseString(const char *buf, char *line); bool parseString(const char *buf, BaseString &err);
}; };
#endif // LocalConfig_H #endif // LocalConfig_H
......
...@@ -40,7 +40,7 @@ LocalConfig::init(const char *connectString, ...@@ -40,7 +40,7 @@ LocalConfig::init(const char *connectString,
//1. Check connectString //1. Check connectString
if(connectString != 0 && connectString[0] != 0){ if(connectString != 0 && connectString[0] != 0){
if(readConnectString(connectString)){ if(readConnectString(connectString, "connect string")){
return true; return true;
} }
return false; return false;
...@@ -59,7 +59,7 @@ LocalConfig::init(const char *connectString, ...@@ -59,7 +59,7 @@ LocalConfig::init(const char *connectString,
char buf[255]; char buf[255];
if(NdbEnv_GetEnv("NDB_CONNECTSTRING", buf, sizeof(buf)) && if(NdbEnv_GetEnv("NDB_CONNECTSTRING", buf, sizeof(buf)) &&
strlen(buf) != 0){ strlen(buf) != 0){
if(readConnectString(buf)){ if(readConnectString(buf, "NDB_CONNECTSTRING")){
return true; return true;
} }
return false; return false;
...@@ -91,7 +91,7 @@ LocalConfig::init(const char *connectString, ...@@ -91,7 +91,7 @@ LocalConfig::init(const char *connectString,
{ {
char buf[256]; char buf[256];
snprintf(buf, sizeof(buf), "host=localhost:%s", NDB_BASE_PORT); snprintf(buf, sizeof(buf), "host=localhost:%s", NDB_BASE_PORT);
if(readConnectString(buf)) if(readConnectString(buf, "default connect string"))
return true; return true;
} }
...@@ -109,8 +109,10 @@ void LocalConfig::setError(int lineNumber, const char * _msg) { ...@@ -109,8 +109,10 @@ void LocalConfig::setError(int lineNumber, const char * _msg) {
} }
void LocalConfig::printError() const { void LocalConfig::printError() const {
ndbout << "Local configuration error"<< endl ndbout << "Configuration error" << endl;
<< "Line: "<< error_line << ", " << error_msg << endl << endl; if (error_line)
ndbout << "Line: "<< error_line << ", ";
ndbout << error_msg << endl << endl;
} }
void LocalConfig::printUsage() const { void LocalConfig::printUsage() const {
...@@ -140,7 +142,7 @@ const char *nodeIdTokens[] = { ...@@ -140,7 +142,7 @@ const char *nodeIdTokens[] = {
const char *hostNameTokens[] = { const char *hostNameTokens[] = {
"host://%[^:]:%i", "host://%[^:]:%i",
"host=%[^:]:%i", "host=%[^:]:%i",
"%[^:]:%i", "%[^:^=^ ]:%i",
"%s %i", "%s %i",
0 0
}; };
...@@ -192,7 +194,7 @@ LocalConfig::parseFileName(const char * buf){ ...@@ -192,7 +194,7 @@ LocalConfig::parseFileName(const char * buf){
} }
bool bool
LocalConfig::parseString(const char * connectString, char *line){ LocalConfig::parseString(const char * connectString, BaseString &err){
char * for_strtok; char * for_strtok;
char * copy = strdup(connectString); char * copy = strdup(connectString);
NdbAutoPtr<char> tmp_aptr(copy); NdbAutoPtr<char> tmp_aptr(copy);
...@@ -212,15 +214,12 @@ LocalConfig::parseString(const char * connectString, char *line){ ...@@ -212,15 +214,12 @@ LocalConfig::parseString(const char * connectString, char *line){
if (found_other = parseFileName(tok)) if (found_other = parseFileName(tok))
continue; continue;
if (line) err.assfmt("Unexpected entry: \"%s\"", tok);
snprintf(line, 150, "Unexpected entry: \"%s\"", tok);
return false; return false;
} }
if (!found_other) { if (!found_other) {
if (line) err.appfmt("Missing host/file name extry in \"%s\"", connectString);
snprintf(line, 150, "Missing host/file name extry in \"%s\"",
connectString);
return false; return false;
} }
...@@ -235,7 +234,8 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError) ...@@ -235,7 +234,8 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
FILE * file = fopen(filename, "r"); FILE * file = fopen(filename, "r");
if(file == 0){ if(file == 0){
snprintf(line, 150, "Unable to open local config file: %s", filename); snprintf(line, sizeof(line),
"Unable to open local config file: %s", filename);
setError(0, line); setError(0, line);
fopenError = true; fopenError = true;
return false; return false;
...@@ -243,7 +243,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError) ...@@ -243,7 +243,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
BaseString theString; BaseString theString;
while(fgets(line, 1024, file)){ while(fgets(line, sizeof(line), file)){
BaseString tmp(line); BaseString tmp(line);
tmp.trim(" \t\n\r"); tmp.trim(" \t\n\r");
if(tmp.length() > 0 && tmp.c_str()[0] != '#'){ if(tmp.length() > 0 && tmp.c_str()[0] != '#'){
...@@ -251,7 +251,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError) ...@@ -251,7 +251,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
break; break;
} }
} }
while (fgets(line, 1024, file)) { while (fgets(line, sizeof(line), file)) {
BaseString tmp(line); BaseString tmp(line);
tmp.trim(" \t\n\r"); tmp.trim(" \t\n\r");
if(tmp.length() > 0 && tmp.c_str()[0] != '#'){ if(tmp.length() > 0 && tmp.c_str()[0] != '#'){
...@@ -260,11 +260,12 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError) ...@@ -260,11 +260,12 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
} }
} }
bool return_value = parseString(theString.c_str(), line); BaseString err;
bool return_value = parseString(theString.c_str(), err);
if (!return_value) { if (!return_value) {
BaseString tmp; BaseString tmp;
tmp.assfmt("Reading %s: %s", filename, line); tmp.assfmt("Reading %s: %s", filename, err.c_str());
setError(0, tmp.c_str()); setError(0, tmp.c_str());
} }
...@@ -273,12 +274,14 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError) ...@@ -273,12 +274,14 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError)
} }
bool bool
LocalConfig::readConnectString(const char * connectString){ LocalConfig::readConnectString(const char * connectString,
char line[150], line2[150]; const char * info){
bool return_value = parseString(connectString, line); BaseString err;
bool return_value = parseString(connectString, err);
if (!return_value) { if (!return_value) {
snprintf(line2, 150, "Reading NDB_CONNECTSTRING \"%s\": %s", connectString, line); BaseString err2;
setError(0,line2); err2.assfmt("Reading %d \"%s\": %s", info, connectString, err.c_str());
setError(0,err2.c_str());
} }
return return_value; return return_value;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment