[v3,1/3] app/dumpcap: handle SIGTERM and SIGHUP

Message ID 20240703154705.19192-2-stephen@networkplumber.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Series dumpcap and pdump patches for 24.07 |


Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger July 3, 2024, 3:45 p.m. UTC
  If the dumpcap is killed it does not cleanup which leaves
the ring buffer and the memory pool behind.
Until resource are exhausted devices will continue to fill the ring.

Fix by having the application handle SIGTERM, SIGHUP, and SIGPIPE.
These are the same signals handled in same way by the wireshark
dumpcap application.

Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
 app/dumpcap/main.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)


diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index b25b95e2fc..ba91ca94d0 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -936,6 +936,11 @@  int main(int argc, char **argv)
 	struct rte_ring *r;
 	struct rte_mempool *mp;
+	struct sigaction action = {
+		.sa_flags = SA_RESTART,
+		.sa_handler = signal_handler,
+	};
+	struct sigaction origaction;
 	dumpcap_out_t out;
 	char *p;
@@ -961,8 +966,13 @@  int main(int argc, char **argv)
-	signal(SIGINT, signal_handler);
-	signal(SIGPIPE, SIG_IGN);
+	sigemptyset(&action.sa_mask);
+	sigaction(SIGTERM, &action, NULL);
+	sigaction(SIGINT, &action, NULL);
+	sigaction(SIGPIPE, &action, NULL);
+	sigaction(SIGHUP, NULL, &origaction);
+	if (origaction.sa_handler == SIG_DFL)
+		sigaction(SIGHUP, &action, NULL);