[gnome-initial-setup/wip/pwithnall/misc-fixes: 14/70] driver: track whether the current session is a live boot
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/wip/pwithnall/misc-fixes: 14/70] driver: track whether the current session is a live boot
- Date: Fri, 11 Sep 2020 13:29:09 +0000 (UTC)
commit 7dbdd381bce6a2f4d4a9a6987847b79236aa1f3f
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Sep 21 02:24:34 2016 -0300
driver: track whether the current session is a live boot
As a preparation to future changes, this commit makes GisDriver
track whether we're running on a live session or not by checking
if /proc/cmdline contains the "endless.live_boot" parameter, using code
lifted from eos-installer.
Also, add show_window() function, so we can show the initial setup
with an error dialog if something goes terribly wrong with the installer.
For testing purposes, this respects the EI_FORCE_LIVE_BOOT_UUID
environment variable which is also used by eos-installer, so that you
don't have to patch your local copy or a live image. Using the same
variable as eos-installer allows testing the full live FBE flow.
https://phabricator.endlessm.com/T12547
gnome-initial-setup/gis-driver.c | 76 ++++++++++++++++++++++++++++++++++++++++
gnome-initial-setup/gis-driver.h | 4 +++
2 files changed, 80 insertions(+)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index 2332aee0..4f160bd8 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -60,6 +60,7 @@ static guint signals[LAST_SIGNAL];
typedef enum {
PROP_MODE = 1,
+ PROP_LIVE_SESSION,
PROP_USERNAME,
PROP_SMALL_SCREEN,
PROP_PARENTAL_CONTROLS_ENABLED,
@@ -91,6 +92,8 @@ struct _GisDriverPrivate {
GdkPixbuf *avatar; /* (owned) (nullable) */
+ gboolean is_live_session;
+
GisDriverMode mode;
UmAccountMode account_mode;
gboolean small_screen;
@@ -104,6 +107,53 @@ typedef struct _GisDriverPrivate GisDriverPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(GisDriver, gis_driver, GTK_TYPE_APPLICATION)
+/* Should be kept in sync with eos-installer */
+static gboolean
+check_for_live_boot (gchar **uuid)
+{
+ const gchar *force = NULL;
+ GError *error = NULL;
+ g_autofree gchar *cmdline = NULL;
+ gboolean live_boot = FALSE;
+ g_autoptr(GRegex) reg = NULL;
+ g_autoptr(GMatchInfo) info = NULL;
+
+ g_return_val_if_fail (uuid != NULL, FALSE);
+
+ force = g_getenv ("EI_FORCE_LIVE_BOOT_UUID");
+ if (force != NULL && *force != '\0')
+ {
+ *uuid = g_strdup (force);
+ return TRUE;
+ }
+
+ if (!g_file_get_contents ("/proc/cmdline", &cmdline, NULL, &error))
+ {
+ g_error_free (error);
+ return FALSE;
+ }
+
+ live_boot = g_regex_match_simple ("\\bendless\\.live_boot\\b", cmdline, 0, 0);
+
+ reg = g_regex_new ("\\bendless\\.image\\.device=UUID=([^\\s]*)", 0, 0, NULL);
+ g_regex_match (reg, cmdline, 0, &info);
+ if (g_match_info_matches (info))
+ *uuid = g_match_info_fetch (info, 1);
+
+ return live_boot;
+}
+
+static gboolean
+running_live_session (void)
+{
+ g_autofree gchar *uuid = NULL;
+
+ if (!check_for_live_boot (&uuid))
+ return FALSE;
+
+ return TRUE;
+}
+
static void
gis_driver_dispose (GObject *object)
{
@@ -496,6 +546,14 @@ gis_driver_add_page (GisDriver *driver,
gis_assistant_add_page (priv->assistant, page);
}
+void
+gis_driver_show_window (GisDriver *driver)
+{
+ GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
+
+ gtk_window_present (priv->main_window);
+}
+
void
gis_driver_hide_window (GisDriver *driver)
{
@@ -627,6 +685,13 @@ gis_driver_get_mode (GisDriver *driver)
return priv->mode;
}
+gboolean
+gis_driver_is_live_session (GisDriver *driver)
+{
+ GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
+ return priv->is_live_session;
+}
+
gboolean
gis_driver_is_small_screen (GisDriver *driver)
{
@@ -656,6 +721,9 @@ gis_driver_get_property (GObject *object,
GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
switch ((GisDriverProperty) prop_id)
{
+ case PROP_LIVE_SESSION:
+ g_value_set_boolean (value, priv->is_live_session);
+ break;
case PROP_MODE:
g_value_set_enum (value, priv->mode);
break;
@@ -910,6 +978,9 @@ gis_driver_startup (GApplication *app)
gtk_widget_show (GTK_WIDGET (priv->assistant));
+ priv->is_live_session = running_live_session ();
+ g_object_notify_by_pspec (G_OBJECT (driver), obj_props[PROP_LIVE_SESSION]);
+
gis_driver_set_user_language (driver, setlocale (LC_MESSAGES, NULL), FALSE);
prepare_main_window (driver);
@@ -962,6 +1033,11 @@ gis_driver_class_init (GisDriverClass *klass)
NULL, NULL, NULL,
G_TYPE_NONE, 0);
+ obj_props[PROP_LIVE_SESSION] =
+ g_param_spec_boolean ("live-session", "", "",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
obj_props[PROP_MODE] =
g_param_spec_enum ("mode", "", "",
GIS_TYPE_DRIVER_MODE,
diff --git a/gnome-initial-setup/gis-driver.h b/gnome-initial-setup/gis-driver.h
index a8f1922b..801d6f60 100644
--- a/gnome-initial-setup/gis-driver.h
+++ b/gnome-initial-setup/gis-driver.h
@@ -117,11 +117,15 @@ gboolean gis_driver_get_gdm_objects (GisDriver *driver,
GisDriverMode gis_driver_get_mode (GisDriver *driver);
+gboolean gis_driver_is_live_session (GisDriver *driver);
+
gboolean gis_driver_is_small_screen (GisDriver *driver);
void gis_driver_add_page (GisDriver *driver,
GisPage *page);
+void gis_driver_show_window (GisDriver *driver);
+
void gis_driver_hide_window (GisDriver *driver);
gboolean gis_driver_save_data (GisDriver *driver,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]