From: Nicolas Boichat Date: Sat, 30 Jul 2005 15:59:04 +0000 (+0000) Subject: Fix src/lib/bpipe.c:run_program and run_program_full_output to detect if the watchdog... X-Git-Tag: Release-7.0.0~8559 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e72b99d3c60cc55561f6698ff1f7f8569d63f4c8;p=bacula%2Fbacula Fix src/lib/bpipe.c:run_program and run_program_full_output to detect if the watchdog killed the program, and return an error if it is the case. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2272 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/nb-1.37 b/bacula/nb-1.37 index 8df6fb5d34..6b206f9c4d 100644 --- a/bacula/nb-1.37 +++ b/bacula/nb-1.37 @@ -4,6 +4,9 @@ General: Changes to 1.37.*: +30Jul05 + - Fix src/lib/bpipe.c:run_program and run_program_full_output to detect if the watchdog + killed the program, and return an error if it is the case. 26Apr05 - Modify parse_config to get a LEX_ERROR_HANDLER as a parameter - lex_open_file now returns NULL if the file can't be opened. All calling functions have diff --git a/bacula/src/lib/bpipe.c b/bacula/src/lib/bpipe.c index 45fffe4447..f2e4dd77fe 100644 --- a/bacula/src/lib/bpipe.c +++ b/bacula/src/lib/bpipe.c @@ -239,6 +239,9 @@ int close_bpipe(BPIPE *bpipe) * of seconds. Program killed if wait exceeded. Optionally * return the output from the program (normally a single line). * + * If the watchdog kills the program, fgets returns, and ferror is set + * to 1 (=>SUCCESS), so we check if the watchdog killed the program. + * * Contrary to my normal calling conventions, this program * * Returns: 0 on success @@ -269,6 +272,16 @@ int run_program(char *prog, int wait, POOLMEM *results) Dmsg2(100, "Run program fgets stat=%d ERR=%s\n", stat1, strerror(errno)); } else if (stat1 != 0) { Dmsg1(100, "Run program fgets stat=%d\n", stat1); + if (bpipe->timer_id) { + Dmsg1(100, "Run program fgets killed=%d\n", bpipe->timer_id->killed); + /* NB: I'm not sure it is really useful for run_program. Without the + * following lines run_program would not detect if the program was killed + * by the watchdog. */ + if (bpipe->timer_id->killed) { + stat1 = -EPIPE; + pm_strcat(results, "Program killed by Bacula watchdog (timeout)\n"); + } + } } } else { stat1 = 0; @@ -283,6 +296,10 @@ int run_program(char *prog, int wait, POOLMEM *results) * Run an external program. Optionally wait a specified number * of seconds. Program killed if wait exceeded (it is done by the * watchdog, as fgets is a blocking function). + * + * If the watchdog kills the program, fgets returns, and ferror is set + * to 1 (=>SUCCESS), so we check if the watchdog killed the program. + * * Return the full output from the program (not only the first line). * * Contrary to my normal calling conventions, this program @@ -334,6 +351,14 @@ int run_program_full_output(char *prog, int wait, POOLMEM *results) break; } else if (stat1 != 0) { Dmsg1(900, "Run program fgets stat=%d\n", stat1); + if (bpipe->timer_id) { + Dmsg1(100, "Run program fgets killed=%d\n", bpipe->timer_id->killed); + if (bpipe->timer_id->killed) { + pm_strcat(tmp, "Program killed by Bacula watchdog (timeout)\n"); + stat1 = -EPIPE; + break; + } + } } } int len = sizeof_pool_memory(results) - 1;