move signal ignore out of `eth/common` (#734)

`net/nat` is the only place where it is used and it certainly doesn't
belong in `common`
This commit is contained in:
Jacek Sieka 2024-09-24 11:30:05 +02:00 committed by GitHub
parent 410eab5a16
commit 3d51887c15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 35 deletions

View File

@ -8,14 +8,9 @@
import
std/[hashes],
nimcrypto/hash, stew/byteutils, metrics,
nimcrypto/hash, stew/byteutils,
./eth_types
when defined(posix):
import std/[posix, os]
export metrics
proc hash*(d: MDigest): Hash {.inline.} = hash(d.data)
proc parseAddress*(hexString: string): EthAddress =
@ -23,31 +18,3 @@ proc parseAddress*(hexString: string): EthAddress =
proc `$`*(a: EthAddress): string =
a.toHex()
# Block all/most signals in the current thread, so we don't interfere with regular signal
# handling elsewhere.
proc ignoreSignalsInThread*() =
when defined(posix):
var signalMask, oldSignalMask: Sigset
# sigprocmask() doesn't work on macOS, for multithreaded programs
if sigfillset(signalMask) != 0:
echo osErrorMsg(osLastError())
quit(QuitFailure)
when defined(boehmgc):
# Turns out Boehm GC needs some signals to deal with threads:
# https://www.hboehm.info/gc/debugging.html
const
SIGPWR = 30
SIGXCPU = 24
SIGSEGV = 11
SIGBUS = 7
if sigdelset(signalMask, SIGPWR) != 0 or
sigdelset(signalMask, SIGXCPU) != 0 or
sigdelset(signalMask, SIGSEGV) != 0 or
sigdelset(signalMask, SIGBUS) != 0:
echo osErrorMsg(osLastError())
quit(QuitFailure)
if pthread_sigmask(SIG_BLOCK, signalMask, oldSignalMask) != 0:
echo osErrorMsg(osLastError())
quit(QuitFailure)

View File

@ -47,6 +47,23 @@ var
logScope:
topics = "eth net nat"
when defined(posix):
import std/posix
# Block all/most signals in the current thread, so we don't interfere with regular signal
# handling elsewhere.
proc ignoreSignalsInThread() =
when defined(posix):
var signalMask, oldSignalMask: Sigset
# sigprocmask() doesn't work on macOS, for multithreaded programs
if sigfillset(signalMask) != 0:
echo osErrorMsg(osLastError())
quit(QuitFailure)
if pthread_sigmask(SIG_BLOCK, signalMask, oldSignalMask) != 0:
echo osErrorMsg(osLastError())
quit(QuitFailure)
## Also does threadvar initialisation.
## Must be called before redirectPorts() in each thread.
proc getExternalIP*(natStrategy: NatStrategy, quiet = false): Opt[IpAddress] =

View File

@ -41,7 +41,7 @@ when useSnappy:
# "undeclared identifier: 'activeChroniclesStream'", when the code using p2p
# does not import chronicles. Need to resolve this properly.
export
options, p2pProtocol, rlp, chronicles
options, p2pProtocol, rlp, chronicles, metrics
declarePublicGauge rlpx_connected_peers,
"Number of connected peers in the pool"