From f8e9cb10184b22b6ec9cbf3b4f2dc93259aaf25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A2=D1=80=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Tue, 11 Aug 2026 01:02:07 +0300 Subject: [PATCH] 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. --- README.md | 5 ++++- simtrace2_pysniff/__main__.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f437635..efc1055 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,10 @@ Non-TPDU messages (ATR, PPS, card state changes, Fi/Di) print identically in all ## 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: ```sh diff --git a/simtrace2_pysniff/__main__.py b/simtrace2_pysniff/__main__.py index 4b49d82..671f7cd 100644 --- a/simtrace2_pysniff/__main__.py +++ b/simtrace2_pysniff/__main__.py @@ -131,7 +131,8 @@ def main(): file_dumper.close() 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.SIGTERM, on_signal)