All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
@ 2026-04-25 14:48 Helge Deller
  2026-04-25 15:02 ` Warner Losh
  2026-04-26 13:01 ` Peter Maydell
  0 siblings, 2 replies; 10+ messages in thread
From: Helge Deller @ 2026-04-25 14:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: deller

From: Helge Deller <deller@gmx.de>

Qemu user mode does not properly flushes error messages related to bad
arguments when exiting (at least when the output is piped to a file
instead of running on a terminal).
Ensure that we always flush by using exit() instead of _exit().

Reported by: Tobias Bergkvist
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index c49d1e91d2..84e110dfe9 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -767,7 +767,7 @@ int main(int argc, char **argv, char **envp)
         execfd = open(exec_path, O_RDONLY);
         if (execfd < 0) {
             printf("Error while loading %s: %s\n", exec_path, strerror(errno));
-            _exit(EXIT_FAILURE);
+            exit(EXIT_FAILURE);
         }
     }
 
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-25 14:48 [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path Helge Deller
@ 2026-04-25 15:02 ` Warner Losh
  2026-04-25 15:17   ` Helge Deller
  2026-04-26 13:01 ` Peter Maydell
  1 sibling, 1 reply; 10+ messages in thread
From: Warner Losh @ 2026-04-25 15:02 UTC (permalink / raw)
  To: Helge Deller; +Cc: qemu-devel, deller, Laurent Vivier, Pierrick Bouvier

[-- Attachment #1: Type: text/plain, Size: 773 bytes --]

On Sat, Apr 25, 2026 at 8:50 AM Helge Deller <deller@kernel.org> wrote:

> From: Helge Deller <deller@gmx.de>
>
> Qemu user mode does not properly flushes error messages related to bad
> arguments when exiting (at least when the output is piped to a file
> instead of running on a terminal).
> Ensure that we always flush by using exit() instead of _exit().
>
> Reported by: Tobias Bergkvist
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
>  linux-user/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>

Note: I've added the linux-user maintainers to the CC list for visibility.
bsd-user has the same problem.

Warner

[-- Attachment #2: Type: text/html, Size: 1462 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-25 15:02 ` Warner Losh
@ 2026-04-25 15:17   ` Helge Deller
  2026-04-25 15:50     ` Warner Losh
  0 siblings, 1 reply; 10+ messages in thread
From: Helge Deller @ 2026-04-25 15:17 UTC (permalink / raw)
  To: Warner Losh, Helge Deller; +Cc: qemu-devel, Laurent Vivier, Pierrick Bouvier

On 4/25/26 17:02, Warner Losh wrote:
> 
> 
> On Sat, Apr 25, 2026 at 8:50 AM Helge Deller <deller@kernel.org <mailto:deller@kernel.org>> wrote:
> 
>     From: Helge Deller <deller@gmx.de <mailto:deller@gmx.de>>
> 
>     Qemu user mode does not properly flushes error messages related to bad
>     arguments when exiting (at least when the output is piped to a file
>     instead of running on a terminal).
>     Ensure that we always flush by using exit() instead of _exit().
> 
>     Reported by: Tobias Bergkvist
>     Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544 <https://gitlab.com/qemu-project/qemu/-/work_items/2544>
>     Signed-off-by: Helge Deller <deller@gmx.de <mailto:deller@gmx.de>>
>     ---
>       linux-user/main.c | 2 +-
>       1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 
> Reviewed-by: Warner Losh <imp@bsdimp.com <mailto:imp@bsdimp.com>>

Thanks!
  
> Note: I've added the linux-user maintainers to the CC list for visibility. 

Ok.

> bsd-user has the same problem.
I hesitate to change things I don't not test at all :-(
Even this patch here is not widely tested, but I think we need to add it.
If things break we see reports anyway.

Helge


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-25 15:17   ` Helge Deller
@ 2026-04-25 15:50     ` Warner Losh
  2026-04-26 13:06       ` Peter Maydell
  0 siblings, 1 reply; 10+ messages in thread
From: Warner Losh @ 2026-04-25 15:50 UTC (permalink / raw)
  To: Helge Deller; +Cc: Helge Deller, qemu-devel, Laurent Vivier, Pierrick Bouvier

[-- Attachment #1: Type: text/plain, Size: 2385 bytes --]

[[ Oops, my last message cc'd Pierrick's old address, maybe my tree is old
or it needs to update in MAINTAINERS ]]

On Sat, Apr 25, 2026 at 9:17 AM Helge Deller <deller@gmx.de> wrote:

> On 4/25/26 17:02, Warner Losh wrote:
> >
> >
> > On Sat, Apr 25, 2026 at 8:50 AM Helge Deller <deller@kernel.org <mailto:
> deller@kernel.org>> wrote:
> >
> >     From: Helge Deller <deller@gmx.de <mailto:deller@gmx.de>>
> >
> >     Qemu user mode does not properly flushes error messages related to
> bad
> >     arguments when exiting (at least when the output is piped to a file
> >     instead of running on a terminal).
> >     Ensure that we always flush by using exit() instead of _exit().
> >
> >     Reported by: Tobias Bergkvist
> >     Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544 <
> https://gitlab.com/qemu-project/qemu/-/work_items/2544>
> >     Signed-off-by: Helge Deller <deller@gmx.de <mailto:deller@gmx.de>>
> >     ---
> >       linux-user/main.c | 2 +-
> >       1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >
> > Reviewed-by: Warner Losh <imp@bsdimp.com <mailto:imp@bsdimp.com>>
>
> Thanks!
>
> > Note: I've added the linux-user maintainers to the CC list for
> visibility.
>
> Ok.
>
> > bsd-user has the same problem.
> I hesitate to change things I don't not test at all :-(
>

I can, since I do a lot with bsd-user.


> Even this patch here is not widely tested, but I think we need to add it.
> If things break we see reports anyway.
>

I don't think this will break anything. The printf can't possibly work,
either
we must change it to a write or do the exit. exit is done everywhere else.
This has been wrong since:

commit 03cfd8faa7ffb7201e2949b99c2f35b1fef7078b
Author: Laurent Vivier <laurent@vivier.eu>
Date:   Fri Aug 30 01:46:44 2013 +0200

    linux-user: add support of binfmt_misc 'O' flag
...
+    if (execfd < 0) {
+        printf("Error while loading %s: %s\n", filename,
strerror(-execfd));
+        _exit(1);
+    }
...
but the full commit log doesn't say why.  Laaurent was one of the people I
cc'd before
I chased this back to this commit. :).

I'll go ahead and make the bsd-user/main.c change (the error message is a
little different, and there's
a pull request against the bsd-user upstream I need to land in the area
around it, IIRC).

Warner

[-- Attachment #2: Type: text/html, Size: 4008 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-25 14:48 [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path Helge Deller
  2026-04-25 15:02 ` Warner Losh
@ 2026-04-26 13:01 ` Peter Maydell
  2026-04-26 14:37   ` Helge Deller
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2026-04-26 13:01 UTC (permalink / raw)
  To: Helge Deller; +Cc: qemu-devel, deller

On Sat, 25 Apr 2026 at 15:49, Helge Deller <deller@kernel.org> wrote:
>
> From: Helge Deller <deller@gmx.de>
>
> Qemu user mode does not properly flushes error messages related to bad
> arguments when exiting (at least when the output is piped to a file
> instead of running on a terminal).
> Ensure that we always flush by using exit() instead of _exit().
>
> Reported by: Tobias Bergkvist
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
>  linux-user/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/linux-user/main.c b/linux-user/main.c
> index c49d1e91d2..84e110dfe9 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -767,7 +767,7 @@ int main(int argc, char **argv, char **envp)
>          execfd = open(exec_path, O_RDONLY);
>          if (execfd < 0) {
>              printf("Error while loading %s: %s\n", exec_path, strerror(errno));
> -            _exit(EXIT_FAILURE);
> +            exit(EXIT_FAILURE);
>          }
>      }

