Help with dbus_connection_get_unix_process_id
I am having trouble getting the dbus_connection_get_unix_process_id
function to return TRUE
and populate the peer process ID. From the documentation:
Returns TRUE if the pid is filled in. Always returns FALSE prior to authenticating the connection.
Although I believe dbus-daemon
is configured to require authentication, and indeed I can view the authentication handshake when running strace
on the dbus-daemon
process and the client, this function always returns FALSE
.
Here is a short Python program I put together to validate:
import logging
import dbus.mainloop.glib
import dbus.service
from gi.repository import GLib
log = logging.getLogger('dbustest')
BUS_NAME = 'org.example.test'
BUS_PATH = '/'
IFACE_NAME = 'org.example.test.TestService'
class TestService(dbus.service.Object):
def __init__(self, bus):
bus_name = dbus.service.BusName(BUS_NAME, bus=bus)
super().__init__(bus_name, '/')
@dbus.service.method(IFACE_NAME, '', connection_keyword='conn')
def do_test(self, conn):
log.info('connection: %r', conn)
log.info('connection authenticated: %s', conn.get_is_authenticated())
log.info('peer process id: %s', conn.get_peer_unix_process_id())
logging.basicConfig(level=logging.DEBUG)
loop = GLib.MainLoop()
bus = dbus.SystemBus(mainloop=dbus.mainloop.glib.DBusGMainLoop())
service = TestService(bus)
loop.run()
I call this test method like so:
dbus-send --system --dest=org.example.test --print-reply / org.example.test.TestService.do_test
The server logs these messages:
INFO:dbustest:connection: <dbus._dbus.SystemBus (system) at 0x7f24380224f0>
INFO:dbustest:connection authenticated: True
INFO:dbustest:peer process id: None
If the connection is authenticated, why am I unable to get the peer's process ID?