From patchwork Fri Aug 24 16:55:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 10949 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A64E223E1B for ; Fri, 24 Aug 2012 16:56:08 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 719F3A1898A for ; Fri, 24 Aug 2012 16:55:50 +0000 (UTC) Received: by iafj25 with SMTP id j25so1458789iaf.11 for ; Fri, 24 Aug 2012 09:56:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=kLVz6cmWnRL0Qnzj9XtS/Sp/joQu6c9B3xlyfrgw9Sw=; b=RdwjztGNe/ixf1DvQgIfDCotTPNW+8/N3+4WCYoOivJNbFt/GL1aoB//wV6gSpIiBI pZQf9pco3QnzlGdlqs7ngVFwZJyU8/ycFflVjmoNQCCbewk7oVYbvqiapzWUQasIzMVT q2WmUW34ejFVHACZrAVgnvpW7ecysrwyTYTyr9fGCHH5qgYYO2FURdV95mH419Or1tsm 0TJ/9ttH/I7GeGQP4wkwsXBBQWBoAt4hg0Ep179kHEjRToNSCgptuFhG0E9523vHuraj t8KniRGC0DwztM/3Sewk6DtefSDqRn9zBSQLGKI7AfJPo+16wtmjU8TiNsJWtXBrgqBA ANMA== Received: by 10.50.45.162 with SMTP id o2mr2988873igm.0.1345827367702; Fri, 24 Aug 2012 09:56:07 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp330152igc; Fri, 24 Aug 2012 09:56:06 -0700 (PDT) Received: by 10.14.203.69 with SMTP id e45mr8330474eeo.23.1345827365916; Fri, 24 Aug 2012 09:56:05 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id w6si7602385eel.60.2012.08.24.09.56.04 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Aug 2012 09:56:05 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1T4xAn-0004SR-LH; Fri, 24 Aug 2012 17:55:53 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: Riku Voipio , patches@linaro.org, Christophe Lyon Subject: [PATCH] linux-user: If loading fails, print error as string, not number Date: Fri, 24 Aug 2012 17:55:53 +0100 Message-Id: <1345827353-17112-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQnYv7lu2i6M0s94ZFxMxjnlfjN7lE6G07lJAR4ywFBu2bi6FQVAklxCUaFgcBWW25sCr7DO 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 --- My motivation here was that "user downloads guest binary from somewhere and it ends up without exec permissions" is quite a common mistake, and "Error -13 while loading my-program" is not a very helpful way to report this... linux-user/linuxload.c | 8 ++++---- linux-user/main.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index b47025f..381ab89 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -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); @@ -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; } } diff --git a/linux-user/main.c b/linux-user/main.c index 7dea084..ae0de9a 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3581,7 +3581,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); }