You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/05/15 21:31:59 UTC
svn commit: r1338850 - /incubator/mesos/trunk/src/common/webui_utils.cpp
Author: benh
Date: Tue May 15 19:31:58 2012
New Revision: 1338850
URL: http://svn.apache.org/viewvc?rev=1338850&view=rev
Log:
Run bottle in a separate process to avoid races with dlopen/Python (https://reviews.apache.org/r/5116).
Modified:
incubator/mesos/trunk/src/common/webui_utils.cpp
Modified: incubator/mesos/trunk/src/common/webui_utils.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/common/webui_utils.cpp?rev=1338850&r1=1338849&r2=1338850&view=diff
==============================================================================
--- incubator/mesos/trunk/src/common/webui_utils.cpp (original)
+++ incubator/mesos/trunk/src/common/webui_utils.cpp Tue May 15 19:31:58 2012
@@ -1,6 +1,10 @@
#ifdef MESOS_WEBUI
#include <Python.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/uio.h>
#include <tr1/functional>
@@ -54,6 +58,16 @@ static void run(const std::string& direc
}
+void wait(int fd)
+{
+ char temp[8];
+ if (read(fd, temp, 8) == -1) {
+ PLOG(FATAL) << "Failed to read on pipe from parent";
+ }
+ exit(1);
+}
+
+
void start(const Configuration& conf,
const std::string& script,
const std::vector<std::string>& args)
@@ -84,9 +98,31 @@ void start(const Configuration& conf,
// interpreter errors (and maybe even remove the need for two C-c to
// exit the process).
- if (!thread::start(std::tr1::bind(&run, directory, script, args), true)) {
- LOG(FATAL) << "Failed to start webui thread";
+ int pipes[2];
+ pipe(pipes);
+
+ pid_t pid;
+ if ((pid = fork()) == -1) {
+ PLOG(FATAL) << "Failed to fork to launch new executor";
}
+
+ if (pid) {
+ // In parent process.
+ close(pipes[0]); // Close the reader end in the parent.
+ } else {
+ // In child process.
+ close(pipes[1]); // Close the writer end in the child.
+
+ if (!thread::start(std::tr1::bind(&wait, pipes[0]), true)) {
+ LOG(FATAL) << "Failed to start wait thread";
+ }
+
+ run(directory, script, args);
+ }
+
+// if (!thread::start(std::tr1::bind(&run, directory, script, args), true)) {
+// LOG(FATAL) << "Failed to start webui thread";
+// }
}
} // namespace webui {