summaryrefslogtreecommitdiffstats
path: root/src/plugin_tc.c
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2018-03-27 21:28:21 +0000
committerFederico Ceratto <federico.ceratto@gmail.com>2018-03-27 21:28:21 +0000
commitd4dd00f58a502c9ca4b63e36ce6bc7a9945dc63c (patch)
treefaac99f51f182bb8c0a03e95e393d421ac9ddf42 /src/plugin_tc.c
parentNew upstream version 1.9.0+dfsg (diff)
downloadnetdata-d4dd00f58a502c9ca4b63e36ce6bc7a9945dc63c.tar.xz
netdata-d4dd00f58a502c9ca4b63e36ce6bc7a9945dc63c.zip
New upstream version 1.10.0+dfsgupstream/1.10.0+dfsg
Diffstat (limited to 'src/plugin_tc.c')
-rw-r--r--src/plugin_tc.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/src/plugin_tc.c b/src/plugin_tc.c
index 0d8fd3d6..4b6d84e1 100644
--- a/src/plugin_tc.c
+++ b/src/plugin_tc.c
@@ -828,17 +828,32 @@ static inline void tc_split_words(char *str, char **words, int max_words) {
while(i < max_words) words[i++] = NULL;
}
-volatile pid_t tc_child_pid = 0;
-void *tc_main(void *ptr) {
+static pid_t tc_child_pid = 0;
+
+static void tc_main_cleanup(void *ptr) {
struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
+ static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
- info("TC thread created with task id %d", gettid());
+ info("cleaning up...");
- if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
- error("Cannot set pthread cancel type to DEFERRED.");
+ if(tc_child_pid) {
+ info("TC: killing with SIGTERM tc-qos-helper process %d", tc_child_pid);
+ if(killpid(tc_child_pid, SIGTERM) != -1) {
+ siginfo_t info;
- if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
- error("Cannot set pthread cancel state to ENABLE.");
+ info("TC: waiting for tc plugin child process pid %d to exit...", tc_child_pid);
+ waitid(P_PID, (id_t) tc_child_pid, &info, WEXITED);
+ // info("TC: finished tc plugin child process pid %d.", tc_child_pid);
+ }
+
+ tc_child_pid = 0;
+ }
+
+ static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
+}
+
+void *tc_main(void *ptr) {
+ netdata_thread_cleanup_push(tc_main_cleanup, ptr);
struct rusage thread;
@@ -863,10 +878,8 @@ void *tc_main(void *ptr) {
snprintfz(buffer, TC_LINE_MAX, "%s/tc-qos-helper.sh", netdata_configured_plugins_dir);
char *tc_script = config_get("plugin:tc", "script to run to get tc values", buffer);
-
- for(;1;) {
- if(unlikely(netdata_exit)) break;
+ while(!netdata_exit) {
FILE *fp;
struct tc_device *device = NULL;
struct tc_class *class = NULL;
@@ -965,14 +978,10 @@ void *tc_main(void *ptr) {
// debug(D_TC_LOOP, "END line");
if(likely(device)) {
- if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0)
- error("Cannot set pthread cancel state to DISABLE.");
-
+ netdata_thread_disable_cancelability();
tc_device_commit(device);
// tc_device_free(device);
-
- if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
- error("Cannot set pthread cancel state to ENABLE.");
+ netdata_thread_enable_cancelability();
}
device = NULL;
@@ -1149,10 +1158,7 @@ void *tc_main(void *ptr) {
sleep((unsigned int) localhost->rrd_update_every);
}
-cleanup:
- info("TC thread exiting");
-
- static_thread->enabled = 0;
- pthread_exit(NULL);
+cleanup: ; // added semi-colon to prevent older gcc error: label at end of compound statement
+ netdata_thread_cleanup_pop(1);
return NULL;
}