[gupnp] Use unix CM as fall-back if netlink isn't there
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp] Use unix CM as fall-back if netlink isn't there
- Date: Wed, 29 May 2013 13:36:19 +0000 (UTC)
commit 188084a8e847ff60d8006a45f1687758be1350b3
Author: Jens Georg <mail jensge org>
Date: Wed May 29 12:30:21 2013 +0200
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).
libgupnp/gupnp-context-manager.c | 8 ++++++--
libgupnp/gupnp-linux-context-manager.c | 15 +++++++++++++++
libgupnp/gupnp-linux-context-manager.h | 2 ++
3 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/libgupnp/gupnp-context-manager.c b/libgupnp/gupnp-context-manager.c
index e230877..d667ad6 100644
--- a/libgupnp/gupnp-context-manager.c
+++ b/libgupnp/gupnp-context-manager.c
@@ -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,
diff --git a/libgupnp/gupnp-linux-context-manager.c b/libgupnp/gupnp-linux-context-manager.c
index a5d1c46..51c022c 100644
--- a/libgupnp/gupnp-linux-context-manager.c
+++ b/libgupnp/gupnp-linux-context-manager.c
@@ -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)
{
diff --git a/libgupnp/gupnp-linux-context-manager.h b/libgupnp/gupnp-linux-context-manager.h
index de7fa6f..76b1f80 100644
--- a/libgupnp/gupnp-linux-context-manager.h
+++ b/libgupnp/gupnp-linux-context-manager.h
@@ -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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]