dbusjs / node-dbus-next

🚌 The next great dbus library for node
https://www.npmjs.com/package/dbus-next
155 stars 52 forks source link

Get session bus address from X11 #14

Open acrisci opened 5 years ago

acrisci commented 5 years ago

Right now to connect to a session bus, it is required that the DBUS_SESSION_BUS_ADDRESS variable is set. I know that some custom session managers like xinit will not set these environment variables automatically, and there might be some other session managers that don't either.

There is a section in the DBus specification for getting the address from a window property on X11 that is not currently followed by this library.

This is stubbed out in lib/address-x11.js but not implemented.

https://github.com/acrisci/node-dbus-next/blob/8a287c2a7995c785df8b2ac9622cd930a9def8e1/lib/address-x11.js#L7-L36

If this code can be made to work, it would require an optional dependency on the node-x11 library.

An alternative to this would be to look in $HOME/.dbus/session-bus for the session bus address based on the machine id and DISPLAY environment variable. This contains the location of the session bus that we need and might be sufficient to accomplishing the goal of not requiring the DBUS_SESSION_BUS_ADDRESS to be set in the environment. That should be tried first.

ref: https://github.com/martpie/museeks/issues/93

acrisci commented 5 years ago

Getting the dbus session bus address from the filesystem is implemented in f7bc1e1.

If that fails, we must get it from the window selection. And according to the spec if that fails, we must start our own dbus server.

martpie commented 5 years ago

It should not be too hard for me to test it by enforcing the dbus-next resolution to github:username/package#commit. Let me try.

martpie commented 5 years ago

So after a couple of tests, I think something else is going on. Here is what I tested:

export DBUS_SESSION_BUS_ADDRESS="unix:path=/var/run/dbus/system_bus_socket" && npm run museeks
export DBUS_SESSION_BUS_ADDRESS="/var/run/dbus/system_bus_socket" && npm run museeks
DBUS_SESSION_BUS_ADDRESS="unix:path=/var/run/dbus/system_bus_socket" npm run museeks
DBUS_SESSION_BUS_ADDRESS="/var/run/dbus/system_bus_socket" npm run museeks

All give me the same error that the dbus address is unknown.

However, system_bus_socket is present in var/run/dbus.

acrisci commented 5 years ago

I would expect this to fail because you are using the system bus address for the session bus.

I get this error with the example service:

Error:Connection ":1.277" is not allowed to own the service "org.test.name" due to security policies in the configuration file

My session bus is located here: unix:path=/run/user/$UID/bus

This info is gotten from $HOME/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-${DISPLAY} when the environment variable is not present.

Can you try this with the example service?

Also let me know if you are using Wayland.