Move fflush() checking to xexit() and have exit paths in main() call that.
authorRob Landley <rob@landley.net>
Sat, 3 Jan 2015 22:25:36 +0000 (16:25 -0600)
committerRob Landley <rob@landley.net>
Sat, 3 Jan 2015 22:25:36 +0000 (16:25 -0600)
lib/xwrap.c
main.c

index d703065..de7ae83 100644 (file)
@@ -30,6 +30,8 @@ void xstrncat(char *dest, char *src, size_t size)
 
 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);
 }
diff --git a/main.c b/main.c
index dfab2f2..6ca6c2d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -136,7 +136,6 @@ void toy_exec(char *argv[])
   // 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 @@ int main(int argc, char *argv[])
     // 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();
 }