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

syscall: stringer API for Signal should include the symbolic identifier in its output #43489

Closed
krader1961 opened this issue Jan 4, 2021 · 2 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@krader1961
Copy link

The stringer interface for type syscall.Signal should include the Go syscall symbol name in the string for the signal. For example, "SIGTERM" should appear in the string if the value is syscall.SIGTERM. Alternatively, provide a separate method for explicitly converting a syscall.Signal to its syscall symbol.

What version of Go are you using (go version)?

$ go version
go version go1.15.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

I did the equivalent of fmt.Println(syscall.SIGTERM).

What did you expect to see?

Something like SIGTERM (terminated).

What did you see instead?

terminated

@tklauser tklauser changed the title Stringer API for syscall.Signal should include the symbolic identifier in its output syscall: stringer API for Signal should include the symbolic identifier in its output Jan 4, 2021
@tklauser tklauser added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 4, 2021
@tklauser
Copy link
Member

tklauser commented Jan 4, 2021

The syscall package is frozen and should only receive bug fixes (see package level godoc: https://pkg.go.dev/syscall). Instead, the corresponding golang.org/x/sys package should be used.

You can use golang.org/x/sys/unix.SignalName to get the symbolic identifier, i.e.

package main

import (
	"fmt"

	"golang.org/x/sys/unix"
)

func main() {
	fmt.Printf("%s (%s)\n", unix.SignalName(unix.SIGTERM), unix.SIGTERM)
}

https://play.golang.org/p/DSzhx5y8SVI

which will print SIGTERM (terminated).

@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Jan 4, 2021

Changing the result of syscall.Signal.String seems likely to break currently working programs. As @tklauser says, use unix.SignalName.

@golang golang locked and limited conversation to collaborators Jan 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants