dotcloud/docker — pull request #1249 by unclejack (2013-07-20 10:56:54+00:00)
Title: #507 - make docker run handle SIGINT/SIGTERM

This PR adds SIGTERM and SIGINT handling to docker run. When any of the two signals is received by a `docker run` process, `docker stop` will be run to try to stop the container. If the container fails to stop graciously in 4 seconds, it's killed by `docker stop`.

Observations:

1. `docker stop` isn't called, the CmdStop function is called instead to avoid duplicating any code.
2. This PR doesn't break signal handling for bash running in a container (e.g.: `docker run -i -t ubuntu bash.. ^c).
3. There's an issue with sending a SIGTERM/SIGINT to something which has set up a TTY:

```
$ docker run -i -t ubuntu bash
root@8158df67a66a:/#
Received signal: interrupt; cleaning up
bk@bkm:~$
```

Questions:

1. What SIGKILL timeout should be set for `docker stop`?
2. How should the TTY issue be fixed?
3. What other changes should be made?
4. How could we test this?