]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Assorted cleanups: remove magic constants and unneeded header file. Update
authorFlorian Krohm <florian@eich-krohm.de>
Wed, 8 Apr 2015 19:01:15 +0000 (19:01 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Wed, 8 Apr 2015 19:01:15 +0000 (19:01 +0000)
a few comments. Exit with code 127 in bash emulation mode when file was
not found.

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

coregrind/m_ume/elf.c
coregrind/m_ume/macho.c
coregrind/m_ume/main.c
coregrind/m_ume/priv_ume.h
coregrind/m_ume/script.c

index e15839840f19281e3c4b49bb9d8d2bda6a8cb6dd..0e4c1cd9e70d33fd73143ad47f225c39f1e12242 100644 (file)
@@ -244,7 +244,7 @@ ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base)
    return elfbrk;
 }
 
-Bool VG_(match_ELF)(const void *hdr, Int len)
+Bool VG_(match_ELF)(const void *hdr, SizeT len)
 {
    const ESZ(Ehdr) *e = hdr;
    return (len > sizeof(*e)) && VG_(memcmp)(&e->e_ident[0], ELFMAG, SELFMAG) == 0;
index 8d9789ae7ded7602344120bde16c23c46d912f52..5c551419021d1db7dfcda7dc928bbe114947ab98 100644 (file)
@@ -813,7 +813,7 @@ load_mach_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype,
 }
 
 
-Bool VG_(match_macho)(const void *hdr, Int len)
+Bool VG_(match_macho)(const void *hdr, SizeT len)
 {
    const vki_uint32_t *magic = hdr;
 
index 40556afe2eaf0795800fd969548105075bc4917e..11c6cc675128cfebe68e506e9f233846593e1a57 100644 (file)
@@ -46,7 +46,7 @@
 
 
 typedef struct {
-   Bool (*match_fn)(const void *hdr, Int len);
+   Bool (*match_fn)(const void *hdr, SizeT len);
    Int  (*load_fn)(Int fd, const HChar *name, ExeInfo *info);
 } ExeHandler;
 
@@ -70,7 +70,7 @@ VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd, Bool allow_setuid)
    Int fd, ret, i;
    SysRes res;
    Char  buf[4096];
-   SizeT bufsz = 4096, fsz;
+   SizeT bufsz = sizeof buf, fsz;
    Bool is_setuid = False;
 
    // Check it's readable
@@ -132,8 +132,8 @@ VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd, Bool allow_setuid)
 // returns: 0 = success, non-0 is failure
 //
 // We can execute only binaries (ELF, etc) or scripts that begin with "#!".
-// (Not, for example, scripts that don't begin with "#!";  see the
-// VG_(do_exec)() invocation from m_main.c for how that's handled.)
+// (Not, for example, scripts that don't begin with "#!";  see 
+// do_exec_shell_followup for how that's handled.)
 Int VG_(do_exec_inner)(const HChar* exe, ExeInfo* info)
 {
    SysRes res;
@@ -241,10 +241,17 @@ static Int do_exec_shell_followup(Int ret, const HChar* exe_name, ExeInfo* info)
    } else if (0 != ret) {
       // Something else went wrong.  Try to make the error more specific,
       // and then print a message and abort.
-   
-      // Was it a directory?
+      Int exit_code = 126;    // 126 == NOEXEC (bash)
+
       res = VG_(stat)(exe_name, &st);
-      if (!sr_isError(res) && VKI_S_ISDIR(st.mode)) {
+
+      // Does the file exist ?
+      if (sr_isError(res) && sr_Err(res) == VKI_ENOENT) {
+         VG_(fmsg)("%s: %s\n", exe_name, VG_(strerror)(ret));
+         exit_code = 127;     // 127 == NOTFOUND (bash)
+
+      // Was it a directory?
+      } else if (!sr_isError(res) && VKI_S_ISDIR(st.mode)) {
          VG_(fmsg)("%s: is a directory\n", exe_name);
       
       // Was it not executable?
@@ -260,9 +267,7 @@ static Int do_exec_shell_followup(Int ret, const HChar* exe_name, ExeInfo* info)
       } else {
          VG_(fmsg)("%s: %s\n", exe_name, VG_(strerror)(ret));
       }
-      // 126 means NOEXEC;  I think this is Posix, and that in some cases we
-      // should be returning 127, meaning NOTFOUND.  Oh well.
-      VG_(exit)(126);
+      VG_(exit)(exit_code);
    }
    return ret;
 }
