changeset 1644:492bd41f8b9a draft

Move fflush() checking to xexit() and have exit paths in main() call that.
author Rob Landley <rob@landley.net>
date Sat, 03 Jan 2015 16:25:36 -0600
parents 54c092c3ee38
children 2ffee259f519
files lib/xwrap.c main.c
diffstat 2 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib/xwrap.c	Fri Jan 02 21:28:39 2015 -0600
+++ b/lib/xwrap.c	Sat Jan 03 16:25:36 2015 -0600
@@ -30,6 +30,8 @@
 
 void xexit(void)
 {
+  if (fflush(NULL) || ferror(stdout))
+    if (!toys.exitval) perror_msg("write");
   if (toys.rebound) longjmp(*toys.rebound, 1);
   else exit(toys.exitval);
 }
--- a/main.c	Fri Jan 02 21:28:39 2015 -0600
+++ b/main.c	Sat Jan 03 16:25:36 2015 -0600
@@ -136,7 +136,6 @@
   // Run command
   toy_init(which, argv);
   if (toys.which) toys.which->toy_main();
-  if (fflush(NULL) || ferror(stdout)) perror_exit("write");
   xexit();
 }
 
@@ -189,8 +188,7 @@
     // a single toybox command built standalone with no multiplexer
     toy_singleinit(toy_list, argv);
     toy_list->toy_main();
-    if (fflush(NULL) || ferror(stdout)) perror_exit("write");
   }
 
-  return toys.exitval;
+  xexit();
 }