Skip to content

Commit

Permalink
linux-user: If loading fails, print error as string, not number
Browse files Browse the repository at this point in the history
If the attempt to load the guest executable fails, print the
error message as a string, not a number. This requires us to
fix a couple of places in loader_exec() where we were returning
-1 instead of a valid negative errno.

The change allows us to drop the "Unknown binary format" message
because the strerror-enhanced message is now a more self-explanatory
"Error while loading $guest-binary: Exec format error".

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
  • Loading branch information
pm215 authored and Riku Voipio committed Oct 12, 2012
1 parent a05c640 commit 885c1d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions linux-user/linuxload.c
Expand Up @@ -140,8 +140,9 @@ int loader_exec(const char * filename, char ** argv, char ** envp,
bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
memset(bprm->page, 0, sizeof(bprm->page));
retval = open(filename, O_RDONLY);
if (retval < 0)
return retval;
if (retval < 0) {
return -errno;
}
bprm->fd = retval;
bprm->filename = (char *)filename;
bprm->argc = count(argv);
Expand All @@ -165,8 +166,7 @@ int loader_exec(const char * filename, char ** argv, char ** envp,
retval = load_flt_binary(bprm,regs,infop);
#endif
} else {
fprintf(stderr, "Unknown binary format\n");
return -1;
return -ENOEXEC;
}
}

Expand Down
2 changes: 1 addition & 1 deletion linux-user/main.c
Expand Up @@ -3569,7 +3569,7 @@ int main(int argc, char **argv, char **envp)
ret = loader_exec(filename, target_argv, target_environ, regs,
info, &bprm);
if (ret != 0) {
printf("Error %d while loading %s\n", ret, filename);
printf("Error while loading %s: %s\n", filename, strerror(-ret));
_exit(1);
}

Expand Down

0 comments on commit 885c1d1

Please sign in to comment.