From 52482ec70d0feaa0a9a56cff8b6e504f4ad0ed3a Mon Sep 17 00:00:00 2001
From: "Matthew W. S. Bell" <matthew@bells23.org.uk>
Date: Thu, 4 Jan 2018 13:23:17 +0000
Subject: [PATCH] Use with_unix_fd_list variant of DBus method call.

Any returned 'h' type argument is intended to be an index into a
unix fd list structure obtained separately. Such a unix fd list, in
python, will manage and close any contained fds as a whole, or fds may
be retrieved, managed, and closed individually, as is done in this
patch.

Also, use None instead of -1 because python.

This patch means gajim keeps its supsend inhibitor open and stops it
closing stdin on suspend.

Fixes #8852
---
 gajim/logind_listener.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gajim/logind_listener.py b/gajim/logind_listener.py
index 80c5e1ab9e..41bd5e8595 100644
--- a/gajim/logind_listener.py
+++ b/gajim/logind_listener.py
@@ -33,7 +33,7 @@ log = logging.getLogger('gajim.logind_listener')
 
 # file descriptor of the inhibitor; negative number means we don't
 # hold any (yet)
-fd = -1
+fd = None
 
 
 def signal_received(connection, sender_name, object_path,
@@ -61,9 +61,9 @@ def signal_received(connection, sender_name, object_path,
             conn.time_to_reconnect = 5
 
     # close the file descriptor and let the computer suspend
-    if fd >= 0:
+    if fd is not None:
         os.close(fd)
-        fd = -1
+        fd = None
     else:
         # something is wrong, the system is suspending but we don't have
         # a lock file
@@ -76,23 +76,23 @@ def get_inhibitor(connection):
 
     global fd
 
-    if fd >= 0:
+    if fd is not None:
         # someting is wrong, we haven't closed the previous file descriptor
         # and we ask for yet another one
         log.warning('We are about to ask for a sleep inhibitor, but we seem '
                     'to be holding one already')
 
-    ret = connection.call_sync(
+    ret = connection.call_with_unix_fd_list_sync(
         'org.freedesktop.login1',
         '/org/freedesktop/login1',
         'org.freedesktop.login1.Manager',
         'Inhibit',
         GLib.Variant('(ssss)', ('sleep', 'org.gajim.Gajim',
                                 'Disconnect from the network', 'delay')),
-        None,
-        Gio.DBusCallFlags.NONE, -1, None)
+        GLib.VariantType.new('(h)'),
+        Gio.DBusCallFlags.NONE, -1, None, None)
 
-    fd = ret[0]
+    fd = ret.out_fd_list.get(ret[0])
 
 
 def appeared(connection, name, name_owner, *user_data):
-- 
GitLab