Access DBus from container

Hi

I’m trying to get access to system DBus from within a C++ container. I made it privileged like this and added bind mounts corresponding to other threads I found on this forum:

image

The code to open a DBus connection goes like this:

    DBusError err;
    int ret;
    // initialise the errors
    dbus_error_init(&err);

    std::cout << "Establishing DBus connection..." << std::endl;
    DBusConnection* conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if (dbus_error_is_set(&err)) { 
        fprintf(stderr, "Connection Error (%s)\n", err.message); 
        dbus_error_free(&err); 
    }

    if(conn == NULL) {
        std::cout << "Could not establish DBus connection" << std::endl;
    }
    else {
        std::cout << "Connection set up" << std::endl;
    }

I always get the following error:

Connection Error (Unable to autolaunch a dbus-daemon without a $DISPLAY for X11)

What else should I do to get access to system DBus?

Kind regards,
Merijn

I’m an idiot. Using DBUS_BUS_SYSTEM instead of DBUS_BUS_SESSION did the trick.