SIGHUP: ignore only when in background (stdin not a tty)
Use sys.stdin.isatty() to auto-detect: foreground sessions still respond to SIGHUP (terminal close kills the process as expected), background/piped processes ignore it and survive.
This commit is contained in:
1 parent
fb5c1fbf6a
commit
f8e9cb1018
2 files changed
+6
-2
No files matched your search
@@ -131,7 +131,10 @@ Non-TPDU messages (ATR, PPS, card state changes, Fi/Di) print identically in all
|
|||||||
|
|
||||||
## Background / Daemon
|
## Background / Daemon
|
||||||
|
|
||||||
SIGHUP is ignored by default — terminal closure won't kill the sniffer.
|
SIGHUP is automatically ignored when stdin is not a terminal (i.e. run in
|
||||||
|
background or via a pipe). Foreground terminal sessions still respond to
|
||||||
|
SIGHUP normally.
|
||||||
|
|
||||||
To run persistently in the background with output to files:
|
To run persistently in the background with output to files:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
@@ -131,7 +131,8 @@ def main():
|
|||||||
file_dumper.close()
|
file_dumper.close()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
signal.signal(signal.SIGHUP, signal.SIG_IGN)
|
if not sys.stdin.isatty():
|
||||||
|
signal.signal(signal.SIGHUP, signal.SIG_IGN)
|
||||||
signal.signal(signal.SIGINT, on_signal)
|
signal.signal(signal.SIGINT, on_signal)
|
||||||
signal.signal(signal.SIGTERM, on_signal)
|
signal.signal(signal.SIGTERM, on_signal)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user