[1/2] app/dumpcap: handle SIGTERM and SIGHUP
Checks
Commit Message
If application is killed (SIGTERM), or the console session
ends (SIGHUP) or the write to the output file fails (SIGPIPE)
then do cleanup before exiting.
This also makes DPDK dumpcap behave more like Wireshark dumpcap.
Suggested-by: Isaac Boukris <iboukris@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/dumpcap/main.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
@@ -939,6 +939,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;
@@ -964,8 +969,13 @@ int main(int argc, char **argv)
compile_filters();
- 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);
enable_primary_monitor();