You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by kl...@apache.org on 2018/10/02 11:40:02 UTC
[mesos] branch 1.5.x updated (4010b2d -> fcd52ec)
This is an automated email from the ASF dual-hosted git repository.
klueska pushed a change to branch 1.5.x
in repository https://gitbox.apache.org/repos/asf/mesos.git.
from 4010b2d Added MESOS-9279 to 1.5.2 CHANGELOG.
new 0ebf8e3 Added the ability to launch tasks with a TTY attached to mesos-execute.
new fcd52ec Removed call to 'setsid()' in command executor if TTY attached.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/cli/execute.cpp | 20 ++++++++++++++++++--
src/launcher/executor.cpp | 22 +++++++++++++++++++---
src/slave/containerizer/mesos/io/switchboard.cpp | 7 +++++++
3 files changed, 44 insertions(+), 5 deletions(-)
[mesos] 02/02: Removed call to 'setsid()' in command executor if
TTY attached.
Posted by kl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
klueska pushed a commit to branch 1.5.x
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit fcd52ec6f46d54a7140d524bdd37b9a92d0e5366
Author: Kevin Klues <kl...@gmail.com>
AuthorDate: Tue Oct 2 11:41:12 2018 +0200
Removed call to 'setsid()' in command executor if TTY attached.
Previously, we would unconditionally call 'setsid()' in the command
executor whenever we launched a process. This causes the process it
launches to start a new session and NOT inherit the controlling TTY
from it's parent. This obviously causes problems, if the goal of
attaching a TTY to a task is so that we can actually give it control
of that TTY while it is executing.
Interestingly, even if process does not control its TTY, it can still
read and write from the file descriptors associated with it (it just
can't receive any signals associated with it, such as SIGWINCH,
SIGHUP, etc.). This is why things "appeared" to mostly work until this
point because stdin/stdout/stderr were all being redirected properly
to it.
Where we saw problems was with trying to 'attach' to an already
running process launched via the command executor using the
ATTACH_NESTED_CONTAINER_INPUT/OUTPUT calls. If you ran something like
'bash', you would not be able to do job control, and you could not
resize the screen properly when running things like 'vim'.
This commit fixes this issue by checking to see if a TTY has been
attached to a task launched by the command executor, and skipping the
'setsid()' call when forking it. We considered a number of alternative
approaches, but finally settled on this one since it was the least
invasive. I.e. only tasks launched with a TTY (which is a failry new
concept in Mesos) will be affected by this change; the semantics of
all traditional tasks launched via the command executor will go
unchanged.
Note: this problem does not exists for the default executor because
the agent does the job of launching all containers, and there is no
executor sitting between the containerizer and the actual process of a
task intervening to call an extra 'setsid()'. This is why containers
launched via LAUNCH_NESTED_CONTAINER_SESSION have always worked as
expected.
Review: https://reviews.apache.org/r/68810/
---
src/launcher/executor.cpp | 22 +++++++++++++++++++---
src/slave/containerizer/mesos/io/switchboard.cpp | 7 +++++++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index 794bf7c..f883203 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -125,6 +125,7 @@ public:
const Option<Environment>& _taskEnvironment,
const Option<CapabilityInfo>& _effectiveCapabilities,
const Option<CapabilityInfo>& _boundingCapabilities,
+ const Option<string>& _ttySlavePath,
const FrameworkID& _frameworkId,
const ExecutorID& _executorId,
const Duration& _shutdownGracePeriod)
@@ -148,6 +149,7 @@ public:
taskEnvironment(_taskEnvironment),
effectiveCapabilities(_effectiveCapabilities),
boundingCapabilities(_boundingCapabilities),
+ ttySlavePath(_ttySlavePath),
frameworkId(_frameworkId),
executorId(_executorId),
lastTaskStatus(None()) {}
@@ -399,7 +401,8 @@ protected:
const Option<string>& sandboxDirectory,
const Option<string>& workingDirectory,
const Option<CapabilityInfo>& effectiveCapabilities,
- const Option<CapabilityInfo>& boundingCapabilities)
+ const Option<CapabilityInfo>& boundingCapabilities,
+ const Option<string>& ttySlavePath)
{
// Prepare the flags to pass to the launch process.
slave::MesosContainerizerLaunch::Flags launchFlags;
@@ -487,6 +490,11 @@ protected:
parentHooks.emplace_back(Subprocess::ParentHook::CREATE_JOB());
#endif // __WINDOWS__
+ vector<process::Subprocess::ChildHook> childHooks;
+ if (ttySlavePath.isNone()) {
+ childHooks.emplace_back(Subprocess::ChildHook::SETSID());
+ }
+
Try<Subprocess> s = subprocess(
path::join(launcherDir, MESOS_CONTAINERIZER),
argv,
@@ -497,7 +505,7 @@ protected:
None(),
None(),
parentHooks,
- {Subprocess::ChildHook::SETSID()});
+ childHooks);
if (s.isError()) {
ABORT("Failed to launch '" + commandString + "': " + s.error());
@@ -646,7 +654,8 @@ protected:
sandboxDirectory,
workingDirectory,
effectiveCapabilities,
- boundingCapabilities);
+ boundingCapabilities,
+ ttySlavePath);
LOG(INFO) << "Forked command at " << pid;
@@ -1140,6 +1149,7 @@ private:
Option<Environment> taskEnvironment;
Option<CapabilityInfo> effectiveCapabilities;
Option<CapabilityInfo> boundingCapabilities;
+ Option<string> ttySlavePath;
const FrameworkID frameworkId;
const ExecutorID executorId;
Owned<MesosBase> mesos;
@@ -1199,6 +1209,10 @@ public:
"bounding_capabilities",
"The bounding set of capabilities the command can use.");
+ add(&Flags::tty_slave_path,
+ "tty_slave_path",
+ "A path to the slave end of the attached TTY if there is one.");
+
add(&Flags::launcher_dir,
"launcher_dir",
"Directory path of Mesos binaries.",
@@ -1216,6 +1230,7 @@ public:
Option<Environment> task_environment;
Option<mesos::CapabilityInfo> effective_capabilities;
Option<mesos::CapabilityInfo> bounding_capabilities;
+ Option<string> tty_slave_path;
string launcher_dir;
};
@@ -1293,6 +1308,7 @@ int main(int argc, char** argv)
flags.task_environment,
flags.effective_capabilities,
flags.bounding_capabilities,
+ flags.tty_slave_path,
frameworkId,
executorId,
shutdownGracePeriod));
diff --git a/src/slave/containerizer/mesos/io/switchboard.cpp b/src/slave/containerizer/mesos/io/switchboard.cpp
index df33b0d..cf13b31 100644
--- a/src/slave/containerizer/mesos/io/switchboard.cpp
+++ b/src/slave/containerizer/mesos/io/switchboard.cpp
@@ -439,6 +439,13 @@ Future<Option<ContainerLaunchInfo>> IOSwitchboard::_prepare(
containerIO.err = containerIO.in;
launchInfo.set_tty_slave_path(slavePath.get());
+
+ // The command executor requires the `tty_slave_path`
+ // to also be passed as a command line argument.
+ if (containerConfig.has_task_info()) {
+ launchInfo.mutable_command()->add_arguments(
+ "--tty_slave_path=" + slavePath.get());
+ }
} else {
Try<std::array<int_fd, 2>> infds_ = os::pipe();
if (infds_.isError()) {
[mesos] 01/02: Added the ability to launch tasks with a TTY
attached to mesos-execute.
Posted by kl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
klueska pushed a commit to branch 1.5.x
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 0ebf8e3ad744463f561663a8afdf7886d19edfad
Author: Kevin Klues <kl...@gmail.com>
AuthorDate: Tue Oct 2 11:40:52 2018 +0200
Added the ability to launch tasks with a TTY attached to mesos-execute.
Review: https://reviews.apache.org/r/68724/
---
src/cli/execute.cpp | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/cli/execute.cpp b/src/cli/execute.cpp
index 6e62689..8a23c68 100644
--- a/src/cli/execute.cpp
+++ b/src/cli/execute.cpp
@@ -356,6 +356,11 @@ public:
"and 'protobuf' are valid choices.",
"protobuf");
+ add(&Flags::tty,
+ "tty",
+ "Attach a TTY to the task being launched",
+ false);
+
add(&Flags::partition_aware,
"partition_aware",
"Enable partition-awareness for the framework.",
@@ -390,6 +395,7 @@ public:
Option<string> secret;
string content_type;
bool partition_aware;
+ bool tty;
};
@@ -787,7 +793,8 @@ static Result<ContainerInfo> getContainerInfo(
const Option<string>& dockerImage,
const Option<CapabilityInfo>& effective_capabilities,
const Option<CapabilityInfo>& bounding_capabilities,
- const Option<RLimitInfo>& rlimits)
+ const Option<RLimitInfo>& rlimits,
+ const bool tty)
{
if (containerizer.empty()) {
return None();
@@ -870,6 +877,10 @@ static Result<ContainerInfo> getContainerInfo(
containerInfo.mutable_rlimit_info()->CopyFrom(rlimits.get());
}
+ if (tty) {
+ containerInfo.mutable_tty_info();
+ }
+
return containerInfo;
} else if (containerizer == "docker") {
// 'docker' containerizer only supports 'docker' images.
@@ -892,6 +903,10 @@ static Result<ContainerInfo> getContainerInfo(
}
}
+ if (tty) {
+ return Error("'Docker' containerizer does not allow attaching a TTY");
+ }
+
return containerInfo;
}
@@ -1185,7 +1200,8 @@ int main(int argc, char** argv)
dockerImage,
flags.effective_capabilities,
flags.bounding_capabilities,
- flags.rlimits);
+ flags.rlimits,
+ flags.tty);
if (containerInfo.isError()){
EXIT(EXIT_FAILURE) << containerInfo.error();