core: when looking for a UID to use for a dynamic UID start with the current owner...
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Sep 2017 18:28:09 +0000 (20:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 2 Oct 2017 15:41:44 +0000 (17:41 +0200)
commitda50b85af7299c19cb345bd0fa2aa2f19f176ff3
treeaa0d93ad4e3b83e2232701f8623abd0da492727a
parent4a6283603324afb3da50c14a3283c5df2cc01960
core: when looking for a UID to use for a dynamic UID start with the current owner of the StateDirectory= and friends

Let's optimize dynamic UID allocation a bit: if a StateDirectory= (or
suchlike) is configured, we start our allocation loop from that UID and
use it if it currently isn't used otherwise. This is beneficial as it
saves us from having to expensively recursively chown() these
directories in the typical case (which StateDirectory= does when it
notices that the owner of the directory doesn't match the UID picked).

With this in place we now have the a three-phase logic for allocating a
dynamic UID:

a) first, we try to use the owning UID of StateDirectory=,
   CacheDirectory=, LogDirectory= if that exists and is currently
   otherwise unused.

b) if that didn't work out, we hash the UID from the service name

c) if that didn't yield an unused UID either, randomly pick new ones
   until we find a free one.
src/core/dynamic-user.c
src/core/dynamic-user.h
src/core/execute.c