You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2014/02/13 22:52:21 UTC
[4/5] git commit: Fixed clang compilation errors in containerizer
files.
Fixed clang compilation errors in containerizer files.
Review: https://reviews.apache.org/r/18090
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/02a17d88
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/02a17d88
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/02a17d88
Branch: refs/heads/master
Commit: 02a17d8826542b12db1ca3c2668102d7a1763ee8
Parents: 8b794cd
Author: Ian Downes <ia...@gmail.com>
Authored: Thu Feb 13 13:41:09 2014 -0800
Committer: Vinod Kone <vi...@twitter.com>
Committed: Thu Feb 13 13:51:59 2014 -0800
----------------------------------------------------------------------
src/slave/containerizer/cgroups_launcher.cpp | 82 ++++++++++----------
src/slave/containerizer/launcher.cpp | 24 +++---
src/slave/containerizer/mesos_containerizer.cpp | 12 +--
src/slave/containerizer/mesos_containerizer.hpp | 2 +-
4 files changed, 64 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/02a17d88/src/slave/containerizer/cgroups_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/cgroups_launcher.cpp b/src/slave/containerizer/cgroups_launcher.cpp
index 0921d63..a9b0108 100644
--- a/src/slave/containerizer/cgroups_launcher.cpp
+++ b/src/slave/containerizer/cgroups_launcher.cpp
@@ -160,44 +160,7 @@ Try<pid_t> CgroupsLauncher::fork(
return ErrnoError("Failed to fork");
}
- if (pid > 0) {
- // In parent.
- os::close(pipes[0]);
-
- // Move the child into the freezer cgroup. Any grandchildren will also be
- // contained in the cgroup.
- Try<Nothing> assign = cgroups::assign(hierarchy, cgroup(containerId), pid);
-
- if (assign.isError()) {
- LOG(ERROR) << "Failed to assign process " << pid
- << " of container '" << containerId << "'"
- << " to its freezer cgroup: " << assign.error();
- kill(pid, SIGKILL);
- return Error("Failed to contain process");
- }
-
- // Now that we've contained the child we can signal it to continue by
- // writing to the pipe.
- int buf;
- ssize_t len;
- while ((len = write(pipes[1], &buf, sizeof(buf))) == -1 && errno == EINTR);
-
- if (len != sizeof(buf)) {
- // Ensure the child is killed.
- kill(pid, SIGKILL);
- os::close(pipes[1]);
- return Error("Failed to synchronize child process");
- }
- os::close(pipes[1]);
-
- // Store the pid (session id and process group id) if this is the first
- // process forked for this container.
- if (!pids.contains(containerId)) {
- pids.put(containerId, pid);
- }
-
- return pid;
- } else {
+ if (pid == 0) {
// In child.
os::close(pipes[1]);
@@ -237,8 +200,49 @@ Try<pid_t> CgroupsLauncher::fork(
// This function should exec() and therefore not return.
inChild();
- return UNREACHABLE();
+ const char* message = "Child failed to exec";
+ while (write(STDERR_FILENO, message, strlen(message)) == -1 &&
+ errno == EINTR);
+
+ _exit(1);
}
+
+ // Parent.
+ os::close(pipes[0]);
+
+ // Move the child into the freezer cgroup. Any grandchildren will also be
+ // contained in the cgroup.
+ Try<Nothing> assign = cgroups::assign(hierarchy, cgroup(containerId), pid);
+
+ if (assign.isError()) {
+ LOG(ERROR) << "Failed to assign process " << pid
+ << " of container '" << containerId << "'"
+ << " to its freezer cgroup: " << assign.error();
+ kill(pid, SIGKILL);
+ return Error("Failed to contain process");
+ }
+
+ // Now that we've contained the child we can signal it to continue by
+ // writing to the pipe.
+ int buf;
+ ssize_t len;
+ while ((len = write(pipes[1], &buf, sizeof(buf))) == -1 && errno == EINTR);
+
+ if (len != sizeof(buf)) {
+ // Ensure the child is killed.
+ kill(pid, SIGKILL);
+ os::close(pipes[1]);
+ return Error("Failed to synchronize child process");
+ }
+ os::close(pipes[1]);
+
+ // Store the pid (session id and process group id) if this is the first
+ // process forked for this container.
+ if (!pids.contains(containerId)) {
+ pids.put(containerId, pid);
+ }
+
+ return pid;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/02a17d88/src/slave/containerizer/launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/launcher.cpp b/src/slave/containerizer/launcher.cpp
index ddfa91c..2361a20 100644
--- a/src/slave/containerizer/launcher.cpp
+++ b/src/slave/containerizer/launcher.cpp
@@ -94,15 +94,7 @@ Try<pid_t> PosixLauncher::fork(
return ErrnoError("Failed to fork");
}
- if (pid > 0) {
- // In parent.
- LOG(INFO) << "Forked child with pid '" << pid
- << "' for container '" << containerId << "'";
- // Store the pid (session id and process group id).
- pids.put(containerId, pid);
-
- return pid;
- } else {
+ if (pid == 0) {
// In child.
// POSIX guarantees a forked child's pid does not match any existing
// process group id so only a single setsid() is required and the session
@@ -117,8 +109,20 @@ Try<pid_t> PosixLauncher::fork(
// This function should exec() and therefore not return.
inChild();
- return UNREACHABLE();
+ const char* message = "Child failed to exec";
+ while (write(STDERR_FILENO, message, strlen(message)) == -1 &&
+ errno == EINTR);
+
+ _exit(1);
}
+
+ // parent.
+ LOG(INFO) << "Forked child with pid '" << pid
+ << "' for container '" << containerId << "'";
+ // Store the pid (session id and process group id).
+ pids.put(containerId, pid);
+
+ return pid;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/02a17d88/src/slave/containerizer/mesos_containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos_containerizer.cpp b/src/slave/containerizer/mesos_containerizer.cpp
index 269aa35..6d990cb 100644
--- a/src/slave/containerizer/mesos_containerizer.cpp
+++ b/src/slave/containerizer/mesos_containerizer.cpp
@@ -217,7 +217,7 @@ Future<Nothing> MesosContainerizerProcess::_recover(
CHECK_SOME(run.forkedPid);
Future<Option<int > > status = process::reap(run.forkedPid.get());
statuses[containerId] = status;
- status.onAny(defer(self(), &Self::exited, containerId));
+ status.onAny(defer(self(), &Self::reaped, containerId));
foreach (const Owned<Isolator>& isolator, isolators) {
isolator->watch(containerId)
@@ -325,8 +325,8 @@ int execute(
// If we get here, the execv call failed.
asyncSafeFatal("Failed to execute command");
- // Silence end of non-void function warning.
- return UNREACHABLE();
+ // This should not be reached.
+ return -1;
}
@@ -614,7 +614,7 @@ Future<pid_t> MesosContainerizerProcess::fork(
// again during container destroy.
Future<Option<int> > status = process::reap(pid);
statuses.put(containerId, status);
- status.onAny(defer(self(), &Self::exited, containerId));
+ status.onAny(defer(self(), &Self::reaped, containerId));
return pid;
}
@@ -815,7 +815,7 @@ void MesosContainerizerProcess::_destroy(
if (!future.isReady()) {
promises[containerId]->fail(
"Failed to destroy container: " +
- future.isFailed() ? future.failure() : "discarded future");
+ (future.isFailed() ? future.failure() : "discarded future"));
return;
}
@@ -865,7 +865,7 @@ void MesosContainerizerProcess::__destroy(
}
-void MesosContainerizerProcess::exited(const ContainerID& containerId)
+void MesosContainerizerProcess::reaped(const ContainerID& containerId)
{
if (!promises.contains(containerId)) {
return;
http://git-wip-us.apache.org/repos/asf/mesos/blob/02a17d88/src/slave/containerizer/mesos_containerizer.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos_containerizer.hpp b/src/slave/containerizer/mesos_containerizer.hpp
index 489eaf1..ee1fd30 100644
--- a/src/slave/containerizer/mesos_containerizer.hpp
+++ b/src/slave/containerizer/mesos_containerizer.hpp
@@ -171,7 +171,7 @@ private:
// Call back for when the executor exits. This will trigger container
// destroy.
- void exited(const ContainerID& containerId);
+ void reaped(const ContainerID& containerId);
const Flags flags;
const bool local;