I'm writing a program for a Raspberry Pi that needs to be notified when the user inserts a USB drive. I'm using Qt's D-Bus support to listen to InterfacesAdded from org.freedesktop.UDisks2, which works fine on my x86 Linux desktop.
Here's my code that sets up the D-Bus signal to my class's slot:
auto bus = QDBusConnection::systemBus();
auto monitor = new UsbMonitor(&app); // my class
if (!bus.connect("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", "org.freedesktop.DBus.ObjectManager", "InterfacesAdded",
monitor, SLOT(handleit(QDBusObjectPath, QMap<QString,QVariant>)))) {
qFatal("FATAL Couldn't connect USB monitor to D-Bus signal");
}
It does not work on the Pi. I tracked it down to the fact that udisksd isn't running, even though it should automatically start whenever it's needed.
I'm guessing that because I'm booting to console (not GUI) and only adding a signal handler, that that's not enough to have D-Bus automatically start udisksd.
If I add
auto msg = QDBusMessage::createMethodCall("org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
bus.call(msg);
before my call to bus.connect
then everything works.
Is there a better way to make sure udisksd is running? I'd rather change a configuration file on the Pi than have to have extra code just to "wake up" a service.