diff options
author | root <root@mongotest1.peerpong.net> | 2010-09-22 17:18:27 +0000 |
---|---|---|
committer | Mathias Stearn <redbeard0531@gmail.com> | 2010-09-27 18:23:33 -0400 |
commit | 1cefd8cc5dbd9901b9de21c3e07dcefdca172d3e (patch) | |
tree | 92beaed0b99b35ed874e417ce230d48be65c0072 | |
parent | 14baf5f3c95b0be9057fece5e0380a1627d2f9f6 (diff) | |
download | mongo-1cefd8cc5dbd9901b9de21c3e07dcefdca172d3e.tar.gz |
Make hostname.me() smarter
Use hostname.me() when creating a repl config from scratch
bug #SERVER-1813
http://jira.mongodb.org/browse/SERVER-1813
-rw-r--r-- | db/repl/rs_initiate.cpp | 2 | ||||
-rw-r--r-- | util/hostandport.h | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/db/repl/rs_initiate.cpp b/db/repl/rs_initiate.cpp index 9c74be08df6..41bf8d87fd8 100644 --- a/db/repl/rs_initiate.cpp +++ b/db/repl/rs_initiate.cpp @@ -187,7 +187,7 @@ namespace mongo { bob b; b.append("_id", name); bob members; - members.append("0", BSON( "_id" << 0 << "host" << HostAndPort::Me().toString() )); + members.append("0", BSON( "_id" << 0 << "host" << HostAndPort::me().toString() )); for( unsigned i = 0; i < seeds.size(); i++ ) members.append(bob::numStr(i+1), BSON( "_id" << i+1 << "host" << seeds[i].toString())); b.appendArray("members", members.obj()); diff --git a/util/hostandport.h b/util/hostandport.h index 61245700501..a0a7196855f 100644 --- a/util/hostandport.h +++ b/util/hostandport.h @@ -43,6 +43,22 @@ namespace mongo { } static HostAndPort me() { + const char* ips = string(cmdLine.bind_ip).c_str(); + while(*ips){ + string ip; + const char * comma = strchr(ips, ','); + if (comma){ + ip = string(ips, comma - ips); + ips = comma + 1; + }else{ + ip = string(ips); + ips = ""; + } + HostAndPort h = HostAndPort(ip, cmdLine.port); + if (!h.isLocalHost()) { + return h; + } + } return HostAndPort("localhost", cmdLine.port); } |