diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2017-02-15 15:17:00 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2017-02-23 09:53:56 +0100 |
commit | f4cc493426df00f2ec6a768f6719826424dd5e73 (patch) | |
tree | 7a7ff58dacd711661d6a22d1560dec095a0f102f /src/qmi-firmware-update | |
parent | 5a7d20a6a23961f316e1195050fa09bab97a52d3 (diff) | |
download | external_libqmi-f4cc493426df00f2ec6a768f6719826424dd5e73.zip external_libqmi-f4cc493426df00f2ec6a768f6719826424dd5e73.tar.gz external_libqmi-f4cc493426df00f2ec6a768f6719826424dd5e73.tar.bz2 |
qmi-firmware-update: new optional runtime check to see if MM running
Enabled by default, may be disabled using --without-mm-runtime-check
during configure.
Diffstat (limited to 'src/qmi-firmware-update')
-rw-r--r-- | src/qmi-firmware-update/qfu-main.c | 40 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-utils.c | 46 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-utils.h | 9 |
3 files changed, 94 insertions, 1 deletions
diff --git a/src/qmi-firmware-update/qfu-main.c b/src/qmi-firmware-update/qfu-main.c index 7d53cc9..2ecdca6 100644 --- a/src/qmi-firmware-update/qfu-main.c +++ b/src/qmi-firmware-update/qfu-main.c @@ -33,6 +33,7 @@ #include "qfu-operation.h" #include "qfu-device-selection.h" #include "qfu-udev-helpers.h" +#include "qfu-utils.h" #define PROGRAM_NAME "qmi-firmware-update" #define PROGRAM_VERSION PACKAGE_VERSION @@ -50,6 +51,10 @@ static guint16 pid; static gchar *cdc_wdm_str; static gchar *tty_str; +#if defined WITH_MM_RUNTIME_CHECK +static gboolean ignore_mm_runtime_check_flag; +#endif + #if defined WITH_UDEV /* Update */ static gboolean action_update_flag; @@ -287,6 +292,12 @@ static GOptionEntry context_main_entries[] = { "Open a cdc-wdm device in either QMI or MBIM mode (default)", NULL }, +#if defined WITH_MM_RUNTIME_CHECK + { "ignore-mm-runtime-check", 0, 0, G_OPTION_ARG_NONE, &ignore_mm_runtime_check_flag, + "Ignore ModemManager runtime check", + NULL + }, +#endif { "verbose", 'v', 0, G_OPTION_ARG_NONE, &stdout_verbose_flag, "Run action with verbose messages in standard output, including the debug ones.", NULL @@ -595,7 +606,6 @@ int main (int argc, char **argv) /* Initialize logging */ qfu_log_init (stdout_verbose_flag, stdout_silent_flag, verbose_log_str); - /* Total actions */ n_actions = (action_verify_flag + action_update_qdl_flag + action_reset_flag); /* Actions that require images specified */ @@ -640,6 +650,34 @@ int main (int argc, char **argv) g_error_free (error); goto out; } + +#if defined WITH_MM_RUNTIME_CHECK + /* For all those actions that require a device, we will be doing MM runtime checks */ + if (!ignore_mm_runtime_check_flag) { + gboolean mm_running; + gboolean abort_needed = FALSE; + + if (!qfu_utils_modemmanager_running (&mm_running, &error)) { + g_printerr ("error: couldn't check if ModemManager running: %s\n", error->message); + g_error_free (error); + abort_needed = TRUE; + } else if (mm_running) { + g_printerr ("error: ModemManager is running: cannot perform firmware upgrade operation at the same time\n"); + abort_needed = TRUE; + } + + if (abort_needed) { + g_printerr ("\n" + "Note: in order to do a clean firmware upgrade, ModemManager must NOT be running;\n" + "please stop it and retry. On a 'systemd' based system this may be done as follows:\n" + " # systemctl stop ModemManager\n" + "\n" + "You can also ignore this runtime check (at your own risk) using --ignore-mm-runtime-check.\n" + "\n"); + goto out; + } + } +#endif } /* Validate device open flags */ diff --git a/src/qmi-firmware-update/qfu-utils.c b/src/qmi-firmware-update/qfu-utils.c index 2667fbf..9109987 100644 --- a/src/qmi-firmware-update/qfu-utils.c +++ b/src/qmi-firmware-update/qfu-utils.c @@ -714,3 +714,49 @@ qfu_utils_power_cycle (QmiClientDms *qmi_client, power_cycle_step (task); } + +/******************************************************************************/ + +#if defined WITH_MM_RUNTIME_CHECK + +gboolean +qfu_utils_modemmanager_running (gboolean *mm_running, + GError **error) +{ + GDBusConnection *connection; + GVariant *response; + GError *inner_error = NULL; + + g_assert (mm_running); + + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); + if (!connection) { + g_prefix_error (error, "Couldn't get system bus: "); + return FALSE; + } + + response = g_dbus_connection_call_sync (connection, + "org.freedesktop.ModemManager1", + "/org/freedesktop/ModemManager1", + "org.freedesktop.DBus.Peer", + "Ping", + NULL, + NULL, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, + NULL, + &inner_error); + if (!response) { + g_debug ("[qfu-utils] couldn't ping ModemManager: %s", inner_error->message); + g_error_free (inner_error); + *mm_running = FALSE; + } else { + *mm_running = TRUE; + g_variant_unref (response); + } + + g_object_unref (connection); + return TRUE; +} + +#endif diff --git a/src/qmi-firmware-update/qfu-utils.h b/src/qmi-firmware-update/qfu-utils.h index 1490053..3444db1 100644 --- a/src/qmi-firmware-update/qfu-utils.h +++ b/src/qmi-firmware-update/qfu-utils.h @@ -23,6 +23,8 @@ #ifndef QFU_UTILS_H #define QFU_UTILS_H +#include "config.h" + #include <glib.h> #include <gio/gio.h> #include <libqmi-glib.h> @@ -70,6 +72,13 @@ gboolean qfu_utils_power_cycle_finish (QmiClientDms *qmi_client, GAsyncResult *res, GError **error); +#if defined WITH_MM_RUNTIME_CHECK + +gboolean qfu_utils_modemmanager_running (gboolean *mm_running, + GError **error); + +#endif + G_END_DECLS #endif /* QFU_UTILS_H */ |