Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix file descriptors not supported #42

Open
jawsper opened this issue Jan 19, 2017 · 5 comments
Open

Unix file descriptors not supported #42

jawsper opened this issue Jan 19, 2017 · 5 comments

Comments

@jawsper
Copy link

jawsper commented Jan 19, 2017

When I try to inhibit the power key on org.freedesktop.login1, pydbus doesn't seem to return the file descriptor, nor does it give me an error.

Sample code:

import pydbus
bus = pydbus.SystemBus()
login1 = bus.get('.login1')['.Manager']
fd = login1.Inhibit('handle-power-key', 'AppName', 'Reason', 'block')

Expected result is a valid file descriptor.
Actual result is 0.

This does work fine in python-dbus:

import dbus
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.login1', '/org/freedesktop/login1')
login1 = dbus.Interface(proxy, 'org.freedesktop.login1.Manager')
fd = login1.Inhibit('handle-power-key', 'test_logind', 'test_logind handling power button', 'block').take()

This is on python 3.6.0 with pydbus version 0.6.0

@LEW21
Copy link
Owner

LEW21 commented Jan 19, 2017

I haven't written any code for fd passing yet, and looks like GDBus does not support them transparently, but requires using g_dbus_message_get_unix_fd_list - like in https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-example-unix-fd-client.c#n27

I guess it's necessary to modify https://github.com/LEW21/pydbus/blob/master/pydbus/proxy_method.py#L72 to use the GDBusMessage API for calling methods.

@jawsper
Copy link
Author

jawsper commented Jan 19, 2017

While digging around I found the method call_with_unix_fd_list_sync, which seems to be the right function for this job.
Documentation: http://lazka.github.io/pgi-docs/#Gio-2.0/classes/DBusConnection.html#Gio.DBusConnection.call_with_unix_fd_list_sync
Example usage: https://git.centos.org/blob/rpms!gnome-tweak-tool/aaa06e94d4f5ac34090c5b33a91b8ab2dfdcd74f/SOURCES!0001-Add-a-tweak-to-ignore-systemd-s-default-lid-switch-a.patch#L98

I've made a nasty hack to test if this is right, and so far it seems to be successful.

@jawsper
Copy link
Author

jawsper commented Jan 20, 2017

I did some more checks, and it appears it doesn't matter if you call call_sync or call_with_unix_fd_list_sync, since they both call g_dbus_connection_call_sync_internal anyway. (https://git.gnome.org/browse/glib/tree/gio/gdbusconnection.c?h=2.50.0#n6162 vs https://git.gnome.org/browse/glib/tree/gio/gdbusconnection.c?h=2.50.0#n6281)

The question now is how to solve this in the cleanest way. I would propose to use call_with_unix_fd_list_sync either way, since it works the same for either case. Only matter now is deciding how to deal with the return value in the best way. I think the best result would be to copy the result of dbus-python, and replace the return values with the file descriptor as an integer.

One issue I do still see is that call_with_unix_fd_list_sync only works on UNIX, but is that actually an issue? Is there dbus for non-UNIX systems?

@ukBaz
Copy link

ukBaz commented Apr 26, 2017

I just wanted to add that I've seen issues with Unix file descriptors not being represented correctly in pydbus also. It has taken me a while to track this down and I wanted to share some of my findings in the hope that it helps.

I have been rewriting the BlueZ test-profile script to use pydbus.
The fd argument for NewConnection is of type h.
When using python-dbus this arrives as type 'dbus.UnixFd' and when using pydbus it turns up as class int.
Looking at https://developer.gnome.org/glib/stable/gvariant-format-strings.html suggests that pydbus is correct while https://dbus.freedesktop.org/doc/dbus-specification.html#basic-types suggests python-dbus is correct. However it is only possible to read the file with the information given by python-dbus.

Is there a simple work around that would allow me to get something working for test-profile with pydbus?
Or is this a show-stopping issue?

Thanks in advance,
Barry

@jawsper jawsper changed the title Invalid return value? Unix file descriptors not supported Jun 21, 2017
@molobrakos
Copy link

Relevant: #54 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants