flush stdout after printing usage()
PATCH 1/1 flush stdout after printing usage()
testcase:
qemu-arm|grep cpu
Without fflush() getting output from piped qemu is a bit random.
--- bsd-user/main.c | 1 + darwin-user/main.c | 1 + linux-user/main.c | 1 + 3 files changed, 3 insertions(+), 0 deletions(-)
bsd-user/main.c +1 -0
@@ -351,6 +351,7 @@ static void usage(void) interp_prefix, x86_stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }
darwin-user/main.c +1 -0
@@ -758,6 +758,7 @@ void usage(void) interp_prefix, stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }
linux-user/main.c +1 -0
@@ -2216,6 +2216,7 @@ static void usage(void) interp_prefix, x86_stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }
Signature · 5 lines
1.5.6.5 -- "rm -rf" only sounds scary if you don't have backups
Quoted 6 lines · Riku Voipio
testcase:
qemu-arm|grep cpu
Without
fflush()getting output from piped qemu is a bit random.
It should get flushed upon exit(). Perhaps the problem is that we're using _exit() instead of exit()?
Regards,
Anthony Liguori
Quoted 44 lines
Signed-off-by Riku Voipio <[email protected]>--- bsd-user/main.c | 1 + darwin-user/main.c | 1 + linux-user/main.c | 1 + 3 files changed, 3 insertions(+), 0 deletions(-)bsd-user/main.c +1
-0@@ -351,6 +351,7 @@ static void usage(void) interp_prefix, x86_stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }darwin-user/main.c +1
-0@@ -758,6 +758,7 @@ void usage(void) interp_prefix, stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }linux-user/main.c +1
-0@@ -2216,6 +2216,7 @@ static void usage(void) interp_prefix, x86_stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }
Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Riku Voipio
testcase:
qemu-arm|grep cpu
Without
fflush()getting output from piped qemu is a bit random.It should get flushed upon
exit(). Perhaps the problem is that we're using_exit()instead ofexit()?
Well yes in my testing, replacing _exit() with exit() fixes it too. I just presumed _exit() was there for a purpose.
Quoted 50 lines
Regards,
Anthony Liguori
Quoted 44 lines
Signed-off-by Riku Voipio <[email protected]>---
bsd-user/main.c | 1 + darwin-user/main.c | 1 + linux-user/main.c | 1 + 3 files changed, 3 insertions(+), 0 deletions(-)bsd-user/main.c +1
-0@@ -351,6 +351,7 @@ static void usage(void) interp_prefix, x86_stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }darwin-user/main.c +1
-0@@ -758,6 +758,7 @@ void usage(void) interp_prefix, stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }linux-user/main.c +1
-0@@ -2216,6 +2216,7 @@ static void usage(void) interp_prefix, x86_stack_size, DEBUG_LOGFILE); +fflush (stdout);_exit (1 ); }
Signature · 1 line
"rm -rf" only sounds scary if you don't have backups
Quoted 11 lines · Riku Voipio
Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Riku Voipio
testcase:
qemu-arm|grep cpu
Without
fflush()getting output from piped qemu is a bit random.It should get flushed upon
exit(). Perhaps the problem is that we're using_exit()instead ofexit()?
_exit does not trigger callbacks registred with at_exit.
from the man page :
The function _exit() is like exit(3), but does not call any functions registered with atexit(3) or on_exit(3). Whether it flushes standard I/O buffers and removes temporary files created with tmpfile(3) is
implementation-dependent. On the other hand, _exit() does close open
file descriptors, and this may cause an unknown delay, waiting for pending output to finish. If the delay is undesired, it may be useful to call functions like tcflush(3) before calling _exit(). Whether any pending I/O is canceled, and which pending I/O may be canceled upon _exit(), is implementation-dependent.
Quoted 8 lines · Lionel Landwerlin
Quoted 6 lines · Riku Voipio
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Riku Voipio
testcase:
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
qemu-arm|grep cpu
Without
fflush()getting output from piped qemu is a bit random.It should get flushed upon
exit(). Perhaps the problem is that we're using_exit()instead ofexit()?
_exitdoes not trigger callbacks registred withat_exit.
Yes. The question is why is it being used? What at_exit handler are we trying to avoid.
Regards,
Anthony Liguori
Quoted 17 lines
from the man page :
The function
_exit()is like exit(3), but does not call any functions registered with atexit(3) oron_exit(3). Whether it flushes standard I/O buffers and removes temporary files created with tmpfile(3) is
implementation-dependent. On the other hand,_exit()does close open
file descriptors, and this may cause an unknown delay, waiting for pending output to finish. If the delay is undesired, it may be useful to call functions like tcflush(3) before calling_exit(). Whether any pending I/O is canceled, and which pending I/O may be canceled upon_exit(), is implementation-dependent.
Quoted 6 lines · Anthony Liguori
Quoted 5 lines · Lionel Landwerlin
Quoted 5 lines · Anthony Liguori
Quoted 4 lines
Quoted 2 lines · Riku Voipio
Without
fflush()getting output from piped qemu is a bit random.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
It should get flushed upon
exit(). Perhaps the problem is that we're using_exit()instead ofexit()?
_exitdoes not trigger callbacks registred withat_exit.Yes. The question is why is it being used? What
at_exithandler are we trying to avoid.
Historic reasons? Just to "be safe" since system qemu uses atexit handlers? I don't see any atexit handlers registered for linux-user (or bsd-user) targets for current svn qemu. Definetly none registered at command line parsing stage.