Index: /trunk/docs/Changelog
===================================================================
--- /trunk/docs/Changelog	(revision 524)
+++ /trunk/docs/Changelog	(revision 525)
@@ -1,2 +1,5 @@
+4.2.2:
+	* add success/failure message for closing baseline database at init
+
 4.2.1:
 	* fix for broken SetSocketPassword authentication
Index: /trunk/include/sh_cat.h
===================================================================
--- /trunk/include/sh_cat.h	(revision 524)
+++ /trunk/include/sh_cat.h	(revision 525)
@@ -76,5 +76,6 @@
  MSG_CHECK_1,     
  MSG_CHECK_2,     
- MSG_STAMP,       
+ MSG_STAMP,
+ MSG_DCLOSE,
  		  
  MSG_D_START,     
Index: /trunk/include/slib.h
===================================================================
--- /trunk/include/slib.h	(revision 524)
+++ /trunk/include/slib.h	(revision 525)
@@ -108,4 +108,5 @@
 #define SL_EWRITE    -1037     /* Write error. Check errno.            */
 #define SL_ESYNC     -1038     /* Write error. Check errno.            */
+#define SL_ECLOSE    -1039     /* Close error. Check errno.            */
 
 #define SL_EBADNAME  -1040     /* Invalid name.                        */
Index: /trunk/src/sh_cat.c
===================================================================
--- /trunk/src/sh_cat.c	(revision 524)
+++ /trunk/src/sh_cat.c	(revision 525)
@@ -72,5 +72,6 @@
   { MSG_CHECK_2,     SH_ERR_STAMP,   STAMP, N_("msg=\"File check starting.\"")},
   { MSG_STAMP,       SH_ERR_STAMP,   STAMP, N_("msg=\"---- TIMESTAMP ----\"")},
-
+  { MSG_DCLOSE,      SH_ERR_NOTICE,  RUN,   N_("msg=\"Finished writing baseline database.\"")},
+  
   { MSG_D_START,     SH_ERR_INFO,    RUN,   N_("msg=\"Downloading configuration file\"")},
   { MSG_D_DSTART,    SH_ERR_INFO,    RUN,   N_("msg=\"Downloading database file\"")},
@@ -403,4 +404,5 @@
   { MSG_CHECK_2,     SH_ERR_STAMP,   STAMP, N_("msg=<File check starting.>")},
   { MSG_STAMP,       SH_ERR_STAMP,   STAMP, N_("msg=<---- TIMESTAMP ---->")},
+  { MSG_DCLOSE,      SH_ERR_NOTICE,  RUN,   N_("msg=<Finished writing baseline database.>")},
 
   { MSG_D_START,     SH_ERR_INFO,    RUN,   N_("msg=<Downloading configuration file>")},
Index: /trunk/src/sh_dbIO.c
===================================================================
--- /trunk/src/sh_dbIO.c	(revision 524)
+++ /trunk/src/sh_dbIO.c	(revision 525)
@@ -152,4 +152,6 @@
 }
 
+/* Seek to [SOF] and truncate remainder of file
+ */
 static int sh_dbIO_setdataent_old (SL_TICKET fd, char * line, int size, 
 				   const char * file)
@@ -1117,13 +1119,17 @@
 }
 
+/* Seek to [SOF] and truncate remainder
+ */
 static int seek_writeout_data_old(SL_TICKET fd, const char * path)
 {
   char * line = SH_ALLOC(MAX_PATH_STORE+1);
 
+  /* This will do an ftruncate() after the sof marker
+   */
   if (SL_ISERROR(sh_dbIO_setdataent_old (fd, line, MAX_PATH_STORE, path)))
     {
       SH_FREE(line);
       sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGPATH,
-		      _("Failed to seek to end of baseline database"),
+		      _("Failed to seek to start of baseline database"),
 		      _("seek_writeout_data_old"),
 		      path);
@@ -1414,4 +1420,5 @@
 	    {
 	      pushdata_fd = open_writeout_data(outpath);
+	      /* Seek to eof */
 	      seek_writeout_data(pushdata_fd, outpath);
 	    }
@@ -1424,4 +1431,5 @@
 	  TPT((0, FIL__, __LINE__, _("msg=<Update.>\n")));
 	  pushdata_fd = open_writeout_data(outpath);
+	  /* Seek to sof and truncate */
 	  seek_writeout_data_old(pushdata_fd, outpath);
  	}
@@ -1479,5 +1487,17 @@
       if (sh.flag.checkSum != SH_CHECK_INIT || (buf == NULL && fileHash == NULL))
 	{
-	  sl_close (pushdata_fd);
+	  if (SL_ISERROR(sl_close (pushdata_fd))) 
+	    {
+	      char * tmp = sh_util_safe_name(outpath);
+	      sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGPATH,
+			      _("Failed to close baseline database"),
+			      _("sh_dbIO_data_write_int"),
+			      tmp);
+	      SH_FREE(tmp);
+	    }
+	  else {
+	    if (sh.flag.checkSum == SH_CHECK_INIT)
+	      sh_error_handle((-1), FIL__, __LINE__, 0, MSG_DCLOSE);
+	  }
 	  pushdata_fd = -1;
 	}
Index: /trunk/src/slib.c
===================================================================
--- /trunk/src/slib.c	(revision 524)
+++ /trunk/src/slib.c	(revision 525)
@@ -2383,4 +2383,5 @@
 	       _("msg=<Error fclosing file.>, fd=<%d>, err=<%s>\n"), 
 	       fd, strerror(errno)));
+	  SL_IRETURN(SL_ECLOSE, _("sl_close")); 
 	}
     }
@@ -2392,4 +2393,5 @@
 	       _("msg=<Error closing file.>, fd=<%d>, err=<%s>\n"), 
 	       fd, strerror(errno)));
+	  SL_IRETURN(SL_ECLOSE, _("sl_close")); 
 	}
     }
