homed: Ensure closed FD is handled before bus req
authorAdrian Vovk <adrianvovk@gmail.com>
Thu, 21 Mar 2024 17:51:16 +0000 (13:51 -0400)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 23 Mar 2024 01:04:51 +0000 (01:04 +0000)
commit9a077230a4c3e7192c66ed7fa7439eb85893aaee
tree076957d958966274f1e48ffb1a9fe34844d849cc
parent1b5f3f5662023a8d9128214a2b094ac2e1291822
homed: Ensure closed FD is handled before bus req

Before this fix, the following sequence of events was possible:
1. A client holding a Ref() FD closes their FD
2. kernel sends notification that all clients closed their FDs
3. Another client obtains its own Ref() FD from homed
4. homed handles the notification that all clients have closed their
   Ref() FDs. Thus it loses track of the fact that the session is
   actually still being held open by the client from step 3

This change makes sure that homed won't respond to bus messages (and
thus won't open more Ref() FDs) until it has handled all notifications
about the existing FDs being closed.

logind has had a very similar fix applied to it in
e11544a8305ab9dea097c74bb16e296150c9cc10

Fixes https://github.com/systemd/systemd/issues/31518
src/home/homed-home.c
src/home/homed-manager.c