From: Costa Tsaousis (ktsaou) Date: Tue, 5 May 2015 20:01:14 +0000 (+0300) Subject: fix for defunct childs X-Git-Tag: v0.2~26 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=557d1c9543199ed9098df800f32b920bee001674;p=netdata.git fix for defunct childs --- diff --git a/src/daemon.c b/src/daemon.c index 2b66aa04..e40040f6 100755 --- a/src/daemon.c +++ b/src/daemon.c @@ -37,8 +37,8 @@ void sig_handler(int signo) signal(SIGQUIT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); + signal(SIGCHLD, SIG_IGN); kill_childs(); - process_childs(0); rrdset_free_all(); //unlink("/var/run/netdata.pid"); info("NetData exiting. Bye bye..."); @@ -51,12 +51,6 @@ void sig_handler(int signo) // info("Ignoring signal %d. Errno: %d (%s)", signo, errno, strerror(errno)); break; - - case SIGCHLD: - info("Received SIGCHLD (signal %d).", signo); - process_childs(0); - break; - default: info("Signal %d received. Falling back to default action for it.", signo); signal(signo, SIG_DFL); @@ -200,8 +194,8 @@ int become_daemon(int close_all_files, const char *input, const char *output, co if (setsid() < 0) exit(2); - signal(SIGCHLD, SIG_IGN); - signal(SIGHUP, SIG_IGN); + signal(SIGCHLD, SIG_IGN); + signal(SIGHUP, SIG_IGN); signal(SIGWINCH, SIG_IGN); // fork() again diff --git a/src/main.c b/src/main.c index 6b11ab6b..68ac66c1 100755 --- a/src/main.c +++ b/src/main.c @@ -316,8 +316,20 @@ int main(int argc, char **argv) // catch all signals - for (i = 1 ; i < 65 ;i++) if(i != SIGSEGV && i != SIGFPE) signal(i, sig_handler); - + for (i = 1 ; i < 65 ;i++) { + switch(i) { + case SIGSEGV: + case SIGFPE: + case SIGCHLD: + signal(i, SIG_DFL); + break; + + default: + signal(i, sig_handler); + break; + } + } + for (i = 0; static_threads[i].name != NULL ; i++) { struct netdata_static_thread *st = &static_threads[i]; @@ -335,13 +347,8 @@ int main(int argc, char **argv) else info("Not starting thread %s.", st->name); } - // the main process - the web server listener - // this never ends - // socket_listen_main(NULL); - while(1) { - process_childs(1); - sleep(1); - } + // for future use - the main thread + while(1) sleep(60); exit(0); } diff --git a/src/plugin_tc.c b/src/plugin_tc.c index 708da019..3f6665a9 100755 --- a/src/plugin_tc.c +++ b/src/plugin_tc.c @@ -580,7 +580,8 @@ void *tc_main(void *ptr) // debug(D_TC_LOOP, "IGNORED line"); //} } - mypclose(fp); + mypclose(fp, tc_child_pid); + tc_child_pid = 0; if(device) { // tc_device_free(device); diff --git a/src/plugins_d.c b/src/plugins_d.c index c39266c4..1bc56775 100755 --- a/src/plugins_d.c +++ b/src/plugins_d.c @@ -366,7 +366,8 @@ void *pluginsd_worker_thread(void *arg) } // fgets() failed or loop broke - mypclose(fp); + mypclose(fp, cd->pid); + cd->pid = 0; if(!count && cd->enabled) { error("PLUGINSD: '%s' does not generate usefull output. Disabling it.", cd->fullfilename); diff --git a/src/popen.c b/src/popen.c index ab064d48..279373b4 100755 --- a/src/popen.c +++ b/src/popen.c @@ -6,7 +6,46 @@ #include "log.h" #include "popen.h" +/* +struct mypopen { + pid_t pid; + FILE *fp; + struct mypopen *next; + struct mypopen *prev; +}; + +static struct mypopen *mypopen_root = NULL; + +static void mypopen_add(FILE *fp, pid_t *pid) { + struct mypopen *mp = malloc(sizeof(struct mypopen)); + if(!mp) { + fatal("Cannot allocate %zu bytes", sizeof(struct mypopen)) + return; + } + + mp->fp = fp; + mp->pid = pid; + mp->next = popen_root; + mp->prev = NULL; + if(mypopen_root) mypopen_root->prev = mp; + mypopen_root = mp; +} + +static void mypopen_del(FILE *fp) { + struct mypopen *mp; + for(mp = mypopen_root; mp; mp = mp->next) + if(mp->fd == fp) break; + + if(!mp) error("Cannot find mypopen() file pointer in open childs."); + else { + if(mp->next) mp->next->prev = mp->prev; + if(mp->prev) mp->prev->next = mp->next; + if(mypopen_root == mp) mypopen_root = mp->next; + free(mp); + } +} +*/ #define PIPE_READ 0 #define PIPE_WRITE 1 @@ -27,6 +66,7 @@ FILE *mypopen(const char *command, pid_t *pidptr) *pidptr = pid; close(pipefd[PIPE_WRITE]); FILE *fp = fdopen(pipefd[PIPE_READ], "r"); + /*mypopen_add(fp, pid);*/ return(fp); } // the child @@ -68,7 +108,7 @@ FILE *mypopen(const char *command, pid_t *pidptr) fflush(NULL); #endif - // ignore all signals + // reset all signals for (i = 1 ; i < 65 ;i++) if(i != SIGSEGV) signal(i, SIG_DFL); fprintf(stderr, "executing command: '%s' on pid %d.\n", command, getpid()); @@ -76,24 +116,12 @@ FILE *mypopen(const char *command, pid_t *pidptr) exit(1); } -void mypclose(FILE *fp) -{ - // this is a very poor implementation of pclose() - // the caller should catch SIGCHLD and waitpid() on the exited child - // otherwise the child will be a zombie forever - +void mypclose(FILE *fp, pid_t pid) { + /*mypopen_del(fp);*/ fclose(fp); -} -void process_childs(int wait) -{ siginfo_t info; - int options = WEXITED; - if(!wait) options |= WNOHANG; - - info.si_pid = 0; - while(waitid(P_ALL, 0, &info, options) == 0) { - if(!info.si_pid) break; + if(waitid(P_PID, pid, &info, WEXITED) != -1) { switch(info.si_code) { case CLD_EXITED: error("pid %d exited with code %d.", info.si_pid, info.si_status); @@ -123,8 +151,6 @@ void process_childs(int wait) error("pid %d gave us a SIGCHLD with code %d and status %d.", info.si_pid, info.si_code, info.si_status); break; } - - // prevent an infinite loop - info.si_pid = 0; } + else error("Cannot waitid() for pid %d", pid); } diff --git a/src/popen.h b/src/popen.h index f2ef866a..2f006942 100755 --- a/src/popen.h +++ b/src/popen.h @@ -9,7 +9,6 @@ #define PIPE_WRITE 1 extern FILE *mypopen(const char *command, pid_t *pidptr); -extern void mypclose(FILE *fp); -extern void process_childs(int wait); +extern void mypclose(FILE *fp, pid_t pid); #endif /* NETDATA_POPEN_H */ diff --git a/web/index.js b/web/index.js index fc376e53..ea248eb0 100755 --- a/web/index.js +++ b/web/index.js @@ -4,13 +4,13 @@ var TARGET_THUMB_GRAPH_WIDTH = 500; // thumb charts width will range from 0.5 t var MINIMUM_THUMB_GRAPH_WIDTH = 400; // thumb chart will generally try to be wider than that var TARGET_THUMB_GRAPH_HEIGHT = 180; // the height of the thumb charts -var THUMBS_MAX_TIME_TO_SHOW = 600; // how much time the thumb charts will present? -var THUMBS_POINTS_DIVISOR = 4; -var THUMBS_STACKED_POINTS_DIVISOR = 10; +var THUMBS_MAX_TIME_TO_SHOW = 240; // how much time the thumb charts will present? +var THUMBS_POINTS_DIVISOR = 3; +var THUMBS_STACKED_POINTS_DIVISOR = 3; -var GROUPS_MAX_TIME_TO_SHOW = 600; // how much time the thumb charts will present? -var GROUPS_POINTS_DIVISOR = 4; -var GROUPS_STACKED_POINTS_DIVISOR = 10; +var GROUPS_MAX_TIME_TO_SHOW = 120; // how much time the thumb charts will present? +var GROUPS_POINTS_DIVISOR = 2; +var GROUPS_STACKED_POINTS_DIVISOR = 2; var MAINCHART_MAX_TIME_TO_SHOW = 600; // how much time the main chart will present by default? var MAINCHART_POINTS_DIVISOR = 5; // how much detailed will the main chart be by default? 1 = finest, higher is faster