How about the other _exit() further down in the function
for the case where loader_exec() fails ? That seems like
it would have the same problem.

-- PMM


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-25 15:50     ` Warner Losh
@ 2026-04-26 13:06       ` Peter Maydell
  2026-04-27  6:02         ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Maydell @ 2026-04-26 13:06 UTC (permalink / raw)
  To: Warner Losh
  Cc: Helge Deller, Helge Deller, qemu-devel, Laurent Vivier,
	Pierrick Bouvier

On Sat, 25 Apr 2026 at 16:51, Warner Losh <imp@bsdimp.com> wrote:
> I don't think this will break anything. The printf can't possibly work, either
> we must change it to a write or do the exit. exit is done everywhere else.
> This has been wrong since:
>
> commit 03cfd8faa7ffb7201e2949b99c2f35b1fef7078b
> Author: Laurent Vivier <laurent@vivier.eu>
> Date:   Fri Aug 30 01:46:44 2013 +0200
>
>     linux-user: add support of binfmt_misc 'O' flag
> ...
> +    if (execfd < 0) {
> +        printf("Error while loading %s: %s\n", filename, strerror(-execfd));
> +        _exit(1);
> +    }
> ...
> but the full commit log doesn't say why.

My guess is that the "print an error and exit" if() block was
simply copied from the bit further down that does:

    if (ret != 0) {
        printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
        _exit(EXIT_FAILURE);
    }

for the loader_exec failure case. That one dates back to
commit 74cd30b811cc2f in 2003, which changes some exit() calls
to _exit(). I have no idea why, and the commit message is cryptic
and useless. But it seems unlikely that the reason is still
relevant today.

-- PMM


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-26 13:01 ` Peter Maydell
@ 2026-04-26 14:37   ` Helge Deller
  0 siblings, 0 replies; 10+ messages in thread
