util-linux/include
Patrick Steinhardt 530220b6bf include/closestream: fix assignment to read-only standard streams
In order to avoid closing standard streams multiple times, commit
52aa1a661 (include/closestream: avoid close more than once, 2019-06-13)
introduced code to set the standard output and error streams to `NULL`.
As musl libc defines standard streams as constant pointers, the change
causes compiler errors on systems with that libc. According to ISO C89,
being able to assign to the standard text streams is not a requirement
for any C implementation, see footnote 238 in chapter §7.19.5.6:

    The primary use of the freopen function is to change the file
    associated with a standard text stream (stderr, stdin, or stdout),
    as those identifiers need not be modifiable lvalues to which the
    value returned by the fopen function may be assigned.

This commit implements a new function `flush_standard_stream` that tries
to reliably flush standard streams without actually closing them. By not
calling fclose(3P), we can neatly avoid the issue of accessing standard
streams in an unspecified state and thus remove the infringing `NULL`
assignments.

Properly flushing standard streams without fclose(3P) proves to be more
intricate than one may expect, though, as some filesystems like NFS may
defer flushing until they see a close(3P) of the underlying descriptor.
One may call fsync(3P) to remedy that, but this may incur a heavy
performance penalty in some scenarios. To work around the issue and
still get proper errors, we duplicate the stream's file descriptor and
close that one instead, which is sufficient to cause a flush.

