ntfy icon indicating copy to clipboard operation
ntfy copied to clipboard

dbus: Server address of type unix was missing argument path or abstract

Open pmav99 opened this issue 7 years ago • 3 comments

When running as root (or with sudo) I get the following traceback

# ntfy send 'aa'
ERROR: Failed to send notification using default                                                                                                                                              
Traceback (most recent call last):
  File "/root/.local/lib/python3.7/site-packages/ntfy/backends/default.py", line 20, in notify
    module.notify(title=title, message=message, **kwargs)
  File "/root/.local/lib/python3.7/site-packages/ntfy/backends/linux.py", line 31, in notify
    bus = dbus.SessionBus()
  File "/usr/lib/python3.7/site-packages/dbus/_dbus.py", line 211, in __new__
    mainloop=mainloop)
  File "/usr/lib/python3.7/site-packages/dbus/_dbus.py", line 100, in __new__
    bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
  File "/usr/lib/python3.7/site-packages/dbus/bus.py", line 122, in __new__
    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.BadAddress: Server address of type unix was missing argument path or abstract

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.local/lib/python3.7/site-packages/ntfy/__init__.py", line 58, in notify
    **backend_config)
  File "/root/.local/lib/python3.7/site-packages/ntfy/backends/default.py", line 22, in notify
    raise DefaultNotifierError(e, module)
ntfy.backends.default.DefaultNotifierError: (DBusException('Server address of type unix was missing argument path or abstract'), <module 'ntfy.backends.linux' from '/root/.local/lib/python3.7/site-packages/ntfy/backends/linux.py'>)

System: Archlinux x64

ntfy --version
2.6.0

local/dbus 1.12.10-2
    Freedesktop.org message bus system
local/python-dbus 1.2.8-2
    Python bindings for DBUS

any ideas?

pmav99 avatar Oct 14 '18 19:10 pmav99

I did take a closer look at this. I have not exactly pinpointed (it seems somehow related to polkit, pam, dbus,and who knows what else) but it does not look to have to do anything with ntfy itself so I am closing the issue.

For the record, I run archlinux+ awesome WM. I do not use a login manager and as a result I do not have a polkit authentication agent running. I think that root of the problem is that with my setup a dbus session is only started for a user that logins via a tty. Creating a login shell is not enough. So, even though you can create a shell for a different user (e.g. root) with sudo su -, you cannot use dbus to send notifications

One of the things that indicate if a session is active for the current user is:

  • $DBUS_SESSION_BUS_ADDRESS which points to a socket: /var/user/<uid>bus

pmav99 avatar Jan 07 '19 23:01 pmav99

A similar project uses something like this for the root user:

#!/bin/bash
username=<your username here>
if [ "$(id -u)" != "1000" ] ; then
    sudo -u $username DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send.sh "$@"
else
    notify-send.sh "$@"
fi

I am not sure if hardcoding /run/user/1000 is a good idea or not, but since dbus seems to require that $DBUS_SESSION_BUS_ADDRESS is set, it might make sense to actually check for its presence, and if not to exit gracefully instead of throwing an exception.

Alternatively or even complimentary, catching dbus.exceptions.DBusException and exiting gracefully, would also be nice.

@dschep thoughts?

pmav99 avatar Jan 16 '19 10:01 pmav99

Not related to ntfy but if anybody else encounters this, some info WRT why this is happening + some debugging info can be found in the following links:

  • https://unix.stackexchange.com/questions/89016/notifications-and-notification-daemon-not-working-on-window-manager?rq=1
  • https://dunst-project.org/faq/
  • https://github.com/dunst-project/dunst/issues/347#issuecomment-319370556
  • https://unix.stackexchange.com/questions/379810/find-out-the-owner-of-a-dbus-service-name
  • debian seems to be using these files to setup session: 1, 2

pmav99 avatar Jan 16 '19 11:01 pmav99