]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/basic/terminal-util.c
fileio: fileno() can realistically return -1
authorLennart Poettering <lennart@poettering.net>
Mon, 13 Apr 2020 08:09:44 +0000 (10:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 13 Apr 2020 09:26:49 +0000 (11:26 +0200)
commit14f594b995bbaea85456a4c26e5c07446a4c446e
tree0ab2b1d668ea6d386167b2cc1a6104213f50562b
parent9d5dac4dce8721eaa14800039d8a31428c072d13
fileio: fileno() can realistically return -1

An stdio FILE* stream usually refers to something with a file
descriptor, but that's just "usually". It doesn't have to, when taking
fmemopen() and similar into account. Most of our calls to fileno()
assumed the call couldn't fail. In most cases this was correct, but in
some cases where we didn't know whether we work on files or memory we'd
use the returned fd as if it was unconditionally valid while it wasn't,
and passed it to a multitude of kernel syscalls. Let's fix that, and do
something reasonably smart when encountering this case.

(Running test-fileio with this patch applied will remove tons of ioctl()
calls on -1).
src/basic/fileio.c
src/basic/terminal-util.c
src/shared/conf-parser.c