Merge (from 1_0_BRANCH) rev 1.16.2.4 of the old vg_cachesim.c:

Make file_err() not abort the current process; recover and keep
going instead.  This fixes a problem running OpenOffice on cachegrind.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1362 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c
index cca46f0..2a91bc0 100644
--- a/cachegrind/cg_main.c
+++ b/cachegrind/cg_main.c
@@ -81,12 +81,13 @@
 
 Char cachegrind_out_file[FILENAME_LEN];
 
-static void file_err()
+static void file_err ( void )
 {
    VG_(message)(Vg_UserMsg,
-                "error: can't open cache simulation output file `%s'",
-                cachegrind_out_file );
-   VG_(exit)(1);
+      "error: can't open cache simulation output file `%s'",
+      cachegrind_out_file );
+   VG_(message)(Vg_UserMsg,
+      "       ... so simulation results will be missing.");
 }
 
 /*------------------------------------------------------------*/
@@ -1516,7 +1517,12 @@
 
    VGP_PUSHCC(VgpCacheResults);
    fd = VG_(open)(cachegrind_out_file, VKI_O_WRONLY|VKI_O_TRUNC, 0);
-   if (-1 == fd) { file_err(); }
+   if (-1 == fd) { 
+      /* If the file can't be opened for whatever reason (conflict
+         between multiple cachegrinded processes?), give up now. */
+      file_err(); 
+      return;
+   }
 
    /* "desc:" lines (giving I1/D1/L2 cache configuration) */
    VG_(sprintf)(buf, "desc: I1 cache:         %s\n", I1.desc_line);
@@ -1954,7 +1960,8 @@
          file_err(); 
       }
    }
-   VG_(close)(fd);
+   if (-1 != fd)
+      VG_(close)(fd);
 
    initCC(&Ir_total);
    initCC(&Dr_total);