]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
A commit which is almost all trivial change.
authorJulian Seward <jseward@acm.org>
Sat, 23 Jul 2005 09:18:34 +0000 (09:18 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 23 Jul 2005 09:18:34 +0000 (09:18 +0000)
- m_main: if --log-file-qualifier applies, do not add ".pid"
  at the end of the name

- Fix the logic which detected whether the just-devised name
  already existed.  This was broken (by me) because it could not
  distinguish the reasons for failing to open the logfile.

  Doing this required changing the return type of VG_(open)
  from Int to SysRes (to make failure reasons visible) and
  that's the cause of most of the changes.

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

cachegrind/cg_main.c
coregrind/m_aspacemgr/read_procselfmaps.c
coregrind/m_debuginfo/symtab.c
coregrind/m_errormgr.c
coregrind/m_libcfile.c
coregrind/m_main.c
coregrind/m_syswrap/syswrap-generic.c
include/pub_tool_libcfile.h
massif/ms_main.c

index 4f0bef445ad734882b2e6f05bd010f6748f0ebda..73d05a44709db4be8b6605d1c3a3661e7f5dfdba 100644 (file)
@@ -807,6 +807,7 @@ static void fprint_lineCC(Int fd, lineCC* n)
 static void fprint_CC_table_and_calc_totals(void)
 {
    Int     fd;
+   SysRes  sres;
    Char    buf[512];
    fileCC *curr_fileCC;
    fnCC   *curr_fnCC;
@@ -815,9 +816,9 @@ static void fprint_CC_table_and_calc_totals(void)
 
    VGP_PUSHCC(VgpCacheResults);
 
-   fd = VG_(open)(cachegrind_out_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
-                                       VKI_S_IRUSR|VKI_S_IWUSR);
-   if (fd < 0) {
+   sres = VG_(open)(cachegrind_out_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
+                                         VKI_S_IRUSR|VKI_S_IWUSR);
+   if (sres.isError) {
       // If the file can't be opened for whatever reason (conflict
       // between multiple cachegrinded processes?), give up now.
       VG_(message)(Vg_UserMsg,
@@ -826,6 +827,8 @@ static void fprint_CC_table_and_calc_totals(void)
       VG_(message)(Vg_UserMsg,
          "       ... so simulation results will be missing.");
       return;
+   } else {
+      fd = sres.val;
    }
 
    // "desc:" lines (giving I1/D1/L2 cache configuration).  The spaces after
index febef75357fbe4e25f9aa695f7bc673fe225d860..67373c8832798430911b867b4e62d709303642a4 100644 (file)
@@ -98,21 +98,22 @@ static Int readdec ( const Char* buf, UInt* val )
 
 static void read_procselfmaps ( void )
 {
-   Int n_chunk, fd;
+   Int    n_chunk;
+   SysRes fd;
    
    /* Read the initial memory mapping from the /proc filesystem. */
    fd = VG_(open) ( "/proc/self/maps", VKI_O_RDONLY, 0 );
-   if (fd < 0) {
+   if (fd.isError) {
       VG_(message)(Vg_UserMsg, "FATAL: can't open /proc/self/maps");
       VG_(exit)(1);
    }
    buf_n_tot = 0;
    do {
-      n_chunk = VG_(read) ( fd, &procmap_buf[buf_n_tot],
+      n_chunk = VG_(read) ( fd.val, &procmap_buf[buf_n_tot],
                             M_PROCMAP_BUF - buf_n_tot );
       buf_n_tot += n_chunk;
    } while ( n_chunk > 0 && buf_n_tot < M_PROCMAP_BUF );
-   VG_(close)(fd);
+   VG_(close)(fd.val);
    if (buf_n_tot >= M_PROCMAP_BUF-5) {
       VG_(message)(Vg_UserMsg, "FATAL: M_PROCMAP_BUF is too small; "
                                "increase it and recompile");
index 0af108ff0ad956c9bd8a4c69c81f1ea5291b5c74..8f1286d18af1d594765d9ec4804c6fee37a31f7e 100644 (file)
@@ -1145,16 +1145,17 @@ calc_gnu_debuglink_crc32(UInt crc, const UChar *buf, Int len)
 static
 Addr open_debug_file( Char* name, UInt crc, UInt* size )
 {
-   Int fd;
+   SysRes fd;
    struct vki_stat stat_buf;
    Addr addr;
    UInt calccrc;
 
-   if ((fd = VG_(open)(name, VKI_O_RDONLY, 0)) < 0)
+   fd = VG_(open)(name, VKI_O_RDONLY, 0);
+   if (fd.isError)
       return 0;
 
-   if (VG_(fstat)(fd, &stat_buf) != 0) {
-      VG_(close)(fd);
+   if (VG_(fstat)(fd.val, &stat_buf) != 0) {
+      VG_(close)(fd.val);
       return 0;
    }
 
@@ -1165,13 +1166,13 @@ Addr open_debug_file( Char* name, UInt crc, UInt* size )
    
    if ((addr = (Addr)VG_(mmap)(NULL, *size, VKI_PROT_READ,
                                VKI_MAP_PRIVATE|VKI_MAP_NOSYMS, 
-                               0, fd, 0)) == (Addr)-1) 
+                               0, fd.val, 0)) == (Addr)-1) 
    {
-      VG_(close)(fd);
+      VG_(close)(fd.val);
       return 0;
    }
 
-   VG_(close)(fd);
+   VG_(close)(fd.val);
    
    calccrc = calc_gnu_debuglink_crc32(0, (UChar*)addr, *size);
    if (calccrc != crc) {
@@ -1226,7 +1227,7 @@ Bool read_lib_symbols ( SegInfo* si )
    ElfXX_Ehdr*   ehdr;       /* The ELF header                          */
    ElfXX_Shdr*   shdr;       /* The section table                       */
    UChar*        sh_strtab;  /* The section table's string table        */
-   Int           fd;
+   SysRes        fd;
    Int           i;
    Bool          ok;
    Addr          oimage;
@@ -1251,16 +1252,16 @@ Bool read_lib_symbols ( SegInfo* si )
    n_oimage = stat_buf.st_size;
 
    fd = VG_(open)(si->filename, VKI_O_RDONLY, 0);
-   if (fd < 0) {
+   if (fd.isError) {
       ML_(symerr)("Can't open .so/.exe to read symbols?!");
       return False;
    }
 
    oimage = (Addr)VG_(mmap)( NULL, n_oimage, 
                              VKI_PROT_READ, VKI_MAP_PRIVATE|VKI_MAP_NOSYMS, 
-                             0, fd, 0 );
+                             0, fd.val, 0 );
 
-   VG_(close)(fd);
+   VG_(close)(fd.val);
 
    if (oimage == ((Addr)(-1))) {
       VG_(message)(Vg_UserMsg, "warning: mmap failed on %s", si->filename );
index 11e7acbd8e7b72e88d2e389a843e8803c3270676..50e1ab23de3480b34ceaed2c3f01074c7845e2da 100644 (file)
@@ -895,22 +895,25 @@ Bool tool_name_present(Char *name, Char *names)
 static void load_one_suppressions_file ( Char* filename )
 {
 #  define N_BUF 200
-   Int   fd, i;
-   Bool  eof;
-   Char  buf[N_BUF+1];
-   Char* tool_names;
-   Char* supp_name;
-   Char* err_str = NULL;
+   SysRes sres;
+   Int    fd, i;
+   Bool   eof;
+   Char   buf[N_BUF+1];
+   Char*  tool_names;
+   Char*  supp_name;
+   Char*  err_str = NULL;
    SuppLoc tmp_callers[VG_MAX_SUPP_CALLERS];
 
-   fd = VG_(open)( filename, VKI_O_RDONLY, 0 );
-   if (fd < 0) {
+   fd   = -1;
+   sres = VG_(open)( filename, VKI_O_RDONLY, 0 );
+   if (sres.isError) {
       VG_(message)(Vg_UserMsg, "FATAL: can't open suppressions file '%s'", 
                    filename );
       VG_(exit)(1);
    }
+   fd = sres.val;
 
-#define BOMB(S)  { err_str = S;  goto syntax_error; }
+#  define BOMB(S)  { err_str = S;  goto syntax_error; }
 
    while (True) {
       /* Assign and initialise the two suppression halves (core and tool) */
index 8d3865f8a41163575ff57a237eba8343962084c7..16c8087b1e8a8b1504225f3591be6f9ba498ebc5 100644 (file)
@@ -84,11 +84,10 @@ Bool VG_(resolve_filename) ( Int fd, HChar* buf, Int n_buf )
       return False;
 }
 
-/* Returns -1 on failure. */
-Int VG_(open) ( const Char* pathname, Int flags, Int mode )
+SysRes VG_(open) ( const Char* pathname, Int flags, Int mode )
 {  
    SysRes res = VG_(do_syscall3)(__NR_open, (UWord)pathname, flags, mode);
-   return res.isError ? -1 : res.val;
+   return res;
 }
 
 void VG_(close) ( Int fd )
index e33cdadcf390298cff8672e416838b23f76c6f70..6f4fee92b0c1d72bcb9542351c8b3fea72cd058f 100644 (file)
@@ -297,22 +297,23 @@ static void layout_remaining_space(Addr argc_addr, float ratio)
 static char* get_file_clo(char* dir)
 {
 #  define FLEN 512
-   Int fd, n;
+   Int    n;
+   SysRes fd;
    struct vki_stat s1;
-   char* f_clo = NULL;
-   char filename[FLEN];
+   Char* f_clo = NULL;
+   Char  filename[FLEN];
 
    snprintf(filename, FLEN, "%s/.valgrindrc", ( NULL == dir ? "" : dir ) );
    fd = VG_(open)(filename, 0, VKI_S_IRUSR);
-   if ( fd > 0 ) {
-      if ( 0 == VG_(fstat)(fd, &s1) ) {
+   if ( !fd.isError ) {
+      if ( 0 == VG_(fstat)(fd.val, &s1) ) {
          f_clo = malloc(s1.st_size+1);
          vg_assert(f_clo);
-         n = VG_(read)(fd, f_clo, s1.st_size);
+         n = VG_(read)(fd.val, f_clo, s1.st_size);
          if (n == -1) n = 0;
          f_clo[n] = '\0';
       }
-      VG_(close)(fd);
+      VG_(close)(fd.val);
    }
    return f_clo;
 #  undef FLEN
@@ -1160,7 +1161,9 @@ static void load_client(char* cl_argv[], const char* exec, Int need_help,
       VG_(memset)(info, 0, sizeof(*info));
    } else {
       Int ret;
-      VG_(clexecfd) = VG_(open)(exec, VKI_O_RDONLY, VKI_S_IRUSR);
+      /* HACK: assumes VG_(open) always succeeds */
+      VG_(clexecfd) = VG_(open)(exec, VKI_O_RDONLY, VKI_S_IRUSR)
+                      .val;
       ret = VG_(do_exec)(exec, info);
       if (ret != 0) {
          fprintf(stderr, "valgrind: do_exec(%s) failed: %s\n",
@@ -1407,8 +1410,9 @@ static void pre_process_cmd_line_options
 
 static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
 {
-   Int  i, eventually_log_fd;
-   Int  toolname_len = VG_(strlen)(toolname);
+   SysRes sres;
+   Int    i, eventually_log_fd;
+   Int    toolname_len = VG_(strlen)(toolname);
    enum {
       VgLogTo_Fd,
       VgLogTo_File,
@@ -1724,30 +1728,40 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
         }
 
         for (;;) {
-           if (seq == 0)
-              VG_(sprintf)( logfilename, "%s%s%s.pid%d",
-                             VG_(clo_log_name), 
-                             qual ? "." : "", qual ? qual : "",
-                             pid );
-           else
-              VG_(sprintf)( logfilename, "%s%s%s.pid%d.%d",
-                            VG_(clo_log_name), 
-                             qual ? "." : "", qual ? qual : "",
-                             pid, seq );
+            HChar pidtxt[20], seqtxt[20];
+
+            VG_(sprintf)(pidtxt, "%d", pid);
+
+            if (seq == 0)
+               seqtxt[0] = 0;
+            else
+               VG_(sprintf)(seqtxt, ".%d", seq);
+
            seq++;
 
+            /* Result:
+                  if (qual)      base_name ++ "." ++ qual ++ seqtxt
+                  if (not qual)  base_name ++ "." ++ pid  ++ seqtxt
+            */
+            VG_(sprintf)( logfilename, 
+                          "%s.%s%s",
+                          VG_(clo_log_name), 
+                          qual ? qual : pidtxt,
+                          seqtxt );
+
             // EXCL: it will fail with EEXIST if the file already exists.
-           eventually_log_fd 
+            sres
               = VG_(open)(logfilename, 
                           VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC, 
                           VKI_S_IRUSR|VKI_S_IWUSR);
-           if (eventually_log_fd >= 0) {
+           if (!sres.isError) {
+               eventually_log_fd = sres.val;
               VG_(clo_log_fd) = VG_(safe_fd)(eventually_log_fd);
               break; /* for (;;) */
            } else {
                // If the file already existed, we try the next name.  If it
                // was some other file error, we give up.
-              if (eventually_log_fd != -VKI_EEXIST) {
+              if (sres.val != VKI_EEXIST) {
                  VG_(message)(Vg_UserMsg, 
                               "Can't create/open log file '%s.pid%d'; giving up!", 
                               VG_(clo_log_name), pid);
@@ -1764,11 +1778,12 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
          vg_assert(VG_(clo_log_name) != NULL);
          vg_assert(VG_(strlen)(VG_(clo_log_name)) <= 900); /* paranoia */
 
-         eventually_log_fd 
+         sres
             = VG_(open)(VG_(clo_log_name),
                         VKI_O_CREAT|VKI_O_WRONLY|VKI_O_TRUNC, 
                         VKI_S_IRUSR|VKI_S_IWUSR);
-         if (eventually_log_fd >= 0) {
+         if (!sres.isError) {
+            eventually_log_fd = sres.val;
             VG_(clo_log_fd) = VG_(safe_fd)(eventually_log_fd);
          } else {
             VG_(message)(Vg_UserMsg, 
@@ -1937,7 +1952,7 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
    }
 
    if (VG_(clo_verbosity) > 1) {
-      Int fd;
+      SysRes fd;
       if (log_to != VgLogTo_Fd)
          VG_(message)(Vg_DebugMsg, "");
       VG_(message)(Vg_DebugMsg, "Valgrind library directory: %s", VG_(libdir));
@@ -1952,12 +1967,12 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
 
       VG_(message)(Vg_DebugMsg, "Contents of /proc/version:");
       fd = VG_(open) ( "/proc/version", VKI_O_RDONLY, 0 );
-      if (fd < 0) {
+      if (fd.isError) {
          VG_(message)(Vg_DebugMsg, "  can't open /proc/version");
       } else {
 #        define BUF_LEN    256
          Char version_buf[BUF_LEN];
-         Int n = VG_(read) ( fd, version_buf, BUF_LEN );
+         Int n = VG_(read) ( fd.val, version_buf, BUF_LEN );
          vg_assert(n <= BUF_LEN);
          if (n > 0) {
             version_buf[n-1] = '\0';
@@ -1965,7 +1980,7 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
          } else {
             VG_(message)(Vg_DebugMsg, "  (empty?)");
          }
-         VG_(close)(fd);
+         VG_(close)(fd.val);
 #        undef BUF_LEN
       }
    }
index a7fb692cf6f78fed521735183a1f73fc061eedf3..f594a197e5981aabdc5c436a0dd4057fd4ad8297 100644 (file)
@@ -547,32 +547,33 @@ void do_hacky_preopened()
 
 void VG_(init_preopened_fds)()
 {
-   int f, ret;
+   int ret;
    struct vki_dirent d;
+   SysRes f;
 
    f = VG_(open)("/proc/self/fd", VKI_O_RDONLY, 0);
-   if(f == -1) {
+   if (f.isError) {
       do_hacky_preopened();
       return;
    }
 
-   while((ret = VG_(getdents)(f, &d, sizeof(d))) != 0) {
+   while ((ret = VG_(getdents)(f.val, &d, sizeof(d))) != 0) {
       if (ret == -1)
          goto out;
 
       if (VG_(strcmp)(d.d_name, ".") && VG_(strcmp)(d.d_name, "..")) {
          int fno = VG_(atoll)(d.d_name);
 
-         if (fno != f)
+         if (fno != f.val)
             if (VG_(clo_track_fds))
                record_fd_open_named(-1, fno);
       }
 
-      VG_(lseek)(f, d.d_off, VKI_SEEK_SET);
+      VG_(lseek)(f.val, d.d_off, VKI_SEEK_SET);
    }
 
-out:
-   VG_(close)(f);
+  out:
+   VG_(close)(f.val);
 }
 
 static
index 2f80ec95e1cdb0d86f20f2993192b3ef32cd9bc4..aad9fa0dc3d0e5a417ad96c487bff96c1c8a5194 100644 (file)
    File-related functions.
    ------------------------------------------------------------------ */
 
-extern Int  VG_(open)   ( const Char* pathname, Int flags, Int mode );
-extern void VG_(close)  ( Int fd );
-extern Int  VG_(read)   ( Int fd, void* buf, Int count);
-extern Int  VG_(write)  ( Int fd, const void* buf, Int count);
-extern Int  VG_(pipe)   ( Int fd[2] );
-extern OffT VG_(lseek)  ( Int fd, OffT offset, Int whence);
-
-extern Int  VG_(stat)   ( Char* file_name, struct vki_stat* buf );
-extern Int  VG_(fstat)  ( Int   fd,        struct vki_stat* buf );
-extern Int  VG_(dup2)   ( Int oldfd, Int newfd );
-extern Int  VG_(rename) ( Char* old_name, Char* new_name );
-extern Int  VG_(unlink) ( Char* file_name );
+extern SysRes VG_(open)   ( const Char* pathname, Int flags, Int mode );
+extern void   VG_(close)  ( Int fd );
+extern Int    VG_(read)   ( Int fd, void* buf, Int count);
+extern Int    VG_(write)  ( Int fd, const void* buf, Int count);
+extern Int    VG_(pipe)   ( Int fd[2] );
+extern OffT   VG_(lseek)  ( Int fd, OffT offset, Int whence);
+
+extern Int    VG_(stat)   ( Char* file_name, struct vki_stat* buf );
+extern Int    VG_(fstat)  ( Int   fd,        struct vki_stat* buf );
+extern Int    VG_(dup2)   ( Int oldfd, Int newfd );
+extern Int    VG_(rename) ( Char* old_name, Char* new_name );
+extern Int    VG_(unlink) ( Char* file_name );
 
 // Returns False on failure (eg. if the buffer isn't big enough).
 extern Bool VG_(getcwd) ( Char* buf, SizeT size );
index f436d0f6251392cafd9fa3376eaf34700fb7a747..95d1566169395f77c3770d0cd39cac3436331510 100644 (file)
@@ -1345,12 +1345,13 @@ static void file_err ( Char* file )
  */
 static void write_hp_file(void)
 {
-   Int   i, j;
-   Int   fd, res;
-   Char *hp_file, *ps_file, *aux_file;
-   Char* cmdfmt;
-   Char* cmdbuf;
-   Int   cmdlen;
+   Int    i, j;
+   Int    fd, res;
+   SysRes sres;
+   Char  *hp_file, *ps_file, *aux_file;
+   Char*  cmdfmt;
+   Char*  cmdbuf;
+   Int    cmdlen;
 
    VGP_PUSHCC(VgpPrintHp);
    
@@ -1358,12 +1359,14 @@ static void write_hp_file(void)
    hp_file  = make_filename( base_dir, ".hp" );
    ps_file  = make_filename( base_dir, ".ps" );
    aux_file = make_filename( base_dir, ".aux" );
-   fd = VG_(open)(hp_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
-                           VKI_S_IRUSR|VKI_S_IWUSR);
-   if (fd < 0) {
+   sres = VG_(open)(hp_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
+                             VKI_S_IRUSR|VKI_S_IWUSR);
+   if (sres.isError) {
       file_err( hp_file );
       VGP_POPCC(VgpPrintHp);
       return;
+   } else {
+      fd = sres.val;
    }
 
    // File header, including command line
@@ -1658,9 +1661,10 @@ static void pp_all_XPts(Int fd, XPt* xpt, ULong heap_spacetime,
 static void
 write_text_file(ULong total_ST, ULong heap_ST)
 {
-   Int   fd, i;
-   Char* text_file;
-   Char* maybe_p = ( XHTML == clo_format ? "<p>" : "" );
+   SysRes sres;
+   Int    fd, i;
+   Char*  text_file;
+   Char*  maybe_p = ( XHTML == clo_format ? "<p>" : "" );
 
    VGP_PUSHCC(VgpPrintXPts);
 
@@ -1668,12 +1672,14 @@ write_text_file(ULong total_ST, ULong heap_ST)
    text_file = make_filename( base_dir, 
                               ( XText == clo_format ? ".txt" : ".html" ) );
 
-   fd = VG_(open)(text_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
+   sres = VG_(open)(text_file, VKI_O_CREAT|VKI_O_TRUNC|VKI_O_WRONLY,
                              VKI_S_IRUSR|VKI_S_IWUSR);
-   if (fd < 0) {
+   if (sres.isError) {
       file_err( text_file );
       VGP_POPCC(VgpPrintXPts);
       return;
+   } else {
+      fd = sres.val;
    }
 
    // Header