linux-user: Flush errors by using exit() instead of _exit() in error path
PATCH 1/1 linux-user: Flush errors by using exit() instead of _exit() in error path
From: Helge Deller <[email protected]>
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
--- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/main.c +1 -1
@@ -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 ); } }
Signature · 1 line
2.53.0
Quoted 7 lines · Helge Deller
From: Helge Deller <[email protected]>
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 usingexit()instead of_exit().
Quoted 7 lines
Reported by: Tobias Bergkvist
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544Signed-off-by Helge Deller <[email protected]>--- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Note: I've added the linux-user maintainers to the CC list for visibility. bsd-user has the same problem.
Warner
Quoted 13 lines · Warner Losh
On Sat, Apr 25, 2026 at 8:50 AM Helge Deller <[email protected] <mailto:[email protected]>> wrote:
From: Helge Deller <[email protected] <mailto:[email protected]>>
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 usingexit()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>
Quoted 7 lines
Signed-off-by Helge Deller <[email protected] <mailto:[email protected]>>---
linux-user/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Warner Losh <[email protected] <mailto:[email protected]>>
Thanks!
Quoted 1 line
Note: I've added the linux-user maintainers to the CC list for visibility.
Ok.
Quoted 1 line
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
[[ Oops, my last message cc'd Pierrick's old address, maybe my tree is old or it needs to update in MAINTAINERS ]]
Quoted 27 lines · Helge Deller
Quoted 3 lines · Warner Losh
On Sat, Apr 25, 2026 at 8:50 AM Helge Deller <[email protected] <mailto:
Quoted 4 lines · [email protected]>> wrote:
From: Helge Deller <[email protected] <mailto:[email protected]>>
Qemu user mode does not properly flushes error messages related to
bad
Quoted 6 lines
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 usingexit()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>
Quoted 7 lines
Signed-off-by Helge Deller <[email protected] <mailto:[email protected]>>---
linux-user/main.c| 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Warner Losh <[email protected] <mailto:[email protected]>>Thanks!
Quoted 8 lines
Quoted 1 line
Note: I've added the linux-user maintainers to the CC list for
visibility.
Ok.
Quoted 1 line
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.
Quoted 3 lines
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 <[email protected]> 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
Quoted 20 lines · Helge Deller
From: Helge Deller <[email protected]>
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 usingexit()instead of_exit().Reported by: Tobias Bergkvist
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544Signed-off-by Helge Deller <[email protected]>--- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/main.c +0
-0
linux-user/main.c int main(int argc, char **argv, char **envp) · line 772
Quoted 7 lines
linux-user/main.c +1
-1@@ -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
Quoted 15 lines · Warner Losh
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
03cfd8faa7ffb7201e2949b99c2f35b1fef7078bAuthor: Laurent Vivier <[email protected]> Date: Fri Aug 30 01:46:44 2013 +0200linux-user: add support of
binfmt_misc'O' flag
...(quoted diff) +4
-0+ if (execfd < 0) { + printf("Error while loading %s: %s\n", filename, strerror(-execfd)); + _exit(1); + }
Quoted 1 line
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
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Helge Deller
From: Helge Deller <[email protected]>
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 usingexit()instead of_exit().Reported by: Tobias Bergkvist
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2544Signed-off-by Helge Deller <[email protected]>--- linux-user/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
linux-user/main.c int main(int argc, char **argv, char **envp) · line 772
Quoted 12 lines
linux-user/main.c +1
-1@@ -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 whereloader_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
Quoted 26 lines · Peter Maydell
Quoted 15 lines · Warner Losh
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
03cfd8faa7ffb7201e2949b99c2f35b1fef7078bAuthor: Laurent Vivier <[email protected]> Date: Fri Aug 30 01:46:44 2013 +0200linux-user: add support of
binfmt_misc'O' flag
...(quoted diff) +4
-0+ if (execfd < 0) { + printf("Error while loading %s: %s\n", filename, strerror(-execfd)); + _exit(1); + }Quoted 1 line
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); }
Quoted 5 lines
for the
loader_execfailure case. That one dates back to commit74cd30b811cc2fin 2003, which changes someexit()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?