decred / politeia

ISC License
110 stars 75 forks source link

pivoter: Support SIGTERM on Windows. #1644

Closed davecgh closed 2 years ago

davecgh commented 2 years ago

The build tag for the signal handling in politeiavoter was updating incorrectly by commit af61db4. However, rather than just correcting the build tag, this takes the opportunity to update and improve the signal-handling logic as explained below.

Go 1.14 added runtime support for handling the windows CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT events by adding a definition for syscall.SIGTERM to windows and converting the events to that signal.

Consequently, this modifies the logic that deals with conditionally handling SIGTERM to handle it for windows as well as all unix-like operating systems.

Although the additional signals could probably just be added unconditionally without too much issue now due to the runtime adding stubs to all operating systems the project officially supports, it is safer to be explicit when dealing with syscall definitions since there is no guarantee that they will exist for newly-added operating systems.

Stated more plainly, this change means politeiavoter will now be shutdown cleanly when being terminated by windows itself due to various things such as the user logging off, the window terminal being closed, and the system shutting down.