Fix netfilter for it closes when sigpipe happens (#9756)
Fix missing SIGPIPE for netfilter plugin
thiagoftsm committed
Aug 17, 2020 at 10:46 UTC
33d14ad910165db1b3143f8f1b3a51263972167f
1 file changed
+26
collectors/nfacct.plugin/plugin_nfacct.c
+26
@@ -762,6 +762,30 @@ static void nfacct_send_metrics() {
762
763
#endif // HAVE_LIBNETFILTER_ACCT
764
765
+static void nfacct_signal_handler(int signo)
766
+{
767
+ exit((signo == SIGPIPE)?1:0);
768
+}
769
+
770
+// When Netdata crashes this plugin was becoming zombie,
771
+// this function was added to remove it when sigpipe and other signals are received.
772
+void nfacct_signals()
773
+{
774
+ int signals[] = { SIGPIPE, SIGINT, SIGTERM, 0};
775
+ int i;
776
+ struct sigaction sa;
777
+ sa.sa_flags = 0;
778
+ sa.sa_handler = nfacct_signal_handler;
779
+
780
+ // ignore all signals while we run in a signal handler
781
+ sigfillset(&sa.sa_mask);
782
+
783
+ for (i = 0; signals[i]; i++) {
784
+ if(sigaction(signals[i], &sa, NULL) == -1)
785
+ error("Cannot add the handler to signal %d", signals[i]);
786
+ }
787
+}
788
+
789
int main(int argc, char **argv) {
790
791
// ------------------------------------------------------------------------
@@ -833,6 +857,8 @@ int main(int argc, char **argv) {
857
error("nfacct.plugin: ignoring parameter '%s'", argv[i]);
858
}
859
860
+ nfacct_signals();
861
+
862
errno = 0;
863
864
if(freq >= netdata_update_every)