[PATCH 06/10] main: new '--no-auto-scan' to skip udev monitoring even if udev support compiled

Aleksander Morgado aleksander at aleksander.es
Sat Aug 6 13:03:34 UTC 2016


When udev support is available, running with '--no-auto-scan' will fully disable
the udev monitoring and leave us with the possibility of reporting kernel events
with mmcli. Also, if auto-scan is enabled (the default), kernel event reporting
will be forbidden. We'll never be able to merge both methods, as it doesn't make
sense. Either we rely on udev monitoring, or we rely on kernel events reported
via DBus.

When not using udev, '--no-auto-scan' is implicit; i.e. there is no automatic
scan supported.
---
 .../tests/org.freedesktop.ModemManager1.service.in |  2 +-
 src/main.c                                         |  2 +-
 src/mm-base-manager.c                              | 31 +++++++---------------
 src/mm-context.c                                   | 26 ++++++++++++------
 src/mm-context.h                                   |  2 +-
 5 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/data/tests/org.freedesktop.ModemManager1.service.in b/data/tests/org.freedesktop.ModemManager1.service.in
index ee8bdea..d7c1a00 100644
--- a/data/tests/org.freedesktop.ModemManager1.service.in
+++ b/data/tests/org.freedesktop.ModemManager1.service.in
@@ -2,4 +2,4 @@
 
 [D-BUS Service]
 Name=org.freedesktop.ModemManager1
