From b1b57d20b0ea971f3ddb7879796086ecef482c85 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Sun, 7 Feb 2016 22:33:48 -0500 Subject: [PATCH] Isolating the plugin process from the nomad client --- client/driver/utils.go | 3 +++ client/driver/utils_posix.go | 16 ++++++++++++++++ client/driver/utils_windows.go | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 client/driver/utils_posix.go create mode 100644 client/driver/utils_windows.go diff --git a/client/driver/utils.go b/client/driver/utils.go index e8935c80e..f2f8fc02a 100644 --- a/client/driver/utils.go +++ b/client/driver/utils.go @@ -15,6 +15,9 @@ import ( func createExecutor(config *plugin.ClientConfig, w io.Writer) (executor.Executor, *plugin.Client, error) { config.HandshakeConfig = HandshakeConfig config.Plugins = GetPluginMap(w) + if config.Cmd != nil { + isolateCommand(config.Cmd) + } executorClient := plugin.NewClient(config) rpcClient, err := executorClient.Client() if err != nil { diff --git a/client/driver/utils_posix.go b/client/driver/utils_posix.go new file mode 100644 index 000000000..693bba6f6 --- /dev/null +++ b/client/driver/utils_posix.go @@ -0,0 +1,16 @@ +package driver + +import ( + "os/exec" + "syscall" +) + +// isolateCommand sets the setsid flag in exec.Cmd to true so that the process +// becomes the process leader in a new session and doesn't receive signals that +// are sent to the parent process. +func isolateCommand(cmd *exec.Cmd) { + if cmd.SysProcAttr == nil { + cmd.SysProcAttr = &syscall.SysProcAttr{} + } + cmd.SysProcAttr.Setsid = true +} diff --git a/client/driver/utils_windows.go b/client/driver/utils_windows.go new file mode 100644 index 000000000..5b2b7d842 --- /dev/null +++ b/client/driver/utils_windows.go @@ -0,0 +1,9 @@ +package driver + +import ( + "os/exec" +) + +// TODO Figure out if this is needed in Wondows +func isolateCommand(cmd *exec.Cmd) { +}