]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
When creating a logfile name, add a sequence number to the name in case
authorJeremy Fitzhardinge <jeremy@valgrind.org>
Tue, 14 Oct 2003 22:13:28 +0000 (22:13 +0000)
committerJeremy Fitzhardinge <jeremy@valgrind.org>
Tue, 14 Oct 2003 22:13:28 +0000 (22:13 +0000)
a logfile for that pid already exists.  This may happen for programs
started during system boot which will tend to get the same pid each boot.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1928

coregrind/vg_errcontext.c
coregrind/vg_main.c
coregrind/vg_mylibc.c
coregrind/vg_procselfmaps.c
coregrind/vg_symtab2.c
include/vg_kerneliface.h

index 96fe88a96cbc848e3588edcdf3c745c6d5782484..3c76f05cbc81d83e58ebf75cab87f0ad2c3c449b 100644 (file)
@@ -661,7 +661,7 @@ static void load_one_suppressions_file ( Char* filename )
    Char* supp_name;
 
    fd = VG_(open)( filename, VKI_O_RDONLY, 0 );
-   if (fd == -1) {
+   if (fd < 0) {
       VG_(message)(Vg_UserMsg, "FATAL: can't open suppressions file `%s'", 
                    filename );
       VG_(exit)(1);
index 8680af074526284a6b3cb1f340aa3c502fb5dde2..43a2315f0062f51f804999bb3a126c0b040f6472 100644 (file)
@@ -1161,22 +1161,39 @@ static void process_cmd_line_options ( void )
 
       case VgLogTo_File: {
          Char logfilename[1000];
+        Int seq = 0;
+        Int pid = VG_(getpid)();
+
          vg_assert(VG_(clo_logfile_name) != NULL);
          vg_assert(VG_(strlen)(VG_(clo_logfile_name)) <= 900); /* paranoia */
-         VG_(sprintf)(logfilename, "%s.pid%d",
-                      VG_(clo_logfile_name), VG_(getpid)() );
-         eventually_logfile_fd 
-            = VG_(open)(logfilename, VKI_O_CREAT|VKI_O_WRONLY, 
-                                     VKI_S_IRUSR|VKI_S_IWUSR);
-         if (eventually_logfile_fd != -1) {
-            VG_(clo_logfile_fd) = eventually_logfile_fd;
-         } else {
-            VG_(message)(Vg_UserMsg, 
-               "Can't create/open log file `%s.pid%d'; giving up!", 
-               VG_(clo_logfile_name), VG_(getpid)());
-            VG_(bad_option)(
-               "--logfile=<file> didn't work out for some reason.");
-         }
+
+        for(;;) {
+           if (seq == 0)
+              VG_(sprintf)(logfilename, "%s.pid%d",
+                           VG_(clo_logfile_name), pid );
+           else
+              VG_(sprintf)(logfilename, "%s.pid%d.%d",
+                           VG_(clo_logfile_name), pid, seq );
+           seq++;
+
+           eventually_logfile_fd 
+              = VG_(open)(logfilename, 
+                          VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC, 
+                          VKI_S_IRUSR|VKI_S_IWUSR);
+           if (eventually_logfile_fd >= 0) {
+              VG_(clo_logfile_fd) = eventually_logfile_fd;
+              break;
+           } else {
+              if (eventually_logfile_fd != -VKI_EEXIST) {
+                 VG_(message)(Vg_UserMsg, 
+                              "Can't create/open log file `%s.pid%d'; giving up!", 
+                              VG_(clo_logfile_name), pid);
+                 VG_(bad_option)(
+                    "--logfile=<file> didn't work out for some reason.");
+                 break;
+              }
+           }
+        }
          break;
       }
 
index 811818f1a4676d5a343c781e9769f508289bdd2e..5aa4c095e9a38d0cf1377961d73232c762da435c 100644 (file)
@@ -1171,7 +1171,7 @@ Int VG_(open) ( const Char* pathname, Int flags, Int mode )
       ok: */
    fd = VG_(do_syscall)(__NR_open, (UInt)pathname, flags, mode);
    /* VG_(printf)("result = %d\n", fd); */
-   if (VG_(is_kerror)(fd)) fd = -1;
+   /* return -ve error code */
    return fd;
 }
 
index 6350b564e1b0bbb334c291a20e077a1889ad33f7..33186f11faaa1ba2602dd2cbec7e87ffa498bbbc 100644 (file)
@@ -77,7 +77,7 @@ void VG_(read_procselfmaps)(void)
    
    /* Read the initial memory mapping from the /proc filesystem. */
    fd = VG_(open) ( "/proc/self/maps", VKI_O_RDONLY, 0 );
-   if (fd == -1) {
+   if (fd < 0) {
       VG_(message)(Vg_UserMsg, "FATAL: can't open /proc/self/maps");
       VG_(exit)(1);
    }
index 6af77134878f4205d234efdb5b1d24fba7d4c64d..3a227e21b235b2b9af90a4f5918a6fced5beda28 100644 (file)
@@ -743,7 +743,7 @@ Bool vg_read_lib_symbols ( SegInfo* si )
    n_oimage = stat_buf.st_size;
 
    fd = VG_(open)(si->filename, VKI_O_RDONLY, 0);
-   if (fd == -1) {
+   if (fd < 0) {
       VG_(symerr)("Can't open .so/.exe to read symbols?!");
       return False;
    }
index 9b281d260d8e3a672ad9b138b20ada9471642109..a12dfee4a9b41c549d8ea464decdf5a77472bb8b 100644 (file)
@@ -359,6 +359,7 @@ struct vki_ucontext {
 #define VKI_EWOULDBLOCK     VKI_EAGAIN  /* Operation would block */
 #define VKI_EAGAIN          11      /* Try again */
 #define        VKI_EFAULT          14      /* Bad address */
+#define VKI_EEXIST         17      /* File exists */
 #define VKI_EINVAL          22      /* Invalid argument */
 #define VKI_EMFILE         24      /* Too many open files */
 #define VKI_ENOSYS          38      /* Function not implemented */