Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runc cli: nits #3214

Merged
merged 3 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/urfave/cli"
Expand Down Expand Up @@ -55,20 +56,12 @@ command(s) that get executed on start, edit the args parameter of the spec. See
if err := checkArgs(context, 1, exactArgs); err != nil {
return err
}
if err := revisePidFile(context); err != nil {
return err
}
spec, err := setupSpec(context)
if err != nil {
return err
}
status, err := startContainer(context, spec, CT_ACT_CREATE, nil)
if err != nil {
return err
status, err := startContainer(context, CT_ACT_CREATE, nil)
if err == nil {
// exit with the container's exit status so any external supervisor
// is notified of the exit with the correct exit status.
os.Exit(status)
}
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
return nil
return fmt.Errorf("runc create failed: %w", err)
},
}
2 changes: 1 addition & 1 deletion delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
if force {
return killContainer(container)
}
return fmt.Errorf("cannot delete container %s that is not stopped: %s\n", id, s)
return fmt.Errorf("cannot delete container %s that is not stopped: %s", id, s)
}

return nil
Expand Down
6 changes: 1 addition & 5 deletions restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,11 @@ using the runc checkpoint command.`,
logrus.Warn("runc checkpoint is untested with rootless containers")
}

spec, err := setupSpec(context)
if err != nil {
return err
}
options := criuOptions(context)
if err := setEmptyNsMask(context, options); err != nil {
return err
}
status, err := startContainer(context, spec, CT_ACT_RESTORE, options)
status, err := startContainer(context, CT_ACT_RESTORE, options)
if err != nil {
return err
}
Expand Down
12 changes: 3 additions & 9 deletions run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/urfave/cli"
Expand Down Expand Up @@ -68,19 +69,12 @@ command(s) that get executed on start, edit the args parameter of the spec. See
if err := checkArgs(context, 1, exactArgs); err != nil {
return err
}
if err := revisePidFile(context); err != nil {
return err
}
spec, err := setupSpec(context)
if err != nil {
return err
}
status, err := startContainer(context, spec, CT_ACT_RUN, nil)
status, err := startContainer(context, CT_ACT_RUN, nil)
if err == nil {
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
}
return err
return fmt.Errorf("runc run failed: %w", err)
},
}
2 changes: 1 addition & 1 deletion start.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ your host.`,
case libcontainer.Running:
return errors.New("cannot start an already running container")
default:
return fmt.Errorf("cannot start a container in the %s state\n", status)
return fmt.Errorf("cannot start a container in the %s state", status)
}
},
}
10 changes: 9 additions & 1 deletion utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,15 @@ const (
CT_ACT_RESTORE
)

func startContainer(context *cli.Context, spec *specs.Spec, action CtAct, criuOpts *libcontainer.CriuOpts) (int, error) {
func startContainer(context *cli.Context, action CtAct, criuOpts *libcontainer.CriuOpts) (int, error) {
if err := revisePidFile(context); err != nil {
return -1, err
}
spec, err := setupSpec(context)
if err != nil {
return -1, err
}

id := context.Args().First()
if id == "" {
return -1, errEmptyID
Expand Down