summaryrefslogtreecommitdiffhomepage
path: root/runsc/cmd/do.go
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-05-23 22:27:36 -0700
committerShentubot <shentubot@google.com>2019-05-23 22:28:38 -0700
commit409e8eea60f096b34c9005b302dc821f38ac19ed (patch)
treed78ade19e332ee80372be30e67b71c13a3ec3923 /runsc/cmd/do.go
parent6240abb205f9e5cdbad1c864dbed345d92f04b09 (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/do.go')
-rw-r--r--runsc/cmd/do.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/runsc/cmd/do.go b/runsc/cmd/do.go
index c5e72f32b..425db8efe 100644
--- a/runsc/cmd/do.go
+++ b/runsc/cmd/do.go
@@ -89,16 +89,16 @@ func (c *Do) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) su
hostname, err := os.Hostname()
if err != nil {
- Fatalf("Error to retrieve hostname: %v", err)
+ return Errorf("Error to retrieve hostname: %v", err)
}
absRoot, err := resolvePath(c.root)
if err != nil {
- Fatalf("Error resolving root: %v", err)
+ return Errorf("Error resolving root: %v", err)
}
absCwd, err := resolvePath(c.cwd)
if err != nil {
- Fatalf("Error resolving current directory: %v", err)
+ return Errorf("Error resolving current directory: %v", err)
}
spec := &specs.Spec{
@@ -121,18 +121,18 @@ func (c *Do) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) su
if conf.Network != boot.NetworkNone {
clean, err := c.setupNet(cid, spec)
if err != nil {
- Fatalf("Error setting up network: %v", err)
+ return Errorf("Error setting up network: %v", err)
}
defer clean()
}
out, err := json.Marshal(spec)
if err != nil {
- Fatalf("Error to marshal spec: %v", err)
+ return Errorf("Error to marshal spec: %v", err)
}
tmpDir, err := ioutil.TempDir("", "runsc-do")
if err != nil {
- Fatalf("Error to create tmp dir: %v", err)
+ return Errorf("Error to create tmp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
@@ -141,12 +141,12 @@ func (c *Do) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) su
cfgPath := filepath.Join(tmpDir, "config.json")
if err := ioutil.WriteFile(cfgPath, out, 0755); err != nil {
- Fatalf("Error write spec: %v", err)
+ return Errorf("Error write spec: %v", err)
}
ws, err := container.Run(cid, spec, conf, tmpDir, "", "", "", false)
if err != nil {
- Fatalf("running container: %v", err)
+ return Errorf("running container: %v", err)
}
*waitStatus = ws