@cryptotaxi247 / netdata-1 / commits / 42acf405a

allow poll_events() to cleanup when thread exits

Costa Tsaousis (ktsaou) committed May 2, 2017 at 23:02 UTC 42acf405af0309b53135f912c3d53d9afb5bda2a
2 files changed +21 -11
src/socket.c
+18 -8
@@ -900,6 +900,19 @@ static int snd_callback_default(int fd, int socktype, void *data, short int *eve
900 return 0;
901 }
902
903 +void poll_events_cleanup(void *data) {
904 + struct poll *p = (struct poll *)data;
905 +
906 + size_t i;
907 + for(i = 0 ; i <= p->max ; i++) {
908 + struct pollinfo *pi = &p->inf[i];
909 + poll_close_fd(p, pi);
910 + }
911 +
912 + freez(p->fds);
913 + freez(p->inf);
914 +}
915 +
916 void poll_events(LISTEN_SOCKETS *sockets
917 , void *(*add_callback)(int fd, short int *events)
918 , void (*del_callback)(int fd, void *data)
@@ -930,7 +943,9 @@ void poll_events(LISTEN_SOCKETS *sockets
943 info("POLLFD: LISTENER: listening on '%s'", (sockets->fds_names[i])?sockets->fds_names[i]:"UNKNOWN");
944 }
945
933 - int timeout = 10 * 1000;
946 + int timeout = -1; // wait forever
947 +
948 + pthread_cleanup_push(poll_events_cleanup, &p);
949
950 for(;;) {
951 if(unlikely(netdata_exit)) break;
@@ -1059,11 +1074,6 @@ void poll_events(LISTEN_SOCKETS *sockets
1074 }
1075 }
1076
1062 - for(i = 0 ; i <= p.max ; i++) {
1063 - struct pollinfo *pi = &p.inf[i];
1064 - poll_close_fd(&p, pi);
1065 - }
1066 -
1067 - freez(p.fds);
1068 - freez(p.inf);
1077 + pthread_cleanup_pop(1);
1078 + debug(D_POLLFD, "POLLFD: LISTENER: cleanup completed");
1079 }
src/statsd.c
+3 -3
@@ -1556,11 +1556,11 @@ static inline void statsd_update_app_chart(STATSD_APP *app, STATSD_APP_CHART *ch
1556 }
1557
1558 static inline void statsd_update_all_app_charts(void) {
1559 - debug(D_STATSD, "updating app charts");
1559 + // debug(D_STATSD, "updating app charts");
1560
1561 STATSD_APP *app;
1562 for(app = statsd.apps; app ;app = app->next) {
1563 - debug(D_STATSD, "updating charts for app '%s'", app->name);
1563 + // debug(D_STATSD, "updating charts for app '%s'", app->name);
1564
1565 STATSD_APP_CHART *chart;
1566 for(chart = app->charts; chart ;chart = chart->next) {
@@ -1570,7 +1570,7 @@ static inline void statsd_update_all_app_charts(void) {
1570 }
1571 }
1572
1573 - debug(D_STATSD, "completed update of app charts");
1573 + // debug(D_STATSD, "completed update of app charts");
1574 }
1575
1576 static inline void statsd_flush_index_metrics(STATSD_INDEX *index, void (*flush_metric)(STATSD_METRIC *)) {