Avoid undefined behavior due to dangling file descriptor

Authored by tobiasdeiminger on Sep 18 2018, 7:30 PM.

Description

Avoid undefined behavior due to dangling file descriptor

Summary:
We request a inhibit lock of DBus type UNIX_FD from systemd logind. It's wrapped into (and owned by) a QDBusUnixFileDescriptor object of automatic storage. The file descriptor will be closed in QDBusUnixFileDescriptor Dtor, and may be reused by some other facility (e.g. pulseaudio).

If we want to store the lock longer than QDBusUnixFileDescriptor lifetime, we have to dup the file descriptor. If we don't dup, and close the original fd later in PresentationWidget::allowPowerManagement, bad things may happen.

Besides that, what we get from systemd is really a file descriptor, not a "cookie". So I renamed the m_sleepInhibitCookie to m_sleepInhibitFd and changed initial state to -1 accordingly.

BUG 393478
BUG 398720

Test Plan:

  • bugs don't occur any longer
  • inhibiting sleep during presentation mode still works

Reviewers: aacid

Reviewed By: aacid

Subscribers: ngraham, anthonyfieroni, okular-devel

Tags: Okular

Differential Revision: https://phabricator.kde.org/D15574

Details