diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2018-05-09 14:12:44 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-09 14:13:37 -0700 |
commit | 1bdec86baed82fe8d79100693949f1259636e9db (patch) | |
tree | 97c3983a0099e4018b1b6fe5af4d4d9eb8fc1cef /runsc/main.go | |
parent | 5ed969aff0e9def4018d24436fb77257925f6a1c (diff) |
Return better errors from Docker when runsc fails to start.
Two changes in this CL:
First, make the "boot" process sleep when it encounters an error to give the
controller time to send the error back to the "start" process. Otherwise the
"boot" process exits immediately and the control connection errors with EOF.
Secondly, open the log file with O_APPEND, not O_TRUNC. Docker uses the same
log file for all runtime commands, and setting O_TRUNC causes them to get
destroyed. Furthermore, containerd parses these log files in the event of an
error, and it does not like the file being truncated out from underneath it.
Now, when trying to run a binary that does not exist in the image, the error
message is more reasonable:
$ docker run alpine /not/found
docker: Error response from daemon: OCI runtime start failed: /usr/local/google/docker/runtimes/runscd did not terminate sucessfully: error starting sandbox: error starting application [/not/found]: failed to create init process: no such file or directory
Fixes #32
PiperOrigin-RevId: 196027084
Change-Id: Iabc24c0bdd8fc327237acc051a1655515f445e68
Diffstat (limited to 'runsc/main.go')
-rw-r--r-- | runsc/main.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/runsc/main.go b/runsc/main.go index cf4b99d3f..883b8b1f4 100644 --- a/runsc/main.go +++ b/runsc/main.go @@ -126,7 +126,10 @@ func main() { var logFile io.Writer = os.Stderr if *logFilename != "" { - f, err := os.OpenFile(*logFilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + // We must set O_APPEND and not O_TRUNC because Docker passes + // the same log file for all commands (and also parses these + // log files), so we can't destroy them on each command. + f, err := os.OpenFile(*logFilename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { cmd.Fatalf("error opening log file %q: %v", *logFilename, err) } |