diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2020-08-17 10:46:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-17 10:46:59 +0000 |
commit | 33d14ad910165db1b3143f8f1b3a51263972167f (patch) | |
tree | 5b978d836d1d69c981ab83f2823df4cafb6b28e1 | |
parent | 5541187fcf745eb381c9cc90691b1265a37563d0 (diff) |
Fix netfilter for it closes when sigpipe happens (#9756)
Fix missing SIGPIPE for netfilter plugin
-rw-r--r-- | collectors/nfacct.plugin/plugin_nfacct.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/collectors/nfacct.plugin/plugin_nfacct.c b/collectors/nfacct.plugin/plugin_nfacct.c index 21c2e4aeec..996070f1ca 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) |