From: Florian Krohm Date: Wed, 8 Apr 2015 19:01:15 +0000 (+0000) Subject: Assorted cleanups: remove magic constants and unneeded header file. Update X-Git-Tag: svn/VALGRIND_3_11_0~516 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fa7e44d039500178a20a362e2c5951345f97cb20;p=thirdparty%2Fvalgrind.git Assorted cleanups: remove magic constants and unneeded header file. Update 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 --- diff --git a/coregrind/m_ume/elf.c b/coregrind/m_ume/elf.c index e15839840f..0e4c1cd9e7 100644 --- a/coregrind/m_ume/elf.c +++ b/coregrind/m_ume/elf.c @@ -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; diff --git a/coregrind/m_ume/macho.c b/coregrind/m_ume/macho.c index 8d9789ae7d..5c55141902 100644 --- a/coregrind/m_ume/macho.c +++ b/coregrind/m_ume/macho.c @@ -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; diff --git a/coregrind/m_ume/main.c b/coregrind/m_ume/main.c index 40556afe2e..11c6cc6751 100644 --- a/coregrind/m_ume/main.c +++ b/coregrind/m_ume/main.c @@ -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) { diff --git a/coregrind/m_ume/priv_ume.h b/coregrind/m_ume/priv_ume.h index b22df80b9d..4f7819051f 100644 --- a/coregrind/m_ume/priv_ume.h +++ b/coregrind/m_ume/priv_ume.h @@ -34,19 +34,19 @@ #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 ); diff --git a/coregrind/m_ume/script.c b/coregrind/m_ume/script.c index 182a23c65a..5c03428da2 100644 --- a/coregrind/m_ume/script.c +++ b/coregrind/m_ume/script.c @@ -35,14 +35,13 @@ #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 */