aboutsummaryrefslogtreecommitdiff
path: root/cli/mmcli-manager.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-09-28 19:46:12 +0200
committerAleksander Morgado <aleksander@aleksander.es>2016-09-29 15:43:05 +0200
commit58c955f5f23e874e4f8c2a4b389e46c0775e7f07 (patch)
tree568f004df95780b881d22284d642f93e5673221c /cli/mmcli-manager.c
parentae9ede926a1747216b54e22398edde203ec9a03c (diff)
core: allow building and running without udev
Instead of relying on the udev daemon and GUDev to manage the devices reported by the kernel, we can now run ModemManager relying solely on the kernel events reported via the new ReportKernelEvent() API. Therefore, the '--no-auto-scan' option is implicit for the ModemManager daemon when udev is disabled in the build. Additionally, a new custom implementation of the kernel device object is provided, which uses sysfs to load the properties and attributes required in each kernel device, instead of using a GUdevDevice. The udev rule files are kept in place, and a simple custom parser is provided which preloads all rules in memory once and then applies them to the different kernel objects reported via ReportKernelEvent(), e.g. to set port type hints. A simple unit test setup is prepared to validate the udev rules during the `check' Makefile target.
Diffstat (limited to 'cli/mmcli-manager.c')
-rw-r--r--cli/mmcli-manager.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/cli/mmcli-manager.c b/cli/mmcli-manager.c
index 4e078f17..24ecc4eb 100644
--- a/cli/mmcli-manager.c
+++ b/cli/mmcli-manager.c
@@ -29,7 +29,9 @@
#include <glib.h>
#include <gio/gio.h>
-#include <gudev/gudev.h>
+#if WITH_UDEV
+# include <gudev/gudev.h>
+#endif
#define _LIBMM_INSIDE_MMCLI
#include "libmm-glib.h"
@@ -41,7 +43,9 @@
typedef struct {
MMManager *manager;
GCancellable *cancellable;
+#if WITH_UDEV
GUdevClient *udev;
+#endif
} Context;
static Context *ctx;
@@ -51,7 +55,10 @@ static gboolean monitor_modems_flag;
static gboolean scan_modems_flag;
static gchar *set_logging_str;
static gchar *report_kernel_event_str;
+
+#if WITH_UDEV
static gboolean report_kernel_event_auto_scan;
+#endif
static GOptionEntry entries[] = {
{ "set-logging", 'G', 0, G_OPTION_ARG_STRING, &set_logging_str,
@@ -74,10 +81,12 @@ static GOptionEntry entries[] = {
"Report kernel event",
"[\"key=value,...\"]"
},
+#if WITH_UDEV
{ "report-kernel-event-auto-scan", 0, 0, G_OPTION_ARG_NONE, &report_kernel_event_auto_scan,
"Automatically report kernel events based on udev notifications",
NULL
},
+#endif
{ NULL }
};
@@ -110,8 +119,11 @@ mmcli_manager_options_enabled (void)
monitor_modems_flag +
scan_modems_flag +
!!set_logging_str +
- !!report_kernel_event_str +
- report_kernel_event_auto_scan);
+ !!report_kernel_event_str);
+
+#if WITH_UDEV
+ n_actions += report_kernel_event_auto_scan;
+#endif
if (n_actions > 1) {
g_printerr ("error: too many manager actions requested\n");
@@ -121,8 +133,10 @@ mmcli_manager_options_enabled (void)
if (monitor_modems_flag)
mmcli_force_async_operation ();
+#if WITH_UDEV
if (report_kernel_event_auto_scan)
mmcli_force_async_operation ();
+#endif
checked = TRUE;
return !!n_actions;
@@ -134,8 +148,11 @@ context_free (Context *ctx)
if (!ctx)
return;
+#if WITH_UDEV
if (ctx->udev)
g_object_unref (ctx->udev);
+#endif
+
if (ctx->manager)
g_object_unref (ctx->manager);
if (ctx->cancellable)
@@ -308,6 +325,8 @@ cancelled (GCancellable *cancellable)
mmcli_async_operation_done ();
}
+#if WITH_UDEV
+
static void
handle_uevent (GUdevClient *client,
const char *action,
@@ -324,6 +343,8 @@ handle_uevent (GUdevClient *client,
g_object_unref (properties);
}
+#endif
+
static void
get_manager_ready (GObject *source,
GAsyncResult *result,
@@ -367,6 +388,7 @@ get_manager_ready (GObject *source,
return;
}
+#if WITH_UDEV
if (report_kernel_event_auto_scan) {
const gchar *subsys[] = { "tty", "usbmisc", "net", NULL };
guint i;
@@ -400,6 +422,7 @@ get_manager_ready (GObject *source,
NULL);
return;
}
+#endif
/* Request to monitor modems? */
if (monitor_modems_flag) {
@@ -457,10 +480,12 @@ mmcli_manager_run_synchronous (GDBusConnection *connection)
exit (EXIT_FAILURE);
}
+#if WITH_UDEV
if (report_kernel_event_auto_scan) {
g_printerr ("error: monitoring udev events cannot be done synchronously\n");
exit (EXIT_FAILURE);
}
+#endif
/* Initialize context */
ctx = g_new0 (Context, 1);