Skip to contentSkip to conversation

Sanitize linux-user stdout

PATCH In review Philippe Mathieu-Daudé 4 participants 10 messages Jul 6, 2018 – Jul 8, 2018

lore
Share & tools
lore
#0 lore raw

cover Sanitize linux-user stdout

Hi Laurent,

Here 3 trivial patches, the first one resolves this launchpad issue:
https://bugs.launchpad.net/qemu/+bug/1777226, then the following two sanitize a bit further.

Regards,

Phil.

Philippe Mathieu-Daudé (3):
linux-user: Do not report "Unsupported syscall" by default
linux-user: Do not report "syscall not implemented" by default
linux-user: Report error message on stderr, rather than stdout

 linux-user/alpha/cpu_loop.c      | 2 +-
 linux-user/cris/cpu_loop.c       | 2 +-
 linux-user/cris/signal.c         | 4 ++--
 linux-user/microblaze/cpu_loop.c | 6 +++---
 linux-user/microblaze/signal.c   | 4 ++--
 linux-user/nios2/signal.c        | 2 +-
 linux-user/sh4/cpu_loop.c        | 2 +-
 linux-user/sparc/cpu_loop.c      | 2 +-
 linux-user/sparc/signal.c        | 4 ++--
 linux-user/syscall.c             | 2 +-
 10 files changed, 15 insertions(+), 15 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/3 linux-user: Do not report "Unsupported syscall" by default

This can still be reported using the "-d unimp" command line option.

---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
index 5822e03e28..e4b1b7d7da 100644
@@ -12757,7 +12757,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
     default:
     unimplemented:
-        gemu_log("qemu: Unsupported syscall: %d\n", num);
+        qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
     unimplemented_nowarn:
 #endif
Signature · 1 line
2.18.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH for-3.0 1/3] linux-user: Do not report "Unsupported syscall" by default

Quoted 24 lines · Philippe Mathieu-Daudé

This can still be reported using the "-d unimp" command line option.

---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -2
index 5822e03e28..e4b1b7d7da 100644
@@ -12757,7 +12757,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
     default:
     unimplemented:
-        gemu_log("qemu: Unsupported syscall: %d\n", num);
+        qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
 #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list)
     unimplemented_nowarn:
 #endif
--
Quoted 1 line

2.18.0

thanks
-- PMM

#3 lore raw

PATCH 2/3 linux-user: Do not report "syscall not implemented" by default

In reply to Philippe Mathieu-Daudé

This can still be reported using the "-d unimp" command line option.

Code change produced with:

  git ls-files linux-user | \
  xargs sed -i -E 's/fprintf\(stderr,\s?(".*not implemented\\n")\);/qemu_log_mask(LOG_UNIMP, \1);/g'
---
 linux-user/cris/signal.c       | 4 ++--
 linux-user/microblaze/signal.c | 4 ++--
 linux-user/nios2/signal.c      | 2 +-
 linux-user/sparc/signal.c      | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)