Note that both `close_stdout` and `close_stdout_atexit` are misnamed
after this change, as we do not actually close the streams now. In order
to avoid unnecessary code churn, we still retain their current names.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-09-02 11:55:56 +02:00
..
Makemodule.am include/debug: don't print pointer address for SUID programs 2018-01-12 11:01:26 +01:00
all-io.h include/all-io: const cleanup 2018-07-20 14:53:25 +02:00
bitops.h include/bitops: avoid fallbacks for more systems 2016-03-08 14:55:38 +01:00
blkdev.h lib: include sys/stat.h for struct stat 2016-03-07 23:17:12 +01:00
c.h include/c: use __has_attribute 2019-05-21 16:27:17 +02:00
canonicalize.h lsblk: use prefix for DM name 2018-06-21 13:19:28 +02:00
carefulputc.h Remove isascii usage 2019-08-08 12:12:55 -07:00
cctype.h lib: add parse-date.y 2017-03-04 10:49:41 -05:00
closestream.h include/closestream: fix assignment to read-only standard streams 2019-09-02 11:55:56 +02:00
color-names.h misc: Fix various typos 2016-05-31 23:40:21 +02:00
colors.h lib/colors: force to "never" mode on non-terminal output 2019-02-04 14:14:37 +01:00
cpuset.h misc: Fix various typos 2016-05-31 23:40:21 +02:00
crc32.h lib/crc32: prefix public functions 2016-10-19 12:11:59 +02:00
crc32c.h lib: Add simple crc32c() function 2017-11-16 11:44:39 +01:00
debug.h include/debug: introduce __UL_INIT_DEBUG_FROM_STRING() 2018-01-17 13:58:29 +01:00
debugobj.h include/debug: don't print pointer address for SUID programs 2018-01-12 11:01:26 +01:00
env.h include/env: minor fixes and clean ups 2016-08-16 12:35:57 +02:00
exec_shell.h lib/exec_shell: cleanup function attributes 2018-02-01 12:25:39 +01:00
exitcodes.h include/exitcodes: remove mount(8) exit codes 2017-04-27 14:26:45 +02:00
fileutils.h lib/fileutils: add xreaddir() 2019-04-11 13:11:53 +02:00
idcache.h namei: move icache to lib/ 2015-11-27 13:56:01 +01:00
ismounted.h lib: import whole ismounted.c code from e2fsprogs 2009-10-14 01:13:18 +02:00
linux_version.h lib: add linux_version.{c,h} 2007-11-06 02:40:13 +01:00
list.h include/list: add list_entry_is_first() and list_count_entries() 2018-12-07 12:33:34 +01:00
loopdev.h lib/loopdev: set blocksize when create a new device 2019-01-22 11:37:35 +01:00
mangle.h lib/mangle: const quialifier cleanup 2018-07-20 15:31:42 +02:00
match.h lib,match: split match_fstype() from libmount 2011-11-15 15:17:19 +01:00
mbsalign.h lib/mbsalign: add mbs_invalid_encode() 2017-11-22 14:41:10 +01:00
mbsedit.h lib/mbsedit: add simple buffer editor 2017-02-16 13:47:44 +01:00
md5.h lib/md5: use ul_/UL_ prefix 2017-12-12 12:06:15 +01:00
minix.h libblkid: arch independent minix detection 2013-04-15 15:14:33 +02:00
monotonic.h include: add indirect monotonic clock id specifier 2019-01-12 08:46:53 +00:00
namespace.h Implement support for cgroup namespaces 2016-03-02 17:53:42 -08:00
nls.h misc: fix typos using codespell 2018-02-16 11:12:52 +01:00
optutils.h optutils.h: don't print non-graph characters 2017-04-18 22:39:05 -04:00
pager.h lib/pager: cleanup and extend API 2016-08-26 12:07:25 +02:00
partx.h build-sys: fix non-blkid compilation 2017-09-19 13:48:52 +02:00
path.h include/path.h: remove duplicate header inclusion 2019-02-18 13:21:46 +01:00
pathnames.h wdctl; read from /sys if necessary 2019-06-17 15:47:39 +02:00
plymouth-ctrl.h misc: Fix various typos 2016-05-31 23:40:21 +02:00
procutils.h lslocks: use stuff from lib/procutils 2015-11-25 14:17:22 +01:00
pt-bsd.h fdisk: (bsd) write/read PT code cleanup 2013-09-16 16:47:06 +02:00
pt-mbr-partnames.h docs: remove some old history from manpages 2017-06-29 12:56:22 +02:00
pt-mbr.h include/pt-mbr.h: fix integer overflow 2018-05-28 13:36:38 +02:00
pt-sgi.h libfdisk: (sgi) improve checksum calculation [-Waddress-of-packed-member] 2019-05-22 17:42:48 +02:00
pt-sun.h libblkid: const qualifier cleanup 2018-07-20 15:05:32 +02:00
pwdutils.h lib/pwdutils: add xgetlogin() 2017-09-18 11:48:56 +02:00
randutils.h lib/randutils: remove unnecessary function 2016-10-04 16:18:16 +02:00
rpmatch.h rpmatch: use symbolic value when evaluation return codes 2015-02-24 12:42:06 +01:00
setproctitle.h lib: cleanup setproctitle.c 2011-10-26 23:17:15 +02:00
sha1.h lib/sha1: use ul_/UL_prefix for symbols 2017-12-12 11:29:02 +01:00
signames.h lib/signames: remove unused function 2017-11-28 14:39:17 +01:00
statfs_magic.h misc: Fix various typos 2016-05-31 23:40:21 +02:00
strutils.h include/strutils: fix potential null pointer dereference 2019-05-16 22:05:07 +01:00
strv.h lib/strv: add strv_extendv() 2015-10-01 14:43:05 +02:00
swapheader.h mkswap: remove unnecessary size check 2014-11-07 13:21:05 +01:00
swapprober.h swapon: split swapon-common.c 2014-09-22 13:16:25 +02:00
sysfs.h lib/sysfs: add function to detect partitioned devices 2018-12-07 12:32:57 +01:00
timer.h lib/timer: add fallback if timer_create() not available 2018-12-03 11:23:33 +01:00
timeutils.h timeutils: match today day and this year correctly 2019-01-12 08:46:29 +00:00
ttyutils.h lib/ttyutils: introduce get_terminal_stdfd() 2019-05-27 12:49:12 +02:00
widechar.h include/widechar: add fallback for WEOF 2016-06-03 14:50:48 +02:00
xalloc.h include/xalloc: reindent function bodies to unify indentation 2019-08-21 15:00:16 +02:00