int ret;
dbus_uint64_t flags;
+#ifdef LIBDBUSPOLICY
+ void *policy = dbuspolicy1_init (_kdbus_get_path(transport->kdbus));
+ if (NULL == policy)
+ {
+ dbus_set_error (error,
+ DBUS_ERROR_NO_REPLY,
+ "Did not receive a reply. Possible causes include: couldn't load dbus policy for kdbus transport or the message bus security policy blocked the reply.");
+ return FALSE;
+ }
+
+ transport->policy = policy;
+#endif
+
flags = KDBUS_HELLO_ACCEPT_FD;
if (registration_flags & REGISTER_FLAG_MONITOR)
flags |= KDBUS_HELLO_MONITOR;
if (ret != 0)
{
dbus_set_error (error, DBUS_ERROR_FAILED, "Hello failed: %d", -ret);
+#ifdef LIBDBUSPOLICY
+ dbuspolicy1_free (policy);
+#endif
return FALSE;
}
if (NULL == transport->my_DBus_unique_name)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, "Hello post failed: %d", -ret);
+#ifdef LIBDBUSPOLICY
+ dbuspolicy1_free (policy);
+#endif
return FALSE;
}
return ret_size;
}
+#ifdef ENABLE_KDBUS_SYNC_CALLS
static DBusMessage *
kdbus_send_sync_call (DBusTransportKdbus *transport,
DBusMessage *message)
return reply;
}
+#endif
/**
* Copy-paste from socket transport. Only renames done.
DBusTransportKdbus *transport;
DBusString address;
kdbus_t *kdbus;
-#ifdef LIBDBUSPOLICY
- void *policy;
-#endif
#ifdef DBUS_ENABLE_VERBOSE_MODE
const char *dbgenv = _dbus_getenv ("G_DBUS_DEBUG");
goto failed_0;
}
- kdbus = _kdbus_new ();
+ kdbus = _kdbus_new (path);
if (NULL == kdbus)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed_0;
}
-#ifdef LIBDBUSPOLICY
- policy = dbuspolicy1_init (path);
- if (NULL == policy)
- {
- dbus_set_error (error,
- DBUS_ERROR_NO_REPLY,
- "Did not receive a reply. Possible causes include: couldn't load dbus policy for kdbus transport or the message bus security policy blocked the reply.");
- goto failed_0_with_kdbus;
- }
-#endif
-
- ret = _kdbus_open (kdbus, path);
+ ret = _kdbus_open (kdbus);
if (ret < 0)
{
dbus_set_error (error,
"Failed to open file descriptor: %s: %s",
path,
_dbus_strerror (-ret));
- goto failed_0_with_kdbus_and_policy;
+ goto failed_0_with_kdbus;
}
_dbus_verbose ("Successfully connected to kdbus bus %s\n", path);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed_1;
}
-#ifdef LIBDBUSPOLICY
- transport->policy = policy;
-#endif
_dbus_string_free (&address);
failed_1:
_kdbus_close (kdbus);
-failed_0_with_kdbus_and_policy:
-#ifdef LIBDBUSPOLICY
- dbuspolicy1_free (policy);
-#endif
failed_0_with_kdbus:
_kdbus_free (kdbus);
failed_0:
struct kdbus_t
{
+ const char *path; /**< Path to kdbus file */
int fd; /**< File descriptor */
void *mmap_ptr; /**< Mapped memory where kdbus (kernel) writes
* messages incoming to us.
}
kdbus_t *
-_kdbus_new ()
+_kdbus_new (const char *path)
{
- return dbus_new (kdbus_t, 1);
+ kdbus_t *kdbus = dbus_new (kdbus_t, 1);
+ if (NULL != kdbus)
+ {
+ kdbus->path = _dbus_strdup(path);
+ if (NULL == kdbus->path)
+ {
+ dbus_free (kdbus);
+ kdbus = NULL;
+ }
+ }
+ return kdbus;
}
void
_kdbus_free (kdbus_t *kdbus)
{
+ dbus_free ((char*)kdbus->path);
dbus_free (kdbus);
}
* Opens a connection to the kdbus bus
*
* @param kdbus kdbus object
- * @param path the path to kdbus bus
* @returns 0 on success, -errno on failure
*/
int
-_kdbus_open (kdbus_t *kdbus, const char *path)
+_kdbus_open (kdbus_t *kdbus)
{
- int fd = open (path, O_RDWR|O_CLOEXEC|O_NONBLOCK);
+ int fd = open (kdbus->path, O_RDWR|O_CLOEXEC|O_NONBLOCK);
if (-1 == fd)
return -errno;
return 0;
}
+const char *
+_kdbus_get_path (kdbus_t *kdbus)
+{
+ return kdbus->path;
+}
+
int
_kdbus_get_fd (kdbus_t *kdbus)
{
typedef __u64 kdbus_bloom_data_t;
-kdbus_t * _kdbus_new (void);
+kdbus_t * _kdbus_new (const char *path);
void _kdbus_free (kdbus_t *kdbus);
-int _kdbus_open (kdbus_t *kdbus, const char *path);
+int _kdbus_open (kdbus_t *kdbus);
int _kdbus_close (kdbus_t *kdbus);
+const char *_kdbus_get_path (kdbus_t *kdbus);
int _kdbus_get_fd (kdbus_t *kdbus);
__u64 _kdbus_get_id (kdbus_t *kdbus);
char *_kdbus_get_bus_id (kdbus_t *kdbus);