getting PID on DBus

Colin Walters walters at verbum.org
Mon Sep 15 07:29:47 PDT 2008


On Mon, Sep 15, 2008 at 10:25 AM, Akshay Sumant <sumantakshay at gmail.com> wrote:

> Hi,
>     I have daemon exposing  a method on DBus which other processes are
> using, I want to know PID of process calling exposed method, I have used
> dbus_connection_get_unix_process_id.  It is not returning me valid PID.
> Please help.
>
> Here is a code snippet,
>
> DBusConnection *bus;
>   bus = dbus_g_connection_get_connection(context->connection);
>   status = dbus_connection_get_unix_process_id(bus,pid);
>
> I am getting return value, status = FALSE.
>
For posterity, the answer here is to call GetConnectionUnixUser on the
bus, rather than using the connection method (which is designed for
point-to-point rather than messages sent over the bus).

<walters> python -c "import dbus;
bus=dbus.SystemBus().get_object('org.freedesktop.DBus',
'/org/freedesktop/DBus'); print dbus.Interface(bus,
'org.freedesktop.DBus').GetConnectionUnixUser(':1.11')"
<walters> where ':1.11' is the return value from dbus_message_get_sender


More information about the dbus mailing list