From 2e85f9325a797977eea9dfea0a925775ddd211d9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Feb 2021 12:49:00 +0100 Subject: Merging upstream version 1.29.0. Signed-off-by: Daniel Baumann --- collectors/nfacct.plugin/plugin_nfacct.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'collectors/nfacct.plugin/plugin_nfacct.c') diff --git a/collectors/nfacct.plugin/plugin_nfacct.c b/collectors/nfacct.plugin/plugin_nfacct.c index 21c2e4aee..996070f1c 100644 --- a/collectors/nfacct.plugin/plugin_nfacct.c +++ b/collectors/nfacct.plugin/plugin_nfacct.c @@ -762,6 +762,30 @@ static void nfacct_send_metrics() { #endif // HAVE_LIBNETFILTER_ACCT +static void nfacct_signal_handler(int signo) +{ + exit((signo == SIGPIPE)?1:0); +} + +// When Netdata crashes this plugin was becoming zombie, +// this function was added to remove it when sigpipe and other signals are received. +void nfacct_signals() +{ + int signals[] = { SIGPIPE, SIGINT, SIGTERM, 0}; + int i; + struct sigaction sa; + sa.sa_flags = 0; + sa.sa_handler = nfacct_signal_handler; + + // ignore all signals while we run in a signal handler + sigfillset(&sa.sa_mask); + + for (i = 0; signals[i]; i++) { + if(sigaction(signals[i], &sa, NULL) == -1) + error("Cannot add the handler to signal %d", signals[i]); + } +} + int main(int argc, char **argv) { // ------------------------------------------------------------------------ @@ -833,6 +857,8 @@ int main(int argc, char **argv) { error("nfacct.plugin: ignoring parameter '%s'", argv[i]); } + nfacct_signals(); + errno = 0; if(freq >= netdata_update_every) -- cgit v1.2.3