[PATCH 03/10] build: make gudev support optional
Aleksander Morgado
aleksander at aleksander.es
Sat Aug 6 13:03:31 UTC 2016
ModemManager won't be functional if gudev isn't used, but only for now.
---
configure.ac | 30 ++++++--
plugins/huawei/mm-broadband-modem-huawei.c | 61 ++++++++-------
src/Makefile.am | 5 ++
src/mm-base-manager.c | 118 +++++++++++++++++++----------
src/mm-base-modem.c | 1 -
test/Makefile.am | 4 +
6 files changed, 145 insertions(+), 74 deletions(-)
diff --git a/configure.ac b/configure.ac
index dd3111d..c74d015 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,7 +95,6 @@ dnl Build dependencies
dnl
GLIB_MIN_VERSION=2.36.0
-GUDEV_MIN_VERSION=147
PKG_CHECK_MODULES(MM,
glib-2.0 >= $GLIB_MIN_VERSION
@@ -121,10 +120,6 @@ PKG_CHECK_MODULES(MMCLI,
AC_SUBST(MMCLI_CFLAGS)
AC_SUBST(MMCLI_LIBS)
-PKG_CHECK_MODULES(GUDEV, gudev-1.0 >= $GUDEV_MIN_VERSION)
-AC_SUBST(GUDEV_CFLAGS)
-AC_SUBST(GUDEV_LIBS)
-
dnl Some required utilities
GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
AC_SUBST(GLIB_MKENUMS)
@@ -183,6 +178,30 @@ fi
AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$SYSTEMD_UNIT_DIR" -a "$SYSTEMD_UNIT_DIR" != xno ])
dnl-----------------------------------------------------------------------------
+dnl udev support (enabled by default)
+dnl
+
+GUDEV_VERSION=147
+
+AC_ARG_WITH(udev, AS_HELP_STRING([--without-udev], [Build without udev support]), [], [with_udev=yes])
+AM_CONDITIONAL(WITH_UDEV, test "x$with_udev" = "xyes")
+case $with_udev in
+ yes)
+ PKG_CHECK_MODULES(GUDEV, [gudev-1.0 >= $GUDEV_VERSION], [have_gudev=yes],[have_gudev=no])
+ if test "x$have_gudev" = "xno"; then
+ AC_MSG_ERROR([Couldn't find gudev >= $GUDEV_VERSION. Install it, or otherwise configure using --without-udev to disable udev support.])
+ else
+ AC_DEFINE(WITH_UDEV, 1, [Define if you want udev support])
+ AC_SUBST(GUDEV_CFLAGS)
+ AC_SUBST(GUDEV_LIBS)
+ fi
+ ;;
+ *)
+ with_udev=no
+ ;;
+esac
+
+dnl-----------------------------------------------------------------------------
dnl Suspend/resume support
dnl
@@ -396,6 +415,7 @@ echo "
systemd unit directory: ${with_systemdsystemunitdir}
Features:
+ udev support: ${with_udev}
policykit support: ${with_polkit}
mbim support: ${with_mbim}
qmi support: ${with_qmi}
diff --git a/plugins/huawei/mm-broadband-modem-huawei.c b/plugins/huawei/mm-broadband-modem-huawei.c
index c650901..aa88786 100644
--- a/plugins/huawei/mm-broadband-modem-huawei.c
+++ b/plugins/huawei/mm-broadband-modem-huawei.c
@@ -26,7 +26,10 @@
#include <unistd.h>
#include <ctype.h>
#include <time.h>
-#include <gudev/gudev.h>
+
+#if WITH_UDEV
+# include <gudev/gudev.h>
+#endif
#include <ModemManager.h>
#define _LIBMM_INSIDE_MM
@@ -2204,44 +2207,48 @@ static void
ensure_ndisdup_support_checked (MMBroadbandModemHuawei *self,
MMPort *port)
{
- GUdevClient *client;
- GUdevDevice *data_device;
-
/* Check NDISDUP support the first time we need it */
if (self->priv->ndisdup_support != FEATURE_SUPPORT_UNKNOWN)
return;
- /* First, check for devices which support NDISDUP on any AT port. These
- * devices are tagged by udev */
- client = g_udev_client_new (NULL);
- data_device = (g_udev_client_query_by_subsystem_and_name (
+#if WITH_UDEV
+ {
+ GUdevClient *client;
+ GUdevDevice *data_device;
+
+ /* First, check for devices which support NDISDUP on any AT port. These
+ * devices are tagged by udev */
+ client = g_udev_client_new (NULL);
+ data_device = (g_udev_client_query_by_subsystem_and_name (
client,
"net",
mm_port_get_device (port)));
- if (data_device && g_udev_device_get_property_as_boolean (data_device, "ID_MM_HUAWEI_NDISDUP_SUPPORTED")) {
- mm_dbg ("This device (%s) can support ndisdup feature", mm_port_get_device (port));
- self->priv->ndisdup_support = FEATURE_SUPPORTED;
- goto out;
- }
+ if (data_device && g_udev_device_get_property_as_boolean (data_device, "ID_MM_HUAWEI_NDISDUP_SUPPORTED")) {
+ mm_dbg ("This device (%s) can support ndisdup feature", mm_port_get_device (port));
+ self->priv->ndisdup_support = FEATURE_SUPPORTED;
+ }
+ /* Then, look for devices which have both a net port and a cdc-wdm
+ * AT-capable port. We assume that these devices allow NDISDUP only
+ * when issued in the cdc-wdm port. */
+ else if (peek_port_at_for_data (self, port)) {
+ mm_dbg ("This device (%s) can support ndisdup feature on non-serial AT port",
+ mm_port_get_device (port));
+ self->priv->ndisdup_support = FEATURE_SUPPORTED;
+ }
- /* Then, look for devices which have both a net port and a cdc-wdm
- * AT-capable port. We assume that these devices allow NDISDUP only
- * when issued in the cdc-wdm port. */
- if (peek_port_at_for_data (self, port)) {
- mm_dbg ("This device (%s) can support ndisdup feature on non-serial AT port",
- mm_port_get_device (port));
- self->priv->ndisdup_support = FEATURE_SUPPORTED;
- goto out;
+ if (data_device)
+ g_object_unref (data_device);
+ g_object_unref (client);
}
+#else
+ mm_warn ("NDISDUP support check not implemented");
+#endif
+
+ if (self->priv->ndisdup_support != FEATURE_SUPPORT_UNKNOWN)
+ return;
mm_dbg ("This device (%s) can not support ndisdup feature", mm_port_get_device (port));
self->priv->ndisdup_support = FEATURE_NOT_SUPPORTED;
-
-out:
- if (data_device)
- g_object_unref (data_device);
- if (client)
- g_object_unref (client);
}
static void
diff --git a/src/Makefile.am b/src/Makefile.am
index 911b802..f64f1c1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -175,9 +175,14 @@ noinst_LTLIBRARIES += libkerneldevice.la
libkerneldevice_la_SOURCES = \
kerneldevice/mm-kernel-device.h \
kerneldevice/mm-kernel-device.c \
+ $(NULL)
+
+if WITH_UDEV
+libkerneldevice_la_SOURCES += \
kerneldevice/mm-kernel-device-udev.h \
kerneldevice/mm-kernel-device-udev.c \
$(NULL)
+endif
################################################################################
# ModemManager daemon
diff --git a/src/mm-base-manager.c b/src/mm-base-manager.c
index 9da3896..85f66a8 100644
--- a/src/mm-base-manager.c
+++ b/src/mm-base-manager.c
@@ -17,11 +17,16 @@
* Copyright (C) 2011 - 2016 Aleksander Morgado <aleksander at aleksander.es>
*/
+#include <config.h>
+
#include <string.h>
#include <ctype.h>
#include <gmodule.h>
-#include "mm-kernel-device-udev.h"
+
+#if WITH_UDEV
+# include "mm-kernel-device-udev.h"
+#endif
#include <ModemManager.h>
#include <mm-errors-types.h>
@@ -59,8 +64,6 @@ struct _MMBaseManagerPrivate {
gboolean enable_test;
/* Path to look for plugins */
gchar *plugin_dir;
- /* The UDev client */
- GUdevClient *udev;
/* The authorization provider */
MMAuthProvider *authp;
GCancellable *authp_cancellable;
@@ -73,6 +76,11 @@ struct _MMBaseManagerPrivate {
/* The Test interface support */
MmGdbusTest *test_skeleton;
+
+#if WITH_UDEV
+ /* The UDev client */
+ GUdevClient *udev;
+#endif
};
/*****************************************************************************/
@@ -288,6 +296,8 @@ device_added (MMBaseManager *manager,
mm_device_grab_port (device, port);
}
+#if WITH_UDEV
+
static void
handle_uevent (GUdevClient *client,
const char *action,
@@ -356,58 +366,69 @@ start_device_added (MMBaseManager *self,
g_idle_add ((GSourceFunc)start_device_added_idle, ctx);
}
+#endif
+
void
mm_base_manager_start (MMBaseManager *manager,
- gboolean manual_scan)
+ gboolean manual_scan)
{
- GList *devices, *iter;
-
g_return_if_fail (manager != NULL);
g_return_if_fail (MM_IS_BASE_MANAGER (manager));
if (!manager->priv->auto_scan && !manual_scan)
return;
- mm_dbg ("Starting %s device scan...", manual_scan ? "manual" : "automatic");
+#if WITH_UDEV
+ {
+ GList *devices, *iter;
- devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty");
- for (iter = devices; iter; iter = g_list_next (iter)) {
- start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan);
- g_object_unref (G_OBJECT (iter->data));
- }
- g_list_free (devices);
-
- devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net");
- for (iter = devices; iter; iter = g_list_next (iter)) {
- start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan);
- g_object_unref (G_OBJECT (iter->data));
- }
- g_list_free (devices);
+ mm_dbg ("Starting %s device scan...", manual_scan ? "manual" : "automatic");
- devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usb");
- for (iter = devices; iter; iter = g_list_next (iter)) {
- const gchar *name;
+ devices = g_udev_client_query_by_subsystem (manager->priv->udev, "tty");
+ for (iter = devices; iter; iter = g_list_next (iter)) {
+ start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan);
+ g_object_unref (G_OBJECT (iter->data));
+ }
+ g_list_free (devices);
- name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data));
- if (name && g_str_has_prefix (name, "cdc-wdm"))
+ devices = g_udev_client_query_by_subsystem (manager->priv->udev, "net");
+ for (iter = devices; iter; iter = g_list_next (iter)) {
start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan);
- g_object_unref (G_OBJECT (iter->data));
- }
- g_list_free (devices);
+ g_object_unref (G_OBJECT (iter->data));
+ }
+ g_list_free (devices);
- /* Newer kernels report 'usbmisc' subsystem */
- devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usbmisc");
- for (iter = devices; iter; iter = g_list_next (iter)) {
- const gchar *name;
+ devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usb");
+ for (iter = devices; iter; iter = g_list_next (iter)) {
+ const gchar *name;
- name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data));
- if (name && g_str_has_prefix (name, "cdc-wdm"))
- start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan);
- g_object_unref (G_OBJECT (iter->data));
+ name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data));
+ if (name && g_str_has_prefix (name, "cdc-wdm"))
+ start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan);
+ g_object_unref (G_OBJECT (iter->data));
+ }
+ g_list_free (devices);
+
+ /* Newer kernels report 'usbmisc' subsystem */
+ devices = g_udev_client_query_by_subsystem (manager->priv->udev, "usbmisc");
+ for (iter = devices; iter; iter = g_list_next (iter)) {
+ const gchar *name;
+
+ name = g_udev_device_get_name (G_UDEV_DEVICE (iter->data));
+ if (name && g_str_has_prefix (name, "cdc-wdm"))
+ start_device_added (manager, G_UDEV_DEVICE (iter->data), manual_scan);
+ g_object_unref (G_OBJECT (iter->data));
+ }
+ g_list_free (devices);
+
+ mm_dbg ("Finished device scan...");
}
- g_list_free (devices);
+#else
+ mm_dbg ("Unsupported %s device scan...", manual_scan ? "manual" : "automatic");
- mm_dbg ("Finished device scan...");
+ /* Make compiler happy */
+ device_added (manager, NULL, FALSE, FALSE);
+#endif
}
/*****************************************************************************/
@@ -585,11 +606,17 @@ scan_devices_auth_ready (MMAuthProvider *authp,
if (!mm_auth_provider_authorize_finish (authp, res, &error))
g_dbus_method_invocation_take_error (ctx->invocation, error);
else {
+#if WITH_UDEV
/* Otherwise relaunch device scan */
mm_base_manager_start (MM_BASE_MANAGER (ctx->self), TRUE);
mm_gdbus_org_freedesktop_modem_manager1_complete_scan_devices (
MM_GDBUS_ORG_FREEDESKTOP_MODEM_MANAGER1 (ctx->self),
ctx->invocation);
+#else
+ g_dbus_method_invocation_return_error_literal (
+ ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
+ "Cannot request manual scan of devices: unsupported");
+#endif
}
scan_devices_context_free (ctx);
@@ -777,7 +804,6 @@ static void
mm_base_manager_init (MMBaseManager *manager)
{
MMBaseManagerPrivate *priv;
- const gchar *subsys[5] = { "tty", "net", "usb", "usbmisc", NULL };
/* Setup private data */
manager->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
@@ -791,8 +817,14 @@ mm_base_manager_init (MMBaseManager *manager)
/* Setup internal lists of device objects */
priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- /* Setup UDev client */
- priv->udev = g_udev_client_new (subsys);
+#if WITH_UDEV
+ {
+ const gchar *subsys[5] = { "tty", "net", "usb", "usbmisc", NULL };
+
+ /* Setup UDev client */
+ priv->udev = g_udev_client_new (subsys);
+ }
+#endif
/* By default, enable autoscan */
priv->auto_scan = TRUE;
@@ -821,9 +853,11 @@ initable_init (GInitable *initable,
{
MMBaseManagerPrivate *priv = MM_BASE_MANAGER (initable)->priv;
+#if WITH_UDEV
/* If autoscan enabled, list for udev events */
if (priv->auto_scan)
g_signal_connect (priv->udev, "uevent", G_CALLBACK (handle_uevent), initable);
+#endif
/* Create plugin manager */
priv->plugin_manager = mm_plugin_manager_new (priv->plugin_dir, error);
@@ -868,8 +902,10 @@ finalize (GObject *object)
g_hash_table_destroy (priv->devices);
+#if WITH_UDEV
if (priv->udev)
g_object_unref (priv->udev);
+#endif
if (priv->plugin_manager)
g_object_unref (priv->plugin_manager);
diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c
index 9cd7c5f..aa0c757 100644
--- a/src/mm-base-modem.c
+++ b/src/mm-base-modem.c
@@ -21,7 +21,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <gudev/gudev.h>
#include <ModemManager.h>
#include <mm-errors-types.h>
diff --git a/test/Makefile.am b/test/Makefile.am
index 4f6028b..eaab99c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -6,12 +6,16 @@ EXTRA_DIST =
# lsudev
################################################################################
+if WITH_UDEV
+
noinst_PROGRAMS += lsudev
lsudev_SOURCES = lsudev.c
lsudev_CPPFLAGS = $(GUDEV_CFLAGS)
lsudev_LDADD = $(GUDEV_LIBS)
+endif
+
################################################################################
# mmtty
################################################################################
--
2.9.0
More information about the ModemManager-devel
mailing list