mirror of
https://github.com/9001/copyparty.git
synced 2026-06-18 20:22:27 -06:00
bsd: signal masking
This commit is contained in:
parent
a48afe87b9
commit
a00bc93fe1
|
|
@ -51,6 +51,7 @@ from .th_srv import (
|
|||
)
|
||||
from .up2k import Up2k
|
||||
from .util import (
|
||||
BLOCK_SIGS,
|
||||
DEF_EXP,
|
||||
DEF_MTE,
|
||||
DEF_MTH,
|
||||
|
|
@ -1486,6 +1487,8 @@ class SvcHub(object):
|
|||
|
||||
for sig in sigs:
|
||||
signal.signal(sig, self.signal_handler)
|
||||
if sig not in BLOCK_SIGS and BLOCK_SIGS:
|
||||
BLOCK_SIGS.append(sig)
|
||||
|
||||
if self.args.sig_thr:
|
||||
Daemon(self._signal_thr, "svchub-sig")
|
||||
|
|
|
|||
|
|
@ -326,7 +326,14 @@ except:
|
|||
BITNESS = struct.calcsize("P") * 8
|
||||
|
||||
|
||||
CAN_SIGMASK = not (ANYWIN or PY2 or GRAAL)
|
||||
try:
|
||||
if ANYWIN or PY2 or GRAAL or not hasattr(signal, "pthread_sigmask"):
|
||||
raise Exception()
|
||||
BLOCK_SIGS = [signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGUSR1]
|
||||
CAN_SIGMASK = True
|
||||
except:
|
||||
BLOCK_SIGS = []
|
||||
CAN_SIGMASK = False
|
||||
|
||||
|
||||
RE_ANSI = re.compile("\033\\[[^mK]*[mK]")
|
||||
|
|
@ -832,10 +839,8 @@ class Daemon(threading.Thread):
|
|||
self.start()
|
||||
|
||||
def run(self):
|
||||
if CAN_SIGMASK:
|
||||
signal.pthread_sigmask(
|
||||
signal.SIG_BLOCK, [signal.SIGINT, signal.SIGTERM, signal.SIGUSR1]
|
||||
)
|
||||
if BLOCK_SIGS:
|
||||
signal.pthread_sigmask(signal.SIG_BLOCK, BLOCK_SIGS)
|
||||
|
||||
self.fun(*self.a, **self.ka)
|
||||
|
||||
|
|
@ -1778,9 +1783,7 @@ def log_thrs(log: Callable[[str, str, int], None], ival: float, name: str) -> No
|
|||
|
||||
|
||||
def _sigblock():
|
||||
signal.pthread_sigmask(
|
||||
signal.SIG_BLOCK, [signal.SIGINT, signal.SIGTERM, signal.SIGUSR1]
|
||||
)
|
||||
signal.pthread_sigmask(signal.SIG_BLOCK, BLOCK_SIGS)
|
||||
|
||||
|
||||
sigblock = _sigblock if CAN_SIGMASK else noop
|
||||
|
|
|
|||
Loading…
Reference in a new issue