linux-user/cris/signal.c +2 -2
index 0b405247cf..1e02194377 100644
@@ -146,7 +146,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                      target_sigset_t *set, CPUCRISState *env)
 {
-    fprintf(stderr, "CRIS setup_rt_frame: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "setup_rt_frame: not implemented\n");
 }
 
 long do_sigreturn(CPUCRISState *env)
@@ -183,6 +183,6 @@ badframe:
 long do_rt_sigreturn(CPUCRISState *env)
 {
     trace_user_do_rt_sigreturn(env, 0);
-    fprintf(stderr, "CRIS do_rt_sigreturn: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "do_rt_sigreturn: not implemented\n");
     return -TARGET_ENOSYS;
 }
linux-user/microblaze/signal.c +2 -2
index 712ee522b2..80950c2181 100644
@@ -200,7 +200,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                     target_sigset_t *set, CPUMBState *env)
 {
-    fprintf(stderr, "Microblaze setup_rt_frame: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "setup_rt_frame: not implemented\n");
 }
 
 long do_sigreturn(CPUMBState *env)
@@ -240,6 +240,6 @@ badframe:
 long do_rt_sigreturn(CPUMBState *env)
 {
     trace_user_do_rt_sigreturn(env, 0);
-    fprintf(stderr, "Microblaze do_rt_sigreturn: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "do_rt_sigreturn: not implemented\n");
     return -TARGET_ENOSYS;
 }
linux-user/nios2/signal.c +1 -1
index 4985dc2212..7d535065ed 100644
@@ -203,7 +203,7 @@ give_sigsegv:
 long do_sigreturn(CPUNios2State *env)
 {
     trace_user_do_sigreturn(env, 0);
-    fprintf(stderr, "do_sigreturn: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "do_sigreturn: not implemented\n");
     return -TARGET_ENOSYS;
 }
 
linux-user/sparc/signal.c +2 -2
index 55e9d6f9b2..b4c60aa446 100644
@@ -278,7 +278,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                     target_sigset_t *set, CPUSPARCState *env)
 {
-    fprintf(stderr, "setup_rt_frame: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "setup_rt_frame: not implemented\n");
 }
 
 long do_sigreturn(CPUSPARCState *env)
@@ -357,7 +357,7 @@ segv_and_exit:
 long do_rt_sigreturn(CPUSPARCState *env)
 {
     trace_user_do_rt_sigreturn(env, 0);
-    fprintf(stderr, "do_rt_sigreturn: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "do_rt_sigreturn: not implemented\n");
     return -TARGET_ENOSYS;
 }
 
Signature · 1 line
2.18.0
#4 lore raw

Re: [Qemu-devel] [PATCH for-3.0 2/3] linux-user: Do not report "syscall not implemented" by default

Quoted 20 lines · Philippe Mathieu-Daudé

This can still be reported using the "-d unimp" command line option.

Code change produced with:

  git ls-files linux-user | \
  xargs sed -i -E 's/fprintf\(stderr,\s?(".*not implemented\\n")\);/qemu_log_mask(LOG_UNIMP, \1);/g'
---
 linux-user/cris/signal.c       | 4 ++--
 linux-user/microblaze/signal.c | 4 ++--
 linux-user/nios2/signal.c      | 2 +-
 linux-user/sparc/signal.c      | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)
linux-user/cris/signal.c +0 -0
index 0b405247cf..1e02194377 100644

linux-user/cris/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 149

Quoted 5 lines
linux-user/cris/signal.c +1 -1
@@ -146,7 +146,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                      target_sigset_t *set, CPUCRISState *env)
 {
-    fprintf(stderr, "CRIS setup_rt_frame: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "setup_rt_frame: not implemented\n");

Your regex seems to have gone a bit awry here, because it's lost the "CRIS" part of the string (similarly below).

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH for-3.0 2/3] linux-user: Do not report "syscall not implemented" by default

Quoted 16 lines · Peter Maydell
Quoted 15 lines · Philippe Mathieu-Daudé

This can still be reported using the "-d unimp" command line option.

Code change produced with:

  git ls-files linux-user | \
  xargs sed -i -E 's/fprintf\(stderr,\s?(".*not implemented\\n")\);/qemu_log_mask(LOG_UNIMP, \1);/g'
---
 linux-user/cris/signal.c       | 4 ++--
 linux-user/microblaze/signal.c | 4 ++--
 linux-user/nios2/signal.c      | 2 +-
 linux-user/sparc/signal.c      | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)
Quoted 13 lines

linux-user/cris/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 149

Quoted 10 lines
linux-user/cris/signal.c +1 -1
index 0b405247cf..1e02194377 100644
@@ -146,7 +146,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                      target_sigset_t *set, CPUCRISState *env)
 {
-    fprintf(stderr, "CRIS setup_rt_frame: not implemented\n");
+    qemu_log_mask(LOG_UNIMP, "setup_rt_frame: not implemented\n");

Your regex seems to have gone a bit awry here, because it's lost the "CRIS" part of the string (similarly below).

Oh I deliberately dropped it when using 'git add -p' after the regex because I noticed neither nios2 nor sparc arch were using it, and I don't think this is a relevant information.

Do you prefer I restore them, I reword the commit message, or even add similar description for the nios2/sparc?

Thanks,

Phil.

#6 lore raw

PATCH 3/3 linux-user: Report error message on stderr, rather than stdout

In reply to Philippe Mathieu-Daudé

Code change produced with:

  git ls-files linux-user | \
  xargs sed -i -E 's/(\s+)printf\s*\(("Unhandled.*)\);/\1fprintf(stderr, \2);/g'
---
 linux-user/alpha/cpu_loop.c      | 2 +-
 linux-user/cris/cpu_loop.c       | 2 +-
 linux-user/microblaze/cpu_loop.c | 6 +++---
 linux-user/sh4/cpu_loop.c        | 2 +-
 linux-user/sparc/cpu_loop.c      | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
linux-user/alpha/cpu_loop.c +1 -1
index b87fcaea87..c1a98c8cbf 100644
@@ -196,7 +196,7 @@ void cpu_loop(CPUAlphaState *env)
             arch_interrupt = false;
             break;
         default:
-            printf ("Unhandled trap: 0x%x\n", trapnr);
+            fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, fprintf, 0);
             exit(EXIT_FAILURE);
         }
linux-user/cris/cpu_loop.c +1 -1
index 1c5eca9f83..37bdcfa8cc 100644
@@ -81,7 +81,7 @@ void cpu_loop(CPUCRISState *env)
             cpu_exec_step_atomic(cs);
             break;
         default:
-            printf ("Unhandled trap: 0x%x\n", trapnr);
+            fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, fprintf, 0);
             exit(EXIT_FAILURE);
         }
