Skip to content

Comments

Add the ability to parse signals based on a platform string#4793

Closed
katiewasnothere wants to merge 1 commit intocontainerd:mainfrom
katiewasnothere:lcow_signal_parse
Closed

Add the ability to parse signals based on a platform string#4793
katiewasnothere wants to merge 1 commit intocontainerd:mainfrom
katiewasnothere:lcow_signal_parse

Conversation

@katiewasnothere
Copy link

This PR adds a new call for parsing signals ParsePlatformSignal that allows for callers to specify what platform they want the signal to be parsed for. This fixes an issue with LCOW where signals for stopping a linux container are parsed for a windows platform.

Signed-off-by: Kathryn Baldauf [email protected]

@k8s-ci-robot
Copy link

Hi @katiewasnothere. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@katiewasnothere
Copy link
Author

@kevpar @ambarve @dcantah @anmaxvl fyi

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 2, 2020

Build succeeded.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 2, 2020

Build succeeded.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 2, 2020

Build succeeded.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 2, 2020

Build succeeded.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 2, 2020

Build succeeded.

@katiewasnothere
Copy link
Author

@crosbymichael or @cpuguy83 PTAL when you can. The test failure doesn't look related afaict, but is persistent across runs. Thoughts?

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 10, 2020

Build succeeded.

Comment on lines +128 to +132
func ParsePlatformSignal(rawSignal, platform string) (syscall.Signal, error) {
return parseSignalGeneric(rawSignal, platform)
}

func parseSignalGeneric(rawSignal, platform string) (syscall.Signal, error) {
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference between ParsePlatformSignal and parseSignalGeneric?

Copy link
Author

@katiewasnothere katiewasnothere Dec 16, 2020

Choose a reason for hiding this comment

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

parseSignalGeneric is just a helper function. I structured it this way since the unix version of parsing platforms also uses a helper function. It's not really needed, was included just for ease of reading really.

linuxSigrtmax = 64
)

var signalMapWindows = map[string]syscall.Signal{
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if it's possible to move this part to golang.org/x/sys/windows. I added unix.SignalNum last year. It's better to have same function for windows.

golang/sys@d455e41

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure it would make much sense to do since windows doesn't really have "signals"


// manually define signals for linux since we may be running an LCOW container, but
// the unix syscalls do not get built when running on windows
var signalMapLinux = map[string]syscall.Signal{
Copy link
Member

Choose a reason for hiding this comment

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

Is this copied from somewhere? If so, we should provide a link as a reference.

Choose a reason for hiding this comment

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

}

func getSignalMapForPlatform(platform string) map[string]syscall.Signal {
if platform != "windows" {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to return an error if we are passed an unrecognized platform. Otherwise we could end up with a bug in the future where the linux signal map is used unintentionally.

}
}
return -1, fmt.Errorf("unknown signal %q", rawSignal)
return sig, fmt.Errorf("unknown signal %q", rawSignal)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we return a valid value along with an error?

Choose a reason for hiding this comment

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

I guess this this would happen if golang successfully looked up the signal number in its private signals table, but it wasn't in our platform-specific map here. (windows table in https://golang.org/src/syscall/types_windows.go)

But yea, returning sig won't help because the caller will see the error is non nil, please return -1 unless there is something else going on?

if platform != "windows" {
return sig, nil
}
// on windows, make sure we support this signal
Copy link
Member

Choose a reason for hiding this comment

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

Is there some specific reason we need to validate this only for Windows?

}
signal, ok := signalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
if !ok {
return -1, fmt.Errorf("unknown signal %q", rawSignal)

Choose a reason for hiding this comment

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

Can you add an extra hint for us by adding is it supported on $platform in the error message here?


// manually define signals for linux since we may be running an LCOW container, but
// the unix syscalls do not get built when running on windows
var signalMapLinux = map[string]syscall.Signal{

Choose a reason for hiding this comment

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

I'm kinda sad that this enhanced signal lookup feature won't work on linux!
(I would have to run a linux container on windows to get RTMIN+3 to work)

Can you put this in a generic location (signals.go), should be safe because it has linux in the name already, so it could be used by both signals_windows and signals_linux ? Bonus for making signals_linux actually use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test status/needs-update Awaiting contributor update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants