Mercurial > hg > octave-lojdl > gnulib-hg
changeset 11713:2b42a598bba2
error: avoid undefined use of stdout
* lib/error.c (error, error_at_line): Check that fd 1 is open
before flushing stdout. Avoids a crash on cygwin when libsigsegv
is handling faults and the close_stdout module wants to report the
detection of closed stdout as an error.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Sat, 18 Jul 2009 06:18:21 -0600 |
parents | e40a88324201 |
children | f33d1c9d5f8f |
files | ChangeLog lib/error.c |
diffstat | 2 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-07-18 Eric Blake <ebb9@byu.net> + + error: avoid undefined use of stdout + * lib/error.c (error, error_at_line): Check that fd 1 is open + before flushing stdout. Avoids a crash on cygwin when libsigsegv + is handling faults and the close_stdout module wants to report the + detection of closed stdout as an error. + 2009-07-17 Eric Blake <ebb9@byu.net> pipe: be robust in face of closed fds
--- a/lib/error.c +++ b/lib/error.c @@ -1,5 +1,5 @@ /* Error handler for noninteractive utilities - Copyright (C) 1990-1998, 2000-2007 Free Software Foundation, Inc. + Copyright (C) 1990-1998, 2000-2007, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software: you can redistribute it and/or modify @@ -85,6 +85,8 @@ #else /* not _LIBC */ +# include <fcntl.h> + # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P # ifndef HAVE_DECL_STRERROR_R "this configure-time declaration test was not run" @@ -236,6 +238,12 @@ 0); #endif +#if !_LIBC + /* POSIX states that fflush (stdout) after fclose is unspecified; it + is safe in glibc, but not on all other platforms. fflush (NULL) + is always defined, but too draconian. */ + if (0 <= fcntl (1, F_GETFL)) +#endif fflush (stdout); #ifdef _LIBC _IO_flockfile (stderr); @@ -295,6 +303,12 @@ 0); #endif +#if !_LIBC + /* POSIX states that fflush (stdout) after fclose is unspecified; it + is safe in glibc, but not on all other platforms. fflush (NULL) + is always defined, but too draconian. */ + if (0 <= fcntl (1, F_GETFL)) +#endif fflush (stdout); #ifdef _LIBC _IO_flockfile (stderr);