-Exec=@abs_top_builddir@/src/ModemManager --test-session --test-no-auto-scan --test-enable --test-plugin-dir="@abs_top_builddir@/plugins/.libs" --debug
+Exec=@abs_top_builddir@/src/ModemManager --test-session --no-auto-scan --test-enable --test-plugin-dir="@abs_top_builddir@/plugins/.libs" --debug
diff --git a/src/main.c b/src/main.c
index 8a3ebab..5e5628c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -86,7 +86,7 @@ bus_acquired_cb (GDBusConnection *connection,
     g_assert (!manager);
     manager = mm_base_manager_new (connection,
                                    mm_context_get_test_plugin_dir (),
-                                   !mm_context_get_test_no_auto_scan (),
+                                   !mm_context_get_no_auto_scan (),
                                    mm_context_get_test_enable (),
                                    &error);
     if (!manager) {
diff --git a/src/mm-base-manager.c b/src/mm-base-manager.c
index 0c12e10..528c5e9 100644
--- a/src/mm-base-manager.c
+++ b/src/mm-base-manager.c
@@ -26,9 +26,8 @@
 
 #if WITH_UDEV
 # include "mm-kernel-device-udev.h"
-#else
-# include "mm-kernel-device-generic.h"
 #endif
+#include "mm-kernel-device-generic.h"
 
 #include <ModemManager.h>
 #include <mm-errors-types.h>
@@ -656,8 +655,6 @@ handle_scan_devices (MmGdbusOrgFreedesktopModemManager1 *manager,
 
 /*****************************************************************************/
 
-#if !WITH_UDEV
-
 typedef struct {
     MMBaseManager *self;
     GDBusMethodInvocation *invocation;
@@ -686,6 +683,15 @@ report_kernel_event_auth_ready (MMAuthProvider           *authp,
     if (!mm_auth_provider_authorize_finish (authp, res, &error))
         goto out;
 
+#if WITH_UDEV
+    if (ctx->self->priv->auto_scan) {
+        error = g_error_new_literal (MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
+                                     "Cannot report kernel event: "
+                                     "udev monitoring already in place");
+        goto out;
+    }
+#endif
+
     properties = mm_kernel_event_properties_new_from_dictionary (ctx->dictionary, &error);
     if (!properties)
         goto out;
@@ -764,23 +770,6 @@ handle_report_kernel_event (MmGdbusOrgFreedesktopModemManager1 *manager,
     return TRUE;
 }
 
-#else
-
-static gboolean
-handle_report_kernel_event (MmGdbusOrgFreedesktopModemManager1 *manager,
-                            GDBusMethodInvocation *invocation,
-                            GVariant *dictionary)
-{
-    g_dbus_method_invocation_return_error (invocation,
-                                           MM_CORE_ERROR,
-                                           MM_CORE_ERROR_UNSUPPORTED,
-                                           "Cannot report kernel event: "
-                                           "udev monitoring already in place");
-    return TRUE;
-}
-
-#endif
-
 /*****************************************************************************/
 /* Test profile setup */
 
diff --git a/src/mm-context.c b/src/mm-context.c
index df8d07c..b6af1a3 100644
--- a/src/mm-context.c
+++ b/src/mm-context.c
@@ -13,6 +13,7 @@
  * Copyright (C) 2012 Aleksander Morgado <aleksander at gnu.org>
  */
 
+#include <config.h>
 #include <stdlib.h>
 
 #include "mm-context.h"
@@ -27,6 +28,10 @@ static const gchar *log_file;
 static gboolean show_ts;
 static gboolean rel_ts;
 
+#if WITH_UDEV
+static gboolean no_auto_scan;
+#endif
+
 static const GOptionEntry entries[] = {
     { "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag, "Print version", NULL },
     { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Run with extended debugging capabilities", NULL },
@@ -34,6 +39,9 @@ static const GOptionEntry entries[] = {
     { "log-file", 0, 0, G_OPTION_ARG_FILENAME, &log_file, "Path to log file", "[PATH]" },
     { "timestamps", 0, 0, G_OPTION_ARG_NONE, &show_ts, "Show timestamps in log output", NULL },
     { "relative-timestamps", 0, 0, G_OPTION_ARG_NONE, &rel_ts, "Use relative timestamps (from MM start)", NULL },
+#if WITH_UDEV
+    { "no-auto-scan", 0, 0, G_OPTION_ARG_NONE, &no_auto_scan, "Don't auto-scan looking for devices", NULL },
+#endif
     { NULL }
 };
 
@@ -67,17 +75,25 @@ mm_context_get_relative_timestamps (void)
     return rel_ts;
 }
 
+gboolean
+mm_context_get_no_auto_scan (void)
+{
+#if WITH_UDEV
+    return no_auto_scan;
+#else
+    return TRUE;
+#endif
+}
+
 /*****************************************************************************/
 /* Test context */
 
 static gboolean test_session;
-static gboolean test_no_auto_scan;
 static gboolean test_enable;
 static gchar *test_plugin_dir;
 
 static const GOptionEntry test_entries[] = {
     { "test-session", 0, 0, G_OPTION_ARG_NONE, &test_session, "Run in session DBus", NULL },
-    { "test-no-auto-scan", 0, 0, G_OPTION_ARG_NONE, &test_no_auto_scan, "Don't auto-scan looking for devices", NULL },
     { "test-enable", 0, 0, G_OPTION_ARG_NONE, &test_enable, "Enable the Test interface in the daemon", NULL },
     { "test-plugin-dir", 0, 0, G_OPTION_ARG_FILENAME, &test_plugin_dir, "Path to look for plugins", "[PATH]" },
     { NULL }
@@ -104,12 +120,6 @@ mm_context_get_test_session (void)
 }
 
 gboolean
-mm_context_get_test_no_auto_scan (void)
-{
-    return test_no_auto_scan;
-}
-
-gboolean
 mm_context_get_test_enable (void)
 {
     return test_enable;
diff --git a/src/mm-context.h b/src/mm-context.h
index 6627a60..b2ba07f 100644
--- a/src/mm-context.h
+++ b/src/mm-context.h
@@ -31,10 +31,10 @@ const gchar *mm_context_get_log_level           (void);
 const gchar *mm_context_get_log_file            (void);
 gboolean     mm_context_get_timestamps          (void);
 gboolean     mm_context_get_relative_timestamps (void);
+gboolean     mm_context_get_no_auto_scan        (void);
 
 /* Testing support */
 gboolean     mm_context_get_test_session        (void);
-gboolean     mm_context_get_test_no_auto_scan   (void);
 gboolean     mm_context_get_test_enable         (void);
 const gchar *mm_context_get_test_plugin_dir     (void);
 
-- 
2.9.0



More information about the ModemManager-devel mailing list