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

runtime/debug: add the options parameter to SetCrashOutput #67192

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 src/runtime/debug/example_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func monitor() {
if err != nil {
log.Fatalf("StdinPipe: %v", err)
}
debug.SetCrashOutput(pipe.(*os.File)) // (this conversion is safe)
debug.SetCrashOutput(pipe.(*os.File), debug.CrashOptions{}) // (this conversion is safe)
if err := cmd.Start(); err != nil {
log.Fatalf("can't start monitor: %v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/debug/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func Stack() []byte {
}
}

// CrashOptions is a placeholder type for future options to SetCrashOutput.
type CrashOptions struct{}

// SetCrashOutput configures a single additional file where unhandled
// panics and other fatal errors are printed, in addition to standard error.
// There is only one additional file: calling SetCrashOutput again overrides
Expand All @@ -40,7 +43,7 @@ func Stack() []byte {
// To disable this additional crash output, call SetCrashOutput(nil).
// If called concurrently with a crash, some in-progress output may be written
// to the old file even after an overriding SetCrashOutput returns.
func SetCrashOutput(f *os.File) error {
func SetCrashOutput(f *os.File, opts ...CrashOptions) error {
fd := ^uintptr(0)
if f != nil {
// The runtime will write to this file descriptor from
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/debug/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatal(err)
}
if err := SetCrashOutput(f); err != nil {
if err := SetCrashOutput(f, CrashOptions{}); err != nil {
log.Fatal(err) // e.g. EMFILE
}
println("hello")
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/traceback_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func crash() {
// Ensure that we get pc=0x%x values in the traceback.
debug.SetTraceback("system")
writeSentinel(os.Stdout)
debug.SetCrashOutput(os.Stdout)
debug.SetCrashOutput(os.Stdout, debug.CrashOptions{})

go func() {
// This call is typically inlined.
Expand Down