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: treat CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT as SIGTERM on Windows #33311

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions src/os/signal/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ will cause os.Interrupt to be sent on the channel, and the program will
not exit. If Reset is called, or Stop is called on all channels passed
to Notify, then the default behavior will be restored.
Additionally, if Notify is called, and Windows sends CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT or CTRL_SHUTDOWN_EVENT to the process, Notify will
return syscall.SIGTERM. Unlike Control-C and Control-Break, Notify does
not change process behavior when either CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT or CTRL_SHUTDOWN_EVENT is received - the process will
still get terminated unless it exits. But receiving syscall.SIGTERM will
give the process an opportunity to clean up before termination.
Plan 9
On Plan 9, signals have type syscall.Note, which is a string. Calling
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/defs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ const (
DUPLICATE_SAME_ACCESS = C.DUPLICATE_SAME_ACCESS
THREAD_PRIORITY_HIGHEST = C.THREAD_PRIORITY_HIGHEST

SIGINT = C.SIGINT
CTRL_C_EVENT = C.CTRL_C_EVENT
CTRL_BREAK_EVENT = C.CTRL_BREAK_EVENT
SIGINT = C.SIGINT
SIGTERM = C.SIGTERM
CTRL_C_EVENT = C.CTRL_C_EVENT
CTRL_BREAK_EVENT = C.CTRL_BREAK_EVENT
CTRL_CLOSE_EVENT = C.CTRL_CLOSE_EVENT
CTRL_LOGOFF_EVENT = C.CTRL_LOGOFF_EVENT
CTRL_SHUTDOWN_EVENT = C.CTRL_SHUTDOWN_EVENT

CONTEXT_CONTROL = C.CONTEXT_CONTROL
CONTEXT_FULL = C.CONTEXT_FULL
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/defs_windows_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ const (
_DUPLICATE_SAME_ACCESS = 0x2
_THREAD_PRIORITY_HIGHEST = 0x2

_SIGINT = 0x2
_CTRL_C_EVENT = 0x0
_CTRL_BREAK_EVENT = 0x1
_SIGINT = 0x2
_SIGTERM = 0xF
_CTRL_C_EVENT = 0x0
_CTRL_BREAK_EVENT = 0x1
_CTRL_CLOSE_EVENT = 0x2
_CTRL_LOGOFF_EVENT = 0x5
_CTRL_SHUTDOWN_EVENT = 0x6

_CONTEXT_CONTROL = 0x10001
_CONTEXT_FULL = 0x10007
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/defs_windows_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ const (
_DUPLICATE_SAME_ACCESS = 0x2
_THREAD_PRIORITY_HIGHEST = 0x2

_SIGINT = 0x2
_CTRL_C_EVENT = 0x0
_CTRL_BREAK_EVENT = 0x1
_SIGINT = 0x2
_SIGTERM = 0xF
_CTRL_C_EVENT = 0x0
_CTRL_BREAK_EVENT = 0x1
_CTRL_CLOSE_EVENT = 0x2
_CTRL_LOGOFF_EVENT = 0x5
_CTRL_SHUTDOWN_EVENT = 0x6

_CONTEXT_CONTROL = 0x100001
_CONTEXT_FULL = 0x10000b
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/defs_windows_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ const (
_DUPLICATE_SAME_ACCESS = 0x2
_THREAD_PRIORITY_HIGHEST = 0x2

_SIGINT = 0x2
_CTRL_C_EVENT = 0x0
_CTRL_BREAK_EVENT = 0x1
_SIGINT = 0x2
_SIGTERM = 0xF
_CTRL_C_EVENT = 0x0
_CTRL_BREAK_EVENT = 0x1
_CTRL_CLOSE_EVENT = 0x2
_CTRL_LOGOFF_EVENT = 0x5
_CTRL_SHUTDOWN_EVENT = 0x6

_CONTEXT_CONTROL = 0x10001
_CONTEXT_FULL = 0x10007
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ func ctrlhandler1(_type uint32) uint32 {
switch _type {
case _CTRL_C_EVENT, _CTRL_BREAK_EVENT:
s = _SIGINT
case _CTRL_CLOSE_EVENT, _CTRL_LOGOFF_EVENT, _CTRL_SHUTDOWN_EVENT:
s = _SIGTERM
default:
return 0
}
Expand Down
7 changes: 5 additions & 2 deletions src/syscall/types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ const (
FILE_MAP_READ = 0x04
FILE_MAP_EXECUTE = 0x20

CTRL_C_EVENT = 0
CTRL_BREAK_EVENT = 1
CTRL_C_EVENT = 0
CTRL_BREAK_EVENT = 1
CTRL_CLOSE_EVENT = 2
CTRL_LOGOFF_EVENT = 5
CTRL_SHUTDOWN_EVENT = 6
)

const (
Expand Down