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")); 
 	}
     }
