diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/dbus.c | 45 | ||||
| -rw-r--r-- | common/dbus.h | 3 | 
2 files changed, 48 insertions, 0 deletions
| diff --git a/common/dbus.c b/common/dbus.c index 3b0c1097..070535d7 100644 --- a/common/dbus.c +++ b/common/dbus.c @@ -308,6 +308,51 @@ int name_listener_remove(DBusConnection *connection, const char *name,  	return 0;  } +dbus_bool_t dbus_bus_get_unix_process_id(DBusConnection *conn, const char *name, +						unsigned long *pid) +{ +	DBusMessage *msg, *reply; +	dbus_uint32_t pid_arg; + +	msg = dbus_message_new_method_call("org.freedesktop.DBus", +						"/org/freedesktop/DBus", +						"org.freedesktop.DBus", +						"GetConnectionUnixProcessID"); +	if (!msg) { +		error("Unable to allocate new message"); +		return FALSE; +	} + +	if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, +					DBUS_TYPE_INVALID)) { +		error("Unable to append arguments to message"); +		dbus_message_unref(msg); +		return FALSE; +	} + +	reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, NULL); +	if (!reply) { +		error("Sending GetConnectionUnixProcessID failed"); +		dbus_message_unref(msg); +		return FALSE; +	} + +	if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_UINT32, &pid_arg, +					DBUS_TYPE_INVALID)) { +		error("Getting GetConnectionUnixProcessID args failed"); +		dbus_message_unref(msg); +		dbus_message_unref(reply); +		return FALSE; +	} + +	*pid = (unsigned long) pid_arg; + +	dbus_message_unref(msg); +	dbus_message_unref(reply); + +	return TRUE; +} +  static DBusHandlerResult disconnect_filter(DBusConnection *conn,  						DBusMessage *msg, void *data)  { diff --git a/common/dbus.h b/common/dbus.h index 393ebcf9..51049391 100644 --- a/common/dbus.h +++ b/common/dbus.h @@ -35,6 +35,9 @@ int name_listener_add(DBusConnection *connection, const char *name,  int name_listener_remove(DBusConnection *connection, const char *name,  				name_cb_t func, void *user_data); +dbus_bool_t dbus_bus_get_unix_process_id(DBusConnection *conn, const char *name, +						unsigned long *pid); +  DBusHandlerResult simple_introspect(DBusConnection *conn, DBusMessage *msg, void *data);  static inline DBusHandlerResult send_message_and_unref(DBusConnection *conn, DBusMessage *msg) | 
