logind: fix (again) the race that might happen when logind restores VT
authorFranck Bui <fbui@suse.com>
Fri, 18 Oct 2019 10:44:51 +0000 (12:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 12 Nov 2019 13:53:24 +0000 (14:53 +0100)
commit8246905af07f741a739c4add8da2c4ade0f20fcf
tree8beab2198701ea5facc115c7c687bf43d9b399f8
parent9e9dd3e329a69a3aad5698552697b3257fdc3845
logind: fix (again) the race that might happen when logind restores VT

This patch is a new attempt to fix the race originally described in issue #9754.

The initial fix (commit ad96887a1205bad9656d280c5681f482e6d04838) consisted in
spawning a sub process that became the controlling process of the VT and hence
kicked the old controlling process off to make sure that the VT wouldn't have
entered in HUP state while logind restored the VT.

But it introduced a regression (see issue #11269) and thus was reverted. But
unlike it was described in the revert commit message, commit
adb8688b3ff445d9c48ed0d72208c7844c2acc01 alone doen't fix the initial race.

This patch fixes the race in a simpler way by trying to restore the VT a second
time after making sure to re-open it if the first attempt fails.

Indeed if the old controlling process dies before or during the first attempt,
logind will fail to restore the VT. At this point the VT is in HUP state but
we're sure that it won't enter in a HUP state a second time. Therefore we will
retry by re-opening the VT to clear the HUP state and by restoring the VT a
second time, which should be safe this time.

Fixes: #9754
Fixes: #13241
src/login/logind-session.c