0

I am trying to create a peer-to-peer gdbus communication on a linux system. I used gdbus-codegen tool to generate the code which I can use to create the server. My server program instantiates an object using the generated skeleton functions and exports it via the g_dbus_interface_skeleton_export function. Here is an overview of the server function which gets invoked when the server receives a new connection:

static gboolean on_new_connection(GDBusServer *server, GDBusConnection *connection, gpointer user_data)
{
    GError *error = NULL;
    printf("Got a new connection!\n");

    my_object = org_some_object_skeleton_new();
    g_signal_connect(my_object, "handle-get-magic-number", G_CALLBACK(my_callback_function), NULL);
    if(!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(my_object), connection,  "/some/path", &error))

    return TRUE;
}

After compiling and starting the server, I try to contact it using the gdbus tool:

gdbus call --address=unix:path=/home/my_user_name/MySockets/some_socket --object-path=/some/path --method=org.some.object.get_magic_number

However, I get the following response:

Error connecting: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.DBus” on object at path /org/freedesktop/DBus

What is going on here? Is it actually possible to use the generated skeleton functions when creating a peer-to-peer server, or do I have to use the lower-level API calls such as g_dbus_connection_register_object?

Moon_Raven
  • 309
  • 2
  • 12
  • 1
    Are you sure that there is a D-Bus daemon running at `unix:path=/home/my_user_name/MySockets/some_socket`? From the error message, I would suspect there is not. – nielsdg Sep 06 '20 at 15:54
  • I opened that socket from my server application (so it is not a separate dbus daemon, but it connects the client directly to my server application). I assume that part works since the printf inside the server "on_new_connection" function actually gets triggered. – Moon_Raven Sep 07 '20 at 09:06

1 Answers1

0

From what I gather from your question and your comment, it seems like you're trying to do D-Bus IPC on a raw socket, without any D-Bus daemon running on that path. It unfortunately doesn't work like that, since D-Bus really needs some kind of broker running. You have a few options here:

  • Rather than use a raw socket, you can connect to the session or system bus (both should be available in a normal Linux session)
  • You start a D-Bus daemon that listens to the socket at the provided path before starting your application. See also dbus-daemon or D-Bus Broker for implementations.
  • You keep on using a raw socket, at which point you use an application-specific protocol (which can be based on any kind of RPC).
nielsdg
  • 2,318
  • 1
  • 13
  • 22