Skip to content

Commit

Permalink
dcrd: Support SIGTERM on Win and all unix variants.
Browse files Browse the repository at this point in the history
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.  It also added definitions for other common
signals, including SIGHUP, and treats them as NOOPs on windows.

Consequently, this modifies the logic that deals with conditionally
handling SIGTERM and SIGHUP to handle them for windows as well as all
unix-like operating systems, including newer ones that are supported by
Go since the code was originally written.

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 dcrd will now be shutdown cleanly
on more variants of unix as well as 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.
  • Loading branch information
davecgh committed Jun 10, 2022
1 parent 891fc80 commit 1629418
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
16 changes: 16 additions & 0 deletions signal_syscall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2021-2022 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
//
//go:build windows || aix || android || darwin || dragonfly || freebsd || hurd || illumos || ios || linux || netbsd || openbsd || solaris
// +build windows aix android darwin dragonfly freebsd hurd illumos ios linux netbsd openbsd solaris

package main

import (
"syscall"
)

func init() {
interruptSignals = append(interruptSignals, syscall.SIGTERM, syscall.SIGHUP)
}
22 changes: 0 additions & 22 deletions signal_unix.go

This file was deleted.

0 comments on commit 1629418

Please sign in to comment.