mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-04 15:12:56 +08:00
startContainer: minor refactor
All three callers* of startContainer call revisePidFile and createSpec before calling it, so it makes sense to move those calls to inside of the startContainer, and drop the spec argument. * -- in fact restore does not call revisePidFile, but it should. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -55,14 +55,7 @@ command(s) that get executed on start, edit the args parameter of the spec. See
|
|||||||
if err := checkArgs(context, 1, exactArgs); err != nil {
|
if err := checkArgs(context, 1, exactArgs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := revisePidFile(context); err != nil {
|
status, err := startContainer(context, CT_ACT_CREATE, nil)
|
||||||
return err
|
|
||||||
}
|
|
||||||
spec, err := setupSpec(context)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
status, err := startContainer(context, spec, CT_ACT_CREATE, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -104,15 +104,11 @@ using the runc checkpoint command.`,
|
|||||||
logrus.Warn("runc checkpoint is untested with rootless containers")
|
logrus.Warn("runc checkpoint is untested with rootless containers")
|
||||||
}
|
}
|
||||||
|
|
||||||
spec, err := setupSpec(context)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
options := criuOptions(context)
|
options := criuOptions(context)
|
||||||
if err := setEmptyNsMask(context, options); err != nil {
|
if err := setEmptyNsMask(context, options); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
status, err := startContainer(context, spec, CT_ACT_RESTORE, options)
|
status, err := startContainer(context, CT_ACT_RESTORE, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
9
run.go
9
run.go
@@ -68,14 +68,7 @@ command(s) that get executed on start, edit the args parameter of the spec. See
|
|||||||
if err := checkArgs(context, 1, exactArgs); err != nil {
|
if err := checkArgs(context, 1, exactArgs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := revisePidFile(context); err != nil {
|
status, err := startContainer(context, CT_ACT_RUN, nil)
|
||||||
return err
|
|
||||||
}
|
|
||||||
spec, err := setupSpec(context)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
status, err := startContainer(context, spec, CT_ACT_RUN, nil)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// exit with the container's exit status so any external supervisor is
|
// exit with the container's exit status so any external supervisor is
|
||||||
// notified of the exit with the correct exit status.
|
// notified of the exit with the correct exit status.
|
||||||
|
@@ -395,7 +395,15 @@ const (
|
|||||||
CT_ACT_RESTORE
|
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()
|
id := context.Args().First()
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return -1, errEmptyID
|
return -1, errEmptyID
|
||||||
|
Reference in New Issue
Block a user