]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libmount: improve mountinfo reliability
authorKarel Zak <kzak@redhat.com>
Wed, 28 Aug 2019 13:47:16 +0000 (15:47 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Aug 2019 12:27:11 +0000 (14:27 +0200)
commite4925f591c1bfb83719418b56b952830d15b77eb
tree8c41e254141c47a997012e8122c828ff7269db2f
parent59a46f36b604fe46747d5a5b6c85078a39b37c2e
libmount: improve mountinfo reliability

The standard way how we read mount table is not reliable because
during the read() syscalls the table may be modified by some another
process. The changes in the table is possible to detect by poll()
event, and in this case it seems better to lseek to the begin of the file
and read it again. It's expensive, but better than races...

This patch does not modify mountinfo parser, but it reads all file to
memory (by read()+poll()) and than it creates memory stream
from the buffer and use it rather than a regular file stream.

It means the parser is still possible to use for normal files
(e.g. fstab) as well as for mountinfo and it's also portable to
systems where for some reason is no fmemopen().

Note that re-read after poll() event is limited to 5 attempts (but
successful read() without event zeroize the counter). It's because we
do not want to wait for consistent mountinfo for ever. It seems better
to use old (less reliable) way than hang up in read()+poll()
loop.

Addresses: https://github.com/systemd/systemd/issues/10872
Reported-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
libmount/src/mountP.h
libmount/src/tab_parse.c
libmount/src/utils.c