]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix src/lib/bpipe.c:run_program and run_program_full_output to detect if the watchdog...
authorNicolas Boichat <nicolas@boichat.ch>
Sat, 30 Jul 2005 15:59:04 +0000 (15:59 +0000)
committerNicolas Boichat <nicolas@boichat.ch>
Sat, 30 Jul 2005 15:59:04 +0000 (15:59 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2272 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/nb-1.37
bacula/src/lib/bpipe.c

index 8df6fb5d34dddf1560bf807f742128b0cbdbf24d..6b206f9c4df6bbdaa0e55ed59184dfcd50ca0c86 100644 (file)
@@ -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
index 45fffe4447cae1c02bed921778e8a6eae87c9001..f2e4dd77fe7ed90d9159d7094261c955977dbdfc 100644 (file)
@@ -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;