Skip to contentSkip to conversation

flush stdout after printing usage()

PATCH In review Riku Voipio 3 participants 6 messages Jan 28, 2009 – Feb 6, 2009

lore
Share & tools
lore
#0 lore raw

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
index 636f1dc..f3cb3b1 100644
@@ -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
index 3edad73..44e8f7c 100644
@@ -758,6 +758,7 @@ void usage(void)
            interp_prefix,
            stack_size,
            DEBUG_LOGFILE);
+    fflush(stdout);
     _exit(1);
 }
 
linux-user/main.c +1 -0
index 3418ca6..9b807e5 100644
@@ -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
#1 lore raw
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
---
 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
index 636f1dc..f3cb3b1 100644
@@ -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
index 3edad73..44e8f7c 100644
@@ -758,6 +758,7 @@ void usage(void)
            interp_prefix,
            stack_size,
            DEBUG_LOGFILE);
+    fflush(stdout);
     _exit(1);
 }
 
linux-user/main.c +1 -0
index 3418ca6..9b807e5 100644
@@ -2216,6 +2216,7 @@ static void usage(void)
            interp_prefix,
            x86_stack_size,
            DEBUG_LOGFILE);
+    fflush(stdout);
     _exit(1);
 }
 
#2 lore raw
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 of exit()?

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

---

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
index 636f1dc..f3cb3b1 100644
@@ -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
index 3edad73..44e8f7c 100644
@@ -758,6 +758,7 @@ void usage(void)
           interp_prefix,
           stack_size,
           DEBUG_LOGFILE);
+    fflush(stdout);
    _exit(1);
 }
 
linux-user/main.c +1 -0
index 3418ca6..9b807e5 100644
@@ -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
#3 lore raw
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 of exit()?

_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.

#4 lore raw
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 of exit()?

_exit does not trigger callbacks registred with at_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) 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.

#5 lore raw
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 of exit()?

_exit does not trigger callbacks registred with at_exit.

Yes. The question is why is it being used? What at_exit handler 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.