Added os::execvpe to stout.

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


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

Branch: refs/heads/master
Commit: bc5ab04d780af836ae8b0d2a9b3a7bf14b80766d
Parents: 5a7f66e
Author: Jie Yu <[email protected]>
Authored: Wed Aug 13 15:50:34 2014 -0700
Committer: Jie Yu <[email protected]>
Committed: Wed Aug 13 20:52:34 2014 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         | 37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bc5ab04d/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 4d67186..5bbf829 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -114,6 +114,22 @@ inline char** environ()
 }
 
 
+// Returns the address of os::environ().
+inline char*** environp()
+{
+  // Accessing the list of environment variables is platform-specific.
+  // On OS X, the 'environ' symbol isn't visible to shared libraries,
+  // so we must use the _NSGetEnviron() function (see 'man environ' on
+  // OS X). On other platforms, it's fine to access 'environ' from
+  // shared libraries.
+#ifdef __APPLE__
+  return _NSGetEnviron();
+#else
+  return &::environ;
+#endif
+}
+
+
 inline hashmap<std::string, std::string> environment()
 {
   char** environ = os::environ();
@@ -578,6 +594,27 @@ inline int system(const std::string& command)
 }
 
 
+// This function is a portable version of execvpe ('p' means searching
+// executable from PATH and 'e' means setting environments). We add
+// this function because it is not available on all systems.
+//
+// NOTE: This function is not thread safe. It is supposed to be used
+// only after fork (when there is only one thread). This function is
+// async signal safe.
+inline int execvpe(const char* file, char** argv, char** envp)
+{
+  char** saved = os::environ();
+
+  *os::environp() = envp;
+
+  int result = execvp(file, argv);
+
+  *os::environp() = saved;
+
+  return result;
+}
+
+
 // Changes the specified path's user and group ownership to that of
 // the specified user..
 inline Try<Nothing> chown(

Reply via email to