From e0b59ab52b87b8fc15dd5534c3231fdd74843f9f Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 28 Oct 2013 18:23:41 -0700 Subject: [PATCH 1/2] Enable sig-proxy by default in run and attach --- commands.go | 5 ++++- container.go | 6 +----- docs/sources/commandline/cli.rst | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/commands.go b/commands.go index 6987e89583..94528273ec 100644 --- a/commands.go +++ b/commands.go @@ -1324,7 +1324,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error { func (cli *DockerCli) CmdAttach(args ...string) error { cmd := Subcmd("attach", "[OPTIONS] CONTAINER", "Attach to a running container") noStdin := cmd.Bool("nostdin", false, "Do not attach stdin") - proxy := cmd.Bool("sig-proxy", false, "Proxify all received signal to the process (even in non-tty mode)") + proxy := cmd.Bool("sig-proxy", true, "Proxify all received signal to the process (even in non-tty mode)") if err := cmd.Parse(args); err != nil { return nil } @@ -1523,6 +1523,9 @@ func (cli *DockerCli) CmdRun(args ...string) error { flSigProxy := cmd.Lookup("sig-proxy") sigProxy, _ := strconv.ParseBool(flSigProxy.Value.String()) flName := cmd.Lookup("name") + if config.Tty { + sigProxy = false + } var containerIDFile *os.File if len(hostConfig.ContainerIDFile) > 0 { diff --git a/container.go b/container.go index ce0ce479a3..43792d5f00 100644 --- a/container.go +++ b/container.go @@ -109,7 +109,6 @@ var ( ErrContainerStart = errors.New("The container failed to start. Unkown error") ErrContainerStartTimeout = errors.New("The container failed to start due to timed out.") ErrInvalidWorikingDirectory = errors.New("The working directory is invalid. It needs to be an absolute path.") - ErrConflictTtySigProxy = errors.New("TTY mode (-t) already imply signal proxying (-sig-proxy)") ErrConflictAttachDetach = errors.New("Conflicting options: -a and -d") ErrConflictDetachAutoRemove = errors.New("Conflicting options: -rm and -d") ) @@ -167,7 +166,7 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig, flNetwork := cmd.Bool("n", true, "Enable networking for this container") flPrivileged := cmd.Bool("privileged", false, "Give extended privileges to this container") flAutoRemove := cmd.Bool("rm", false, "Automatically remove the container when it exits (incompatible with -d)") - flSigProxy := cmd.Bool("sig-proxy", false, "Proxify all received signal to the process (even in non-tty mode)") + cmd.Bool("sig-proxy", true, "Proxify all received signal to the process (even in non-tty mode)") cmd.String("name", "", "Assign a name to the container") if capabilities != nil && *flMemory > 0 && !capabilities.MemoryLimit { @@ -212,9 +211,6 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig, if *flWorkingDir != "" && !path.IsAbs(*flWorkingDir) { return nil, nil, cmd, ErrInvalidWorikingDirectory } - if *flTty && *flSigProxy { - return nil, nil, cmd, ErrConflictTtySigProxy - } if *flDetach && *flAutoRemove { return nil, nil, cmd, ErrConflictDetachAutoRemove } diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index 0badcd67c1..6efa9b1ebb 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -30,7 +30,7 @@ To list available commands, either run ``docker`` with no parameters or execute Attach to a running container. -nostdin=false: Do not attach stdin - -sig-proxy=false: Proxify all received signal to the process (even in non-tty mode) + -sig-proxy=true: Proxify all received signal to the process (even in non-tty mode) You can detach from the container again (and leave it running) with ``CTRL-c`` (for a quiet exit) or ``CTRL-\`` to get a stacktrace of @@ -575,7 +575,7 @@ network communication. -entrypoint="": Overwrite the default entrypoint set by the image -w="": Working directory inside the container -lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1" - -sig-proxy=false: Proxify all received signal to the process (even in non-tty mode) + -sig-proxy=true: Proxify all received signal to the process (even in non-tty mode) -expose=[]: Expose a port from the container without publishing it to your host -link="": Add link to another container (name:alias) -name="": Assign the specified name to the container. If no name is specific docker will generate a random name From 700a71e6b62a3786d11719ae30cacd0f90930525 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 29 Oct 2013 11:59:08 -0700 Subject: [PATCH 2/2] stop proxy at one point --- commands.go | 12 ++++++++---- utils/signal.go | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 utils/signal.go diff --git a/commands.go b/commands.go index 94528273ec..4a7c4b8d23 100644 --- a/commands.go +++ b/commands.go @@ -540,7 +540,7 @@ func (cli *DockerCli) CmdRestart(args ...string) error { return nil } -func (cli *DockerCli) forwardAllSignals(cid string) { +func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal { sigc := make(chan os.Signal, 1) utils.CatchAll(sigc) go func() { @@ -550,6 +550,7 @@ func (cli *DockerCli) forwardAllSignals(cid string) { } } }() + return sigc } func (cli *DockerCli) CmdStart(args ...string) error { @@ -582,7 +583,8 @@ func (cli *DockerCli) CmdStart(args ...string) error { } if !container.Config.Tty { - cli.forwardAllSignals(cmd.Arg(0)) + sigc := cli.forwardAllSignals(cmd.Arg(0)) + defer utils.StopCatch(sigc) } if container.Config.Tty && cli.isTerminal { @@ -1366,7 +1368,8 @@ func (cli *DockerCli) CmdAttach(args ...string) error { v.Set("stderr", "1") if *proxy && !container.Config.Tty { - cli.forwardAllSignals(cmd.Arg(0)) + sigc := cli.forwardAllSignals(cmd.Arg(0)) + defer utils.StopCatch(sigc) } if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, in, cli.out, cli.err, nil); err != nil { @@ -1611,7 +1614,8 @@ func (cli *DockerCli) CmdRun(args ...string) error { } if sigProxy { - cli.forwardAllSignals(runResult.ID) + sigc := cli.forwardAllSignals(runResult.ID) + defer utils.StopCatch(sigc) } var ( diff --git a/utils/signal.go b/utils/signal.go new file mode 100644 index 0000000000..0cac7d113f --- /dev/null +++ b/utils/signal.go @@ -0,0 +1,11 @@ +package utils + +import ( + "os" + "os/signal" +) + +func StopCatch(sigc chan os.Signal) { + signal.Stop(sigc) + close(sigc) +}