chiark / gitweb /
New flush completion
authorIan Jackson <ian@liberator.(none)>
Wed, 24 Mar 2010 00:25:28 +0000 (00:25 +0000)
committerIan Jackson <ian@liberator.(none)>
Wed, 24 Mar 2010 00:25:28 +0000 (00:25 +0000)
backends/innduct.c

index 54e61969863931b532961eb1822e5dd7895b1412..33adaf8097f4692536f11e15e78b884c87f58e0e 100644 (file)
@@ -153,6 +153,7 @@ static int max_connections, max_queue_per_conn;
 static int connection_setup_timeout, port, try_stream;
 static int inndcomm_flush_timeout;
 static const char *remote_host;
 static int connection_setup_timeout, port, try_stream;
 static int inndcomm_flush_timeout;
 static const char *remote_host;
+static int reconnect_delay_periods, flushfail_retry_periods, open_wait_periods;
 
 static double accept_proportion;
 static double nocheck_thresh= 0.95;
 
 static double accept_proportion;
 static double nocheck_thresh= 0.95;
@@ -281,7 +282,7 @@ static char *path_ductlock, *path_duct, *path_ductdefer;
 static StateMachineState sms;
 static FILE *defer;
 static InputFile *main_input_file, *old_input_file;
 static StateMachineState sms;
 static FILE *defer;
 static InputFile *main_input_file, *old_input_file;
-static int waiting_periods_sofar;
+static int sm_period_counter;
 
 
 /*----- function predeclarations -----*/
 
 
 /*----- function predeclarations -----*/
@@ -1457,21 +1458,33 @@ static void statemc_init(void) {
     }
   } else { /*!file_d*/
     sms= sm_WAITING;
     }
   } else { /*!file_d*/
     sms= sm_WAITING;
-    statemc_waiting_poll();
+    sm_period_counter= open_wait_periods;
   }
 }
 
 static void statemc_poll(void) {
   }
 }
 
 static void statemc_poll(void) {
-  if (sms==sm_WAITING) statemc_waiting_poll();
+  if (sms==sm_WAITING)
+    statemc_waiting_poll();
+
+  if (!sm_period_counter) return;
+  sm_period_counter--;
+  assert(sm_period_counter>=0);
+
+  if (sm_period_counter) return;
+  switch (sms) {
+  case sm_WAITING:
+    die("timed out waiting for innd to create feed file %s", feedfile);
+  case sm_FLUSHFAIL:
+    spawn_inndcomm_flush(void);
+    break;
+  default:
+    abort();
+  }
 }
 
 static void statemc_waiting_poll(void) {
   InputFile *file_f= open_input_file(feedfile);
 }
 
 static void statemc_waiting_poll(void) {
   InputFile *file_f= open_input_file(feedfile);
-  if (!file_f) {
-    if (waiting_periods_sofar++ > waiting_timeout_periods)
-      die("timed out waiting for innd to create feed file %s", feedfile);
-    return;
-  }
+  if (!file_f) return;
   startup_set_input_file(file_d);
   sms= sm_NORMAL;
 }
   startup_set_input_file(file_d);
   sms= sm_NORMAL;
 }
@@ -1520,6 +1533,8 @@ static void *statemc_check_oldinput_done(oop_source *lp,
   close_input_file(old_input_file);
   old_input_file= 0;
 
   close_input_file(old_input_file);
   old_input_file= 0;
 
+  notice("flush complete");
+
   sms= sm_NORMAL;
 }
 
   sms= sm_NORMAL;
 }
 
@@ -1566,7 +1581,7 @@ static void *inndcomm_event(oop_source *lp, int fd, oop_event e, void *u) {
       
     }
   } else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGALRM) {
       
     }
   } else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGALRM) {
-    warn("flush of %s timed out trying to talk to innd", feedname);
+    warn("flush timed out trying to talk to innd");
     goto failed;
   } else {
   unexpected_exitstatus:
     goto failed;
   } else {
   unexpected_exitstatus:
@@ -1574,12 +1589,14 @@ static void *inndcomm_event(oop_source *lp, int fd, oop_event e, void *u) {
   }
 
  failed:
   }
 
  failed:
-  
+  sm_period_counter= flushfail_retry_periods;
+  sms= sm_FLUSHFAIL;;
+}
 
 void spawn_inndcomm_flush(void) {
   int pipefds[2];
 
 
 void spawn_inndcomm_flush(void) {
   int pipefds[2];
 
-  assert(sms == sm_NORMAL);
+  assert(sms==sm_NORMAL || sms==sm_FLUSHFAIL);
   assert(!inndcomm_child);
 
   if (pipe(pipefds)) sysdie("create pipe for inndcomm child sentinel");
   assert(!inndcomm_child);
 
   if (pipe(pipefds)) sysdie("create pipe for inndcomm child sentinel");
@@ -1598,7 +1615,7 @@ void spawn_inndcomm_flush(void) {
     if (!r) exit(0); /* yay! */
 
     if (!strcmp(reply, "1 No such site")) exit(INNDCOMMCHILD_ESTATUS_NONESUCH);
     if (!r) exit(0); /* yay! */
 
     if (!strcmp(reply, "1 No such site")) exit(INNDCOMMCHILD_ESTATUS_NONESUCH);
-    syswarn("innd ctlinnd flush %s failed: innd said %s", feedname, reply);
+    syswarn("innd ctlinnd flush failed: innd said %s", reply);
     exit(INNDCOMMCHILD_ESTATUS_FAIL);
   }
 
     exit(INNDCOMMCHILD_ESTATUS_FAIL);
   }