From b39f5e6c9c50b3153c4e7bfac9219f14da73e4d1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 6 Jul 2019 17:41:52 -0700 Subject: =?UTF-8?q?Don=E2=80=99t=20ignore=20stderr=20failure=20when=20ADDR?= =?UTF-8?q?ESS=5FSANITIZER?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * src/emacs.c (close_output_streams): Move from here ... * src/sysdep.c: ... to here, where it really belongs anyway. When ADDRESS_SANITIZER, fflush stderr and check for ferror, to catch stderr output errors even in this case. --- src/sysdep.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/sysdep.c') diff --git a/src/sysdep.c b/src/sysdep.c index 4f89e8aba10..48eebb594f7 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -30,6 +30,7 @@ along with GNU Emacs. If not, see . */ #include #include +#include #include #include @@ -2768,6 +2769,25 @@ safe_strsignal (int code) return signame; } +/* Close standard output and standard error, reporting any write + errors as best we can. This is intended for use with atexit. */ +void +close_output_streams (void) +{ + if (close_stream (stdout) != 0) + { + emacs_perror ("Write error to standard output"); + _exit (EXIT_FAILURE); + } + + /* Do not close stderr if addresses are being sanitized, as the + sanitizer might report to stderr after this function is invoked. */ + if (ADDRESS_SANITIZER + ? fflush_unlocked (stderr) != 0 || ferror (stderr) + : close_stream (stderr) != 0) + _exit (EXIT_FAILURE); +} + #ifndef DOS_NT /* For make-serial-process */ int -- cgit v1.2.1