]> git.ipfire.org Git - thirdparty/systemd.git/commit
capability-util: avoid thread_local
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Apr 2024 07:44:16 +0000 (09:44 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 24 Apr 2024 15:33:38 +0000 (17:33 +0200)
commitfbe8f6928e0795030a5aecceda45c6eccadafd89
treec8ed7d7d73e2f21eb52e1914eca29be40839f34a
parent98cf76a4cc5fcdbe932b2a301d4615902f9c50f4
capability-util: avoid thread_local

While stracing PID1's forking off of children I noticed that every
single forked off child reads cap_last_cap from procfs. That value is a
kernel constant, hence we can save a lot of work if we'd cache it.

Thing is, we actually do cache it, in a thread_local cache field. This
means that the forked off processes (which are considered new threads)
will have to re-query it, even though we already know the result.

Hence, let's get rid of the thread_local stuff (given that the value is
going to be the same for all threads anyway, and we pretty much have a
single thread only anyway). Use an C11 atomic_int instead, which ensures
the value is either initialized or not initialized, but we don't need to
be concerned of partial initialization.

This makes the cap_last_cap reading go away in the children, as strace
shows (since cap_last_cap() is already called by PID 1 before
fork()ing, anyway).
src/basic/capability-util.c