Skip to content
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
2 changes: 1 addition & 1 deletion validation/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
// kill a created
{stoppedConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionDelete, true, specerror.NewError(specerror.KillSignalImplement, fmt.Errorf("`kill` operation MUST send the specified signal to the container process"), rspecs.Version)},
// kill a stopped
{stoppedConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, false, specerror.NewError(specerror.KillSignalImplement, fmt.Errorf("`kill` operation MUST send the specified signal to the container process"), rspecs.Version)},
{stoppedConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, false, specerror.NewError(specerror.KillNonCreateRunGenError, fmt.Errorf("attempting to send a signal to a container that is neither `created` nor `running` MUST generate an error"), rspecs.Version)},
// kill a running
{runningConfig, containerID, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, true, specerror.NewError(specerror.KillSignalImplement, fmt.Errorf("`kill` operation MUST send the specified signal to the container process"), rspecs.Version)},
}
Expand Down
62 changes: 62 additions & 0 deletions validation/kill_no_effect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"fmt"
"os"
"reflect"
"time"

"github.com/mndrix/tap-go"
rspecs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/specerror"
"github.com/opencontainers/runtime-tools/validation/util"
uuid "github.com/satori/go.uuid"
)

func main() {
t := tap.New()
t.Header(0)
bundleDir, err := util.PrepareBundle()
if err != nil {
util.Fatal(err)
}
defer os.RemoveAll(bundleDir)

targetErr := specerror.NewError(specerror.KillNonCreateRunHaveNoEffect, fmt.Errorf("attempting to send a signal to a container that is neither `created` nor `running` MUST have no effect on the container"), rspecs.Version)
containerID := uuid.NewV4().String()
g := util.GetDefaultGenerator()
g.SetProcessArgs([]string{"true"})

config := util.LifecycleConfig{
Config: g,
BundleDir: bundleDir,
Actions: util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete,
PreCreate: func(r *util.Runtime) error {
r.SetID(containerID)
return nil
},
PreDelete: func(r *util.Runtime) error {
err := util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*5, time.Second*1)
if err != nil {
return err
}
currentState, err := r.State()
if err != nil {
return err
}
r.Kill("KILL")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to ensure that this call returns an error, based on this and this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* *Exit code:* Zero if the signal was successfully sent to the container process and non-zero on errors.

I found there is no general exit code, there is golang syscall pkg, but just works in posix system.
So do we still need this 'Exit code' session in command-line-interface?

if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
                log.Printf("Exit Status: %d", status.ExitStatus())
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return error is check in kill.go. There is a bug in the previous kill.go, it displays the wrong spec error code. The new commit 0ddb5cd solves that.

newState, err := r.State()
if err != nil || !reflect.DeepEqual(newState, currentState) {
return targetErr
}
return nil
},
}
err = util.RuntimeLifecycleValidate(config)
if err != nil && err != targetErr {
util.Fatal(err)
} else {
util.SpecErrorOK(t, err == nil, targetErr, nil)
}
t.AutoPlan()
}