Index: /trunk/docs/Changelog
===================================================================
--- /trunk/docs/Changelog	(revision 304)
+++ /trunk/docs/Changelog	(revision 305)
@@ -1,3 +1,5 @@
 2.8.1:
+	* Fix incorrect handling of missing files when secondary schedule
+	  is used (reported by Sergey)
 	* Fix null pointer dereference in config parse handler for SetMailAlias
 	  (reported by Sergey)
Index: /trunk/include/sh_hash.h
===================================================================
--- /trunk/include/sh_hash.h	(revision 304)
+++ /trunk/include/sh_hash.h	(revision 305)
@@ -35,4 +35,8 @@
  */
 int hashreport_missing( char *fullpath, int level);
+
+/* remove internal db record for a file
+ */
+void sh_hash_remove (const char * path);
 
 /* write database to stdout
Index: /trunk/include/sh_utils.h
===================================================================
--- /trunk/include/sh_utils.h	(revision 304)
+++ /trunk/include/sh_utils.h	(revision 305)
@@ -94,5 +94,5 @@
 /* ask if a file should be updated (returns S_TRUE/S_FALSE)
  */
-int sh_util_ask_update(char * path);
+int sh_util_ask_update(const char * path);
 int sh_util_set_interactive(const char * str);
 
Index: /trunk/src/samhain.c
===================================================================
--- /trunk/src/samhain.c	(revision 304)
+++ /trunk/src/samhain.c	(revision 305)
@@ -2024,4 +2024,5 @@
 	  if (flag_check_2 == 1 || FileSchedTwo == NULL)
 	    {
+	      fprintf(stderr, "FIXME check unvisited\n");
 	      TPT((0, FIL__, __LINE__, _("msg=<Check for missing files.>\n")))
 	      sh_hash_unvisited (ShDFLevel[SH_ERR_T_FILE]);
Index: /trunk/src/sh_files.c
===================================================================
--- /trunk/src/sh_files.c	(revision 304)
+++ /trunk/src/sh_files.c	(revision 305)
@@ -377,4 +377,5 @@
 		  if (S_FALSE == sh_ignore_chk_del(ptr->name))
 		    {
+		      fprintf(stderr, "FIXME 1 %s, %d\n", ptr->name, ptr->is_reported);
 		      if (0 != hashreport_missing(ptr->name, 
 						  (ptr->class == SH_LEVEL_ALLIGNORE) ? 
@@ -430,8 +431,10 @@
 		   * file has been added.
 		   */
-		  if (sh_hash_have_it (ptr->name) >= 0)
+		  if (sh_hash_have_it (ptr->name) >= 0 && 
+		      !SH_FFLAG_REPORTED_SET(ptr->is_reported))
 		    {
 		      if (S_FALSE == sh_ignore_chk_del(ptr->name))
 			{
+			  fprintf(stderr, "FIXME 2 %s, %d\n", ptr->name, ptr->is_reported);
 			  if (0 != hashreport_missing(ptr->name, 
 						      (ptr->class == SH_LEVEL_ALLIGNORE) ? 
@@ -1289,4 +1292,5 @@
 	      if (S_FALSE == sh_ignore_chk_del(ptr->name))
 		{
+		  fprintf(stderr, "FIXME 2 %s, %d\n", ptr->name, ptr->is_reported);
 		  if (0 != hashreport_missing(ptr->name, 
 					      (ptr->class == SH_LEVEL_ALLIGNORE) ? 
Index: /trunk/src/sh_hash.c
===================================================================
--- /trunk/src/sh_hash.c	(revision 304)
+++ /trunk/src/sh_hash.c	(revision 305)
@@ -393,5 +393,11 @@
 }
 
+struct two_sh_file_t {
+  sh_file_t * prev;
+  sh_file_t * this;
+};
+
 static sh_file_t * hashsearch (const char * s);
+static int hashsearch_prev (const char * s, struct two_sh_file_t * a, int * index); 
 
 static sh_file_t * tab[TABSIZE];
@@ -423,4 +429,5 @@
   char hashbuf[KEYBUF_SIZE];
   int  retval;
+  volatile int flag = 0;
 
   /* --------  find the entry for the file ----------------       */
@@ -449,4 +456,5 @@
   sh_error_handle (level, FIL__, __LINE__, 0, 
 		   MSG_FI_MISS2, tmp, str);
+  flag = 1;
   SH_FREE(tmp);
   SH_FREE(str);
@@ -458,4 +466,5 @@
   ; /* 'label at end of compound statement */
   SH_MUTEX_UNLOCK(mutex_hash);
+
   return retval;
 }
@@ -625,4 +634,5 @@
 
 
+
 /*********************************************************************
  *
@@ -646,4 +656,50 @@
   SL_RET0(_("hash_unvisited"));
 }
+
+/*********************************************************************
+ *
+ * Remove a single file from the database.
+ *
+ *********************************************************************/
+void sh_hash_remove (const char * path)
+{
+  struct two_sh_file_t entries;
+  int index;
+
+  SL_ENTER(_("sh_hash_remove"));
+
+  SH_MUTEX_LOCK(mutex_hash);
+
+  if ((sh.flag.reportonce == S_TRUE && sh.flag.update == S_FALSE) || 
+      (S_TRUE == sh.flag.update && S_TRUE == sh_util_ask_update(path)))
+    {
+      if (0 == hashsearch_prev (path, &entries, &index))
+	{
+	  sh_file_t * p = entries.this;
+#ifdef REPLACE_OLD
+	  /* Remove the old entry
+	   */
+	  if (entries.prev == p)
+	    tab[index] = p->next;
+	  else
+	    entries.prev->next = p->next;
+	  
+	  p = delete_db_entry(p);
+	  
+	  goto end;
+	  SL_RET0(_("sh_hash_remove"));
+#else
+	  SET_SH_FFLAG_REPORTED(p->fflags); 
+#endif
+	}
+    }
+
+ end:
+  ; /* 'label at end of compound statement' */
+  SH_MUTEX_UNLOCK(mutex_hash);
+
+  SL_RET0(_("sh_hash_remove"));
+}
+
 
 /*********************************************************************
@@ -772,4 +828,40 @@
     } 
   SL_RETURN( NULL, _("hashsearch"));
+} 
+
+static int hashsearch_prev (const char * s, struct two_sh_file_t * a, int * index) 
+{
+  sh_file_t * this;
+  sh_file_t * prev = NULL;
+
+  SL_ENTER(_("hashsearch_prev"));
+
+  if (s)
+    {
+      *index = hashfunc(s);
+
+      this = tab[*index];
+
+      prev  = this;
+
+      if (this)
+	{
+	  do {
+	    
+	    if ((this->fullpath != NULL) && (0 == strcmp(s, this->fullpath)))
+	      {
+		a->prev = prev;
+		a->this = this;
+		
+		SL_RETURN( 0, _("hashsearch_prev"));
+	      }
+	    
+	    prev = this;
+	    this = this->next;
+	    
+	  } while(this);
+	} 
+    }
+  SL_RETURN( -1, _("hashsearch"));
 } 
 
@@ -2226,5 +2318,11 @@
   int i;
   SL_ENTER(_("sh_hash_set_missing"));
+
   i = sh_hash_set_visited_int(newname, SH_FFLAG_CHECKED);
+
+  if (sh.flag.checkSum != SH_CHECK_INIT) {
+    sh_hash_remove(newname);
+  }
+
   SL_RETURN(i, _("sh_hash_set_missing"));
 }
Index: /trunk/src/sh_utils.c
===================================================================
--- /trunk/src/sh_utils.c	(revision 304)
+++ /trunk/src/sh_utils.c	(revision 305)
@@ -120,5 +120,5 @@
 #endif
 
-int sh_util_ask_update(char * path)
+int sh_util_ask_update(const char * path)
 {
   int    inchar, c;
