diff options
author | Andrei Vagin <avagin@google.com> | 2019-05-23 22:27:36 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-05-23 22:28:38 -0700 |
commit | 409e8eea60f096b34c9005b302dc821f38ac19ed (patch) | |
tree | d78ade19e332ee80372be30e67b71c13a3ec3923 /runsc/cmd/cmd.go | |
parent | 6240abb205f9e5cdbad1c864dbed345d92f04b09 (diff) |
runsc/do: do a proper cleanup if a command failed due to internal errors
Fatalf calls os.Exit and a process exits without calling defer callbacks.
Should we do this for other runsc commands?
PiperOrigin-RevId: 249776310
Change-Id: If9d8b54d0ae37db443895906eb33bd9e9b600cc9
Diffstat (limited to 'runsc/cmd/cmd.go')
-rw-r--r-- | runsc/cmd/cmd.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/runsc/cmd/cmd.go b/runsc/cmd/cmd.go index aa7b1a636..a2fc377d1 100644 --- a/runsc/cmd/cmd.go +++ b/runsc/cmd/cmd.go @@ -22,19 +22,26 @@ import ( "strconv" "syscall" + "github.com/google/subcommands" specs "github.com/opencontainers/runtime-spec/specs-go" "gvisor.googlesource.com/gvisor/pkg/log" "gvisor.googlesource.com/gvisor/runsc/specutils" ) -// Fatalf logs to stderr and exits with a failure status code. -func Fatalf(s string, args ...interface{}) { +// Errorf logs to stderr and returns subcommands.ExitFailure. +func Errorf(s string, args ...interface{}) subcommands.ExitStatus { // If runsc is being invoked by docker or cri-o, then we might not have // access to stderr, so we log a serious-looking warning in addition to // writing to stderr. log.Warningf("FATAL ERROR: "+s, args...) fmt.Fprintf(os.Stderr, s+"\n", args...) // Return an error that is unlikely to be used by the application. + return subcommands.ExitFailure +} + +// Fatalf logs to stderr and exits with a failure status code. +func Fatalf(s string, args ...interface{}) { + Errorf(s, args...) os.Exit(128) } |