@@ -270,8 +275,8 @@ static Int do_exec_shell_followup(Int ret, const HChar* exe_name, ExeInfo* info)
 
 // This emulates the kernel's exec().  If it fails, it then emulates the
 // shell's handling of the situation.
-// See ume.h for an indication of which entries of 'info' are inputs, which
-// are outputs, and which are both.
+// See pub_core_ume.h for an indication of which entries of 'info' are
+// inputs, which are outputs, and which are both.
 /* returns: 0 = success, non-0 is failure */
 Int VG_(do_exec)(const HChar* exe_name, ExeInfo* info)
 {
index b22df80b9d7a9c65354aae8acb564ad84c4f04cb..4f7819051f9c8c90e8ef76d95b0f3b4a6f3f8b50 100644 (file)
 
 #include "pub_core_ume.h"   // ExeInfo
 
-extern int VG_(do_exec_inner)(const HChar *exe, ExeInfo *info);
+extern Int VG_(do_exec_inner)(const HChar *exe, ExeInfo *info);
 
 #if defined(VGO_linux)
-extern Bool VG_(match_ELF) ( const void *hdr, Int len );
+extern Bool VG_(match_ELF) ( const void *hdr, SizeT len );
 extern Int  VG_(load_ELF)  ( Int fd, const HChar *name, ExeInfo *info );
 #elif defined(VGO_darwin)
-extern Bool VG_(match_macho) ( const void *hdr, Int len );
+extern Bool VG_(match_macho) ( const void *hdr, SizeT len );
 extern Int  VG_(load_macho)  ( Int fd, const HChar *name, ExeInfo *info );
 #else
 #  error Unknown OS
 #endif
 
-extern Bool VG_(match_script) ( const void *hdr, Int len );
+extern Bool VG_(match_script) ( const void *hdr, SizeT len );
 extern Int  VG_(load_script)  ( Int fd, const HChar *name, ExeInfo *info );
 
 
index 182a23c65a7f0829f085b94cd9bafac6e1b95e93..5c03428da282682ba540d05df246538784770b41 100644 (file)
 #include "pub_core_libcassert.h"    // VG_(exit), vg_assert
 #include "pub_core_libcfile.h"      // VG_(close) et al
 #include "pub_core_libcprint.h"
-#include "pub_core_xarray.h"
-#include "pub_core_clientstate.h"
+#include "pub_core_clientstate.h"   // VG_(args_the_exename)
 #include "pub_core_mallocfree.h"    // VG_(strdup)
 #include "pub_core_ume.h"           // self
 
 #include "priv_ume.h"
 
-Bool VG_(match_script)(const void *hdr, Int len)
+Bool VG_(match_script)(const void *hdr, SizeT len)
 {
    const HChar* script = hdr;
    const HChar* end    = script + len;
@@ -80,7 +79,7 @@ Bool VG_(match_script)(const void *hdr, Int len)
 Int VG_(load_script)(Int fd, const HChar* name, ExeInfo* info)
 {
    HChar  hdr[4096];
-   Int    len = 4096;
+   Int    len = sizeof hdr;
    Int    eol;
    HChar* interp;
    HChar* end;
@@ -101,7 +100,7 @@ Int VG_(load_script)(Int fd, const HChar* name, ExeInfo* info)
 
    end    = hdr + len;
    interp = hdr + 2;
-   while (interp < end && VG_(isspace)(*interp))
+   while (interp < end && (*interp == ' ' || *interp == '\t'))
       interp++;
 
    vg_assert(*interp == '/');   /* absolute path only for interpreter */