Repository: mesos
Updated Branches:
  refs/heads/master 437e7018e -> adecbfa6a


Exposed environment variables LIBPROCESS_ADVERTISE_IP and
LIBPROCESS_ADVERTISE_PORT.

If not set, libprocess defaults to the IP and port on which it binds.

Review: https://reviews.apache.org/r/34128


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/13e982ee
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/13e982ee
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/13e982ee

Branch: refs/heads/master
Commit: 13e982ee902fa41a540fa64b912bcfb9f37701ba
Parents: 437e701
Author: Anindya Sinha <[email protected]>
Authored: Thu Aug 13 10:11:31 2015 -0700
Committer: Vinod Kone <[email protected]>
Committed: Thu Aug 13 10:15:13 2015 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/process.cpp | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/13e982ee/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp 
b/3rdparty/libprocess/src/process.cpp
index 22a1245..755187c 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -86,6 +86,7 @@
 #include <stout/foreach.hpp>
 #include <stout/lambda.hpp>
 #include <stout/net.hpp>
+#include <stout/numify.hpp>
 #include <stout/option.hpp>
 #include <stout/os.hpp>
 #include <stout/path.hpp>
@@ -868,11 +869,12 @@ void initialize(const string& delegate)
   // Check environment for port.
   value = os::getenv("LIBPROCESS_PORT");
   if (value.isSome()) {
-    const int result = atoi(value.get().c_str());
-    if (result < 0 || result > USHRT_MAX) {
+    Try<int> result = numify<int>(value.get().c_str());
+    if (result.isSome() && result.get() >=0 && result.get() <= USHRT_MAX) {
+      __address__.port = result.get();
+    } else {
       LOG(FATAL) << "LIBPROCESS_PORT=" << value.get() << " is not a valid 
port";
     }
-    __address__.port = result;
   }
 
   // Create a "server" socket for communicating.
@@ -895,6 +897,28 @@ void initialize(const string& delegate)
 
   __address__ = bind.get();
 
+  // If advertised IP and port are present, use them instead.
+  value = os::getenv("LIBPROCESS_ADVERTISE_IP");
+  if (value.isSome()) {
+    Try<net::IP> ip = net::IP::parse(value.get(), AF_INET);
+    if (ip.isError()) {
+      LOG(FATAL) << "Parsing LIBPROCESS_ADVERTISE_IP=" << value.get()
+                 << " failed: " << ip.error();
+    }
+    __address__.ip = ip.get();
+  }
+
+  value = os::getenv("LIBPROCESS_ADVERTISE_PORT");
+  if (value.isSome()) {
+    Try<int> result = numify<int>(value.get().c_str());
+    if (result.isSome() && result.get() >=0 && result.get() <= USHRT_MAX) {
+      __address__.port = result.get();
+    } else {
+      LOG(FATAL) << "LIBPROCESS_ADVERTISE_PORT=" << value.get()
+                 << " is not a valid port";
+    }
+  }
+
   // Lookup hostname if missing ip or if ip is 0.0.0.0 in case we
   // actually have a valid external ip address. Note that we need only
   // one ip address, so that other processes can send and receive and

Reply via email to