Commit 188084a8 authored by Jens Georg's avatar Jens Georg
Browse files

Use unix CM as fall-back if netlink isn't there

Sometimes it might happen that netlink sockets aren't available on
runtime (QEmu for example).
parent 1c515b96
......@@ -356,15 +356,19 @@ gupnp_context_manager_create (guint port)
impl_type = GUPNP_TYPE_CONNMAN_MANAGER;
#endif
if (impl_type == G_TYPE_INVALID)
if (impl_type == G_TYPE_INVALID) {
/* Either user requested us to use the Linux CM explicitly or we
* are using one of the DBus managers but it's not available, so we
* fall-back to it. */
#if defined (USE_NETLINK) || defined (HAVE_LINUX_RTNETLINK_H)
impl_type = GUPNP_TYPE_LINUX_CONTEXT_MANAGER;
if (gupnp_linux_context_manager_is_available ())
impl_type = GUPNP_TYPE_LINUX_CONTEXT_MANAGER;
else
impl_type = GUPNP_TYPE_UNIX_CONTEXT_MANAGER;
#else
impl_type = GUPNP_TYPE_UNIX_CONTEXT_MANAGER;
#endif
}
#endif /* G_OS_WIN32 */
impl = g_object_new (impl_type,
"port", port,
......
......@@ -686,6 +686,21 @@ create_netlink_socket (GUPnPLinuxContextManager *self, GError **error)
return TRUE;
}
gboolean
gupnp_linux_context_manager_is_available (void)
{
int fd = -1;
fd = socket (PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
if (fd == -1)
return FALSE;
close (fd);
return TRUE;
}
static void
gupnp_linux_context_manager_init (GUPnPLinuxContextManager *self)
{
......
......@@ -68,6 +68,8 @@ typedef struct {
void (* _gupnp_reserved4) (void);
} GUPnPLinuxContextManagerClass;
G_GNUC_INTERNAL gboolean gupnp_linux_context_manager_is_available (void);
G_END_DECLS
#endif /* __GUPNP_LINUX_CONTEXT_MANAGER_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment