Patchwork [10/19] linux-user/strace.c: Correct errno printing for mmap etc

login
register
mail settings
Submitter riku.voipio@linaro.org
Date Jan. 31, 2012, 9:29 a.m.
Message ID <b02148eadd8ed3bb5afae24348b7bc8f3b2ade10.1328001769.git.riku.voipio@linaro.org>
Download mbox | patch
Permalink /patch/138738/
State New
Headers show

Comments

riku.voipio@linaro.org - Jan. 31, 2012, 9:29 a.m.
From: Peter Maydell <peter.maydell@linaro.org>

Correct the printing of errnos for syscalls which are handled
via print_syscall_ret_addr (mmap, mmap2, brk, shmat): errnos
are returned as negative returned values at this level, not
via the host 'errno' variable.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/strace.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

Patch

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 269481e..05a0d3e 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1,5 +1,4 @@ 
 #include <stdio.h>
-#include <errno.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
 #include <sys/sem.h>
@@ -286,11 +285,11 @@  print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 {
     char *errstr = NULL;
 
-    if (ret == -1) {
-        errstr = target_strerror(errno);
+    if (ret < 0) {
+        errstr = target_strerror(-ret);
     }
-    if ((ret == -1) && errstr) {
-        gemu_log(" = -1 errno=%d (%s)\n", errno, errstr);
+    if (errstr) {
+        gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
     } else {
         gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
     }