properly check return values and exit with a better error instead of ABORT on SIGPIPE