linux-user/microblaze/cpu_loop.c +3 -3
index 5af12d5b21..2af93eb39a 100644
@@ -105,8 +105,8 @@ void cpu_loop(CPUMBState *env)
                     queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
                     break;
                 default:
-                    printf("Unhandled hw-exception: 0x%" PRIx64 "\n",
-                           env->sregs[SR_ESR] & ESR_EC_MASK);
+                    fprintf(stderr, "Unhandled hw-exception: 0x%" PRIx64 "\n",
+                            env->sregs[SR_ESR] & ESR_EC_MASK);
                     cpu_dump_state(cs, stderr, fprintf, 0);
                     exit(EXIT_FAILURE);
                     break;
@@ -130,7 +130,7 @@ void cpu_loop(CPUMBState *env)
             cpu_exec_step_atomic(cs);
             break;
         default:
-            printf ("Unhandled trap: 0x%x\n", trapnr);
+            fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, fprintf, 0);
             exit(EXIT_FAILURE);
         }
linux-user/sh4/cpu_loop.c +1 -1
index 418833ea25..fdd348170b 100644
@@ -84,7 +84,7 @@ void cpu_loop(CPUSH4State *env)
             arch_interrupt = false;
             break;
         default:
-            printf ("Unhandled trap: 0x%x\n", trapnr);
+            fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, fprintf, 0);
             exit(EXIT_FAILURE);
         }
linux-user/sparc/cpu_loop.c +1 -1
index 7c4796ca23..91f714afc6 100644
@@ -285,7 +285,7 @@ void cpu_loop (CPUSPARCState *env)
             cpu_exec_step_atomic(cs);
             break;
         default:
-            printf ("Unhandled trap: 0x%x\n", trapnr);
+            fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(cs, stderr, fprintf, 0);
             exit(EXIT_FAILURE);
         }
Signature · 1 line
2.18.0
Reviewed-by on v1 3/3
#7 lore raw

Re: [Qemu-devel] [PATCH for-3.0 3/3] linux-user: Report error message on stderr, rather than stdout

Quoted 5 lines · Philippe Mathieu-Daudé

Code change produced with:

  git ls-files linux-user | \
  xargs sed -i -E 's/(\s+)printf\s*\(("Unhandled.*)\);/\1fprintf(stderr, \2);/g'
Quoted 8 lines
---
 linux-user/alpha/cpu_loop.c      | 2 +-
 linux-user/cris/cpu_loop.c       | 2 +-
 linux-user/microblaze/cpu_loop.c | 6 +++---
 linux-user/sh4/cpu_loop.c        | 2 +-
 linux-user/sparc/cpu_loop.c      | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

Makes sense, as we're about to print the cpu_dump_state output to stderr too.

thanks
-- PMM

#9 lore raw
In reply to Philippe Mathieu-Daudé

Le 06/07/2018 à 17:51, Philippe Mathieu-Daudé a écrit :

Quoted 15 lines

Hi Laurent,

Here 3 trivial patches, the first one resolves this launchpad issue:
https://bugs.launchpad.net/qemu/+bug/1777226, then the following two sanitize a bit further.

Regards,

Phil.

Philippe Mathieu-Daudé (3):
linux-user: Do not report "Unsupported syscall" by default
linux-user: Do not report "syscall not implemented" by default
linux-user: Report error message on stderr, rather than stdout

Quoted 12 lines
 linux-user/alpha/cpu_loop.c      | 2 +-
 linux-user/cris/cpu_loop.c       | 2 +-
 linux-user/cris/signal.c         | 4 ++--
 linux-user/microblaze/cpu_loop.c | 6 +++---
 linux-user/microblaze/signal.c   | 4 ++--
 linux-user/nios2/signal.c        | 2 +-
 linux-user/sh4/cpu_loop.c        | 2 +-
 linux-user/sparc/cpu_loop.c      | 2 +-
 linux-user/sparc/signal.c        | 4 ++--
 linux-user/syscall.c             | 2 +-
 10 files changed, 15 insertions(+), 15 deletions(-)

I have queued the series for the next pull request.

I think you can also replace the gemu_log("Unknown QEMU_IFLA..."), qemu_log("Unknown host ..") and qemu_log("Unknown target ...") from the netlink part in syscall.c with qemu_log_mask(LOG_UNIMP, ...).

Thanks,
Laurent