flush pending stdio on error, add posterror_hooks