Skip to content

Fix closing of standard text streams for non-glibc system

Patrick Steinhardt util-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4term-utils/ttymsg: fix missing header for ARRAY_SIZE macroterm-utils/ttymsg.c+1 -00 replies
2/4login-utils/islocal: fix missing header for err macrologin-utils/islocal.c+1 -00 replies
3/4lib/closestream: move implementation into its own compilation unitdisk-utils/Makemodule.am include/closestream.h lib/Makemodule.am +5 more+45 -950 replies
4/4lib/closestream: fix assignment to read-only standard streamslib/closestream.c+5 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] Fix closing of standard text streams for non-glibc system

Hi,

since commit 52aa1a661 (include/closestream: avoid close more than once, 2019-06-13), util-linux fails to build on musl libc based systems. The culprit here is that it introduced assignments to stderr and stdout, while the C89 standard explicitly notes that treating stderr and stdout as valid lvalues is not a requirement for any conforming C implementation. musl libc implemented these streams as extern FILE *const, and as a result assigning to these variables causes compiler errors.

Attached is a fix for this. Instead of assigning NULL to the streams, util-linux now uses a static variable streams_closed. Unfortunately, this fix necessitated some shifting around as closestream was previously implemented as header, only, and implementing static variables inside of a header is not going to work due to them being static to the single compilation unit, only. Thus I converted the code to move the implementation into "lib/closestream.c".

Regards
Patrick

Patrick Steinhardt (4):
term-utils/ttymsg: fix missing header for ARRAY_SIZE macro login-utils/islocal: fix missing header for err macro lib/closestream: move implementation into its own compilation unit lib/closestream: fix assignment to read-only standard streams

 disk-utils/Makemodule.am                   |  2 +
 include/closestream.h                      | 90 +++-------------------
 lib/Makemodule.am                          |  1 +
 include/closestream.h => lib/closestream.c | 27 ++++---
 login-utils/Makemodule.am                  |  4 +-
 login-utils/islocal.c                      |  1 +
 misc-utils/Makemodule.am                   | 10 ++-
 sys-utils/Makemodule.am                    |  9 ++-
 term-utils/ttymsg.c                        |  1 +
 text-utils/Makemodule.am                   |  6 +-
 10 files changed, 52 insertions(+), 99 deletions(-)
 copy include/closestream.h => lib/closestream.c (75%)
Signature · 1 line
2.22.1