From: Helge Deller @ 2026-04-26 14:37 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 4/26/26 15:01, Peter Maydell wrote:
> On Sat, 25 Apr 2026 at 15:49, Helge Deller <deller@kernel.org> wrote:
>>
>> From: Helge Deller <deller@gmx.de>
>>
>> Qemu user mode does not properly flushes error messages related to bad
>> arguments when exiting (at least when the output is piped to a file
>> instead of running on a terminal).
>> Ensure that we always flush by using exit() instead of _exit().
>>
>> Reported by: Tobias Bergkvist
>> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544
>> Signed-off-by: Helge Deller <deller@gmx.de>
>> ---
>>   linux-user/main.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/linux-user/main.c b/linux-user/main.c
>> index c49d1e91d2..84e110dfe9 100644
>> --- a/linux-user/main.c
>> +++ b/linux-user/main.c
>> @@ -767,7 +767,7 @@ int main(int argc, char **argv, char **envp)
>>           execfd = open(exec_path, O_RDONLY);
>>           if (execfd < 0) {
>>               printf("Error while loading %s: %s\n", exec_path, strerror(errno));
>> -            _exit(EXIT_FAILURE);
>> +            exit(EXIT_FAILURE);
>>           }
>>       }
> 
> How about the other _exit() further down in the function
> for the case where loader_exec() fails ? That seems like
> it would have the same problem.

I'll send a seperate patch for this one. Will then include in
next pull request series.

Thanks!
Helge


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
@ 2026-04-26 14:41 Helge Deller
  2026-04-26 21:56 ` Richard Henderson
  0 siblings, 1 reply; 10+ messages in thread
From: Helge Deller @ 2026-04-26 14:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: deller, Warner Losh

From: Helge Deller <deller@gmx.de>

Similiar to previous patch - ensure that we always flush I/O by using
exit() instead of _exit().

Reported by: Tobias Bergkvist
Reviewed-by: Warner Losh <imp@bsdimp.com>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 84e110dfe9..86d04cca3c 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -975,7 +975,7 @@ int main(int argc, char **argv, char **envp)
                       info, &bprm);
     if (ret != 0) {
         printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
-        _exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
     }
 
     for (wrk = target_environ; *wrk; wrk++) {
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-26 14:41 Helge Deller
@ 2026-04-26 21:56 ` Richard Henderson
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Henderson @ 2026-04-26 21:56 UTC (permalink / raw)
  To: qemu-devel

On 4/27/26 00:41, Helge Deller wrote:
> From: Helge Deller <deller@gmx.de>
> 
> Similiar to previous patch - ensure that we always flush I/O by using
> exit() instead of _exit().
> 
> Reported by: Tobias Bergkvist
> Reviewed-by: Warner Losh <imp@bsdimp.com>
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
>   linux-user/main.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 84e110dfe9..86d04cca3c 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -975,7 +975,7 @@ int main(int argc, char **argv, char **envp)
>                         info, &bprm);
>       if (ret != 0) {
>           printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
> -        _exit(EXIT_FAILURE);
> +        exit(EXIT_FAILURE);
>       }
>   
>       for (wrk = target_environ; *wrk; wrk++) {

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path
  2026-04-26 13:06       ` Peter Maydell
@ 2026-04-27  6:02         ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-04-27  6:02 UTC (permalink / raw)
  To: Peter Maydell, Warner Losh
  Cc: Helge Deller, Helge Deller, qemu-devel, Laurent Vivier,
	Pierrick Bouvier

On 26/4/26 15:06, Peter Maydell wrote:
> On Sat, 25 Apr 2026 at 16:51, Warner Losh <imp@bsdimp.com> wrote:
>> I don't think this will break anything. The printf can't possibly work, either
>> we must change it to a write or do the exit. exit is done everywhere else.
>> This has been wrong since:
>>
>> commit 03cfd8faa7ffb7201e2949b99c2f35b1fef7078b
>> Author: Laurent Vivier <laurent@vivier.eu>
>> Date:   Fri Aug 30 01:46:44 2013 +0200
>>
>>      linux-user: add support of binfmt_misc 'O' flag
>> ...
>> +    if (execfd < 0) {
>> +        printf("Error while loading %s: %s\n", filename, strerror(-execfd));
>> +        _exit(1);
>> +    }
>> ...
>> but the full commit log doesn't say why.
> 
> My guess is that the "print an error and exit" if() block was
> simply copied from the bit further down that does:
> 
>      if (ret != 0) {
>          printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
>          _exit(EXIT_FAILURE);
>      }
> 
> for the loader_exec failure case. That one dates back to
> commit 74cd30b811cc2f in 2003, which changes some exit() calls
> to _exit(). I have no idea why, and the commit message is cryptic
> and useless. But it seems unlikely that the reason is still
> relevant today.

Could it be do discard any atexit() callback?



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-04-27  6:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-25 14:48 [PATCH] linux-user: Flush errors by using exit() instead of _exit() in error path Helge Deller
2026-04-25 15:02 ` Warner Losh
2026-04-25 15:17   ` Helge Deller
2026-04-25 15:50     ` Warner Losh
2026-04-26 13:06       ` Peter Maydell
2026-04-27  6:02         ` Philippe Mathieu-Daudé
2026-04-26 13:01 ` Peter Maydell
2026-04-26 14:37   ` Helge Deller
  -- strict thread matches above, loose matches on Subject: below --
2026-04-26 14:41 Helge Deller
2026-04-26 21:56 ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.