workaround for self-kill
Costa Tsaousis (ktsaou) committed
Sep 14, 2015 at 17:14 UTC
ccb396d17f169e1bf57bcb50af89701eccad0e56
2 files changed
+34
-18
src/main.c
+10
-6
@@ -82,9 +82,11 @@ void kill_childs()
82
}
83
84
if(tc_child_pid) {
85
- debug(D_EXIT, "Killing tc-qos-helper procees");
86
- kill(tc_child_pid, SIGTERM);
87
- waitid(tc_child_pid, 0, &info, WEXITED);
85
+ if(kill(tc_child_pid, 0) != -1) {
86
+ info("Killing tc-qos-helper procees");
87
+ kill(tc_child_pid, SIGTERM);
88
+ waitid(tc_child_pid, 0, &info, WEXITED);
89
+ }
90
}
91
tc_child_pid = 0;
92
@@ -95,9 +97,11 @@ void kill_childs()
97
pthread_join(cd->thread, NULL);
98
99
if(cd->pid && !cd->obsolete) {
98
- debug(D_EXIT, "killing %s plugin process", cd->id);
99
- kill(cd->pid, SIGTERM);
100
- waitid(cd->pid, 0, &info, WEXITED);
100
+ if(kill(cd->pid, 0) != -1) {
101
+ debug(D_EXIT, "killing %s plugin process", cd->id);
102
+ kill(cd->pid, SIGTERM);
103
+ waitid(cd->pid, 0, &info, WEXITED);
104
+ }
105
}
106
}
107
src/plugins_d.c
+24
-12
@@ -152,7 +152,8 @@ void *pluginsd_worker_thread(void *arg)
152
if(!dimension || !*dimension) {
153
error("PLUGINSD: '%s' is requesting a SET on chart '%s', like this: 'SET %s = %s'. Disabling it.", cd->fullfilename, st->id, dimension?dimension:"<nothing>", value?value:"<nothing>");
154
cd->enabled = 0;
155
- kill(cd->pid, SIGTERM);
155
+ // test: killing an exited child kills us - lets check it exists before killing it
156
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
157
break;
158
}
159
@@ -161,7 +162,8 @@ void *pluginsd_worker_thread(void *arg)
162
if(!st) {
163
error("PLUGINSD: '%s' is requesting a SET on dimension %s with value %s, without a BEGIN. Disabling it.", cd->fullfilename, dimension, value);
164
cd->enabled = 0;
164
- kill(cd->pid, SIGTERM);
165
+ // test: killing an exited child kills us - lets check it exists before killing it
166
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
167
break;
168
}
169
@@ -177,7 +179,8 @@ void *pluginsd_worker_thread(void *arg)
179
if(!id) {
180
error("PLUGINSD: '%s' is requesting a BEGIN without a chart id. Disabling it.", cd->fullfilename);
181
cd->enabled = 0;
180
- kill(cd->pid, SIGTERM);
182
+ // test: killing an exited child kills us - lets check it exists before killing it
183
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
184
break;
185
}
186
@@ -185,7 +188,8 @@ void *pluginsd_worker_thread(void *arg)
188
if(!st) {
189
error("PLUGINSD: '%s' is requesting a BEGIN on chart '%s', which does not exist. Disabling it.", cd->fullfilename, id);
190
cd->enabled = 0;
188
- kill(cd->pid, SIGTERM);
191
+ // test: killing an exited child kills us - lets check it exists before killing it
192
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
193
break;
194
}
195
@@ -200,7 +204,8 @@ void *pluginsd_worker_thread(void *arg)
204
if(!st) {
205
error("PLUGINSD: '%s' is requesting an END, without a BEGIN. Disabling it.", cd->fullfilename);
206
cd->enabled = 0;
203
- kill(cd->pid, SIGTERM);
207
+ // test: killing an exited child kills us - lets check it exists before killing it
208
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
209
break;
210
}
211
@@ -234,7 +239,8 @@ void *pluginsd_worker_thread(void *arg)
239
if(!type || !*type || !id || !*id) {
240
error("PLUGINSD: '%s' is requesting a CHART, without a type.id. Disabling it.", cd->fullfilename);
241
cd->enabled = 0;
237
- kill(cd->pid, SIGTERM);
242
+ // test: killing an exited child kills us - lets check it exists before killing it
243
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
244
break;
245
}
246
@@ -282,14 +288,16 @@ void *pluginsd_worker_thread(void *arg)
288
if(!id || !*id) {
289
error("PLUGINSD: '%s' is requesting a DIMENSION, without an id. Disabling it.", cd->fullfilename);
290
cd->enabled = 0;
285
- kill(cd->pid, SIGTERM);
291
+ // test: killing an exited child kills us - lets check it exists before killing it
292
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
293
break;
294
}
295
296
if(!st) {
297
error("PLUGINSD: '%s' is requesting a DIMENSION, without a CHART. Disabling it.", cd->fullfilename);
298
cd->enabled = 0;
292
- kill(cd->pid, SIGTERM);
299
+ // test: killing an exited child kills us - lets check it exists before killing it
300
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
301
break;
302
}
303
@@ -323,7 +331,8 @@ void *pluginsd_worker_thread(void *arg)
331
else if(hash == DISABLE_HASH && !strcmp(s, "DISABLE")) {
332
error("PLUGINSD: '%s' called DISABLE. Disabling it.", cd->fullfilename);
333
cd->enabled = 0;
326
- kill(cd->pid, SIGTERM);
334
+ // test: killing an exited child kills us - lets check it exists before killing it
335
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
336
break;
337
}
338
#ifdef DETACH_PLUGINS_FROM_NETDATA
@@ -352,7 +361,8 @@ void *pluginsd_worker_thread(void *arg)
361
362
error("PLUGINSD: %s sleeping for %llu. Will kill with SIGCONT pid %d to wake it up.\n", cd->fullfilename, susec, cd->pid);
363
usleep(susec);
355
- kill(cd->pid, SIGCONT);
364
+ // test: killing an exited child kills us - lets check it exists before killing it
365
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGCONT);
366
bcopy(&now, &last, sizeof(struct timeval));
367
break;
368
}
@@ -360,7 +370,8 @@ void *pluginsd_worker_thread(void *arg)
370
else {
371
error("PLUGINSD: '%s' is sending command '%s' which is not known by netdata. Disabling it.", cd->fullfilename, s);
372
cd->enabled = 0;
363
- kill(cd->pid, SIGTERM);
373
+ // test: killing an exited child kills us - lets check it exists before killing it
374
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
375
break;
376
}
377
}
@@ -372,7 +383,8 @@ void *pluginsd_worker_thread(void *arg)
383
if(!count && cd->enabled) {
384
error("PLUGINSD: '%s' does not generate usefull output. Disabling it.", cd->fullfilename);
385
cd->enabled = 0;
375
- kill(cd->pid, SIGTERM);
386
+ // test: killing an exited child kills us - lets check it exists before killing it
387
+ if(kill(cd->pid, 0) != -1) kill(cd->pid, SIGTERM);
388
}
389
390
if(cd->enabled) sleep(cd->update_every);