]> git.ipfire.org Git - thirdparty/systemd.git/commit
fd-util: optimize fd_get_path() a bit 10523/head
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Oct 2018 19:27:00 +0000 (21:27 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 25 Oct 2018 19:37:14 +0000 (21:37 +0200)
commitf267719c389de57ceda433f6288a505e7eeb2f8f
tree6729f4bdbcd4075879fd70c55df1d9118b29f7c5
parent8e060ec225b74bbf22e5bdbacd604efcc73294c0
fd-util: optimize fd_get_path() a bit

journald calls fd_get_path() a lot (it probably shouldn't, there's some
room for improvement there, but I'll leave that for another time), hence
it's worth optimizing the call a bit, in particular as it's easy.

Previously we'd open the dir /proc/self/fd/ first, before reading the
symlink inside it. This means the whole function requires three system
calls: open(), readlinkat(), close(). The reason for doing it this way
is to distinguish the case when we see ENOENT because /proc is not
mounted and the case when the fd doesn't exist.

With this change we'll directly go for the readlink(), and only if that
fails do an access() to see if /proc is mounted at all.

This optimizes the common case (where the fd is valid and /proc
mounted), in favour of the uncommon case (where the fd doesn#t exist or
/proc is not mounted).
src/basic/fd-util.c