Blame SOURCES/0002-common-Add-API-to-reload-settings-from-disk.patch

4e44f9
From d3e073fa1cd314b344db1ec22f0add2702a6c299 Mon Sep 17 00:00:00 2001
4e44f9
From: Ray Strode <rstrode@redhat.com>
4e44f9
Date: Tue, 15 Feb 2022 14:33:22 -0500
4e44f9
Subject: [PATCH 2/4] common: Add API to reload settings from disk
4e44f9
4e44f9
Ideally we would reread /run/gdm/custom.conf after we've decided
4e44f9
graphics setup is complete.  This is because the file may not
4e44f9
get written out by udev until after GDM is already started and waiting.
4e44f9
4e44f9
As a first step to get there, this commit adds an API for rereading
4e44f9
the file, and changes the SIGHUP handler to use it (instead of
4e44f9
the complete teardown and reinitialization it was doing before).
4e44f9
---
4e44f9
 common/gdm-settings-direct.c |  9 +++++++++
4e44f9
 common/gdm-settings-direct.h |  2 ++
4e44f9
 common/gdm-settings.c        | 14 ++++++++++++--
4e44f9
 common/gdm-settings.h        |  1 +
4e44f9
 daemon/main.c                | 12 ++----------
4e44f9
 5 files changed, 26 insertions(+), 12 deletions(-)
4e44f9
4e44f9
diff --git a/common/gdm-settings-direct.c b/common/gdm-settings-direct.c
4e44f9
index ddb31908..5fbe0326 100644
4e44f9
--- a/common/gdm-settings-direct.c
4e44f9
+++ b/common/gdm-settings-direct.c
4e44f9
@@ -224,35 +224,44 @@ hashify_list (GdmSettingsEntry *entry,
4e44f9
 
4e44f9
 gboolean
4e44f9
 gdm_settings_direct_init (GdmSettings *settings,
4e44f9
                           const char  *file,
4e44f9
                           const char  *root)
4e44f9
 {
4e44f9
         GSList  *list;
4e44f9
 
4e44f9
         g_return_val_if_fail (file != NULL, FALSE);
4e44f9
         g_return_val_if_fail (root != NULL, FALSE);
4e44f9
 
4e44f9
         g_debug ("Settings Direct Init");
4e44f9
         if (schemas != NULL) {
4e44f9
                 g_hash_table_unref (schemas);
4e44f9
                 schemas = NULL;
4e44f9
         }
4e44f9
 
4e44f9
         if (! gdm_settings_parse_schemas (file, root, &list)) {
4e44f9
                 g_warning ("Unable to parse schemas");
4e44f9
                 return FALSE;
4e44f9
         }
4e44f9
 
4e44f9
         schemas = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)gdm_settings_entry_free);
4e44f9
         g_slist_foreach (list, (GFunc)hashify_list, NULL);
4e44f9
 
4e44f9
         settings_object = settings;
4e44f9
 
4e44f9
         return TRUE;
4e44f9
 }
4e44f9
 
4e44f9
+void
4e44f9
+gdm_settings_direct_reload (void)
4e44f9
+{
4e44f9
+    if (!settings_object)
4e44f9
+            return;
4e44f9
+
4e44f9
+    gdm_settings_reload (settings_object);
4e44f9
+}
4e44f9
+
4e44f9
 void
4e44f9
 gdm_settings_direct_shutdown (void)
4e44f9
 {
4e44f9
 
4e44f9
 }
4e44f9
diff --git a/common/gdm-settings-direct.h b/common/gdm-settings-direct.h
4e44f9
index 156489cd..6754955f 100644
4e44f9
--- a/common/gdm-settings-direct.h
4e44f9
+++ b/common/gdm-settings-direct.h
4e44f9
@@ -3,48 +3,50 @@
4e44f9
  * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
4e44f9
  *
4e44f9
  * This program is free software; you can redistribute it and/or modify
4e44f9
  * it under the terms of the GNU General Public License as published by
4e44f9
  * the Free Software Foundation; either version 2 of the License, or
4e44f9
  * (at your option) any later version.
4e44f9
  *
4e44f9
  * This program is distributed in the hope that it will be useful,
4e44f9
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
4e44f9
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4e44f9
  * GNU General Public License for more details.
4e44f9
  *
4e44f9
  * You should have received a copy of the GNU General Public License
4e44f9
  * along with this program; if not, write to the Free Software
4e44f9
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
4e44f9
  *
4e44f9
  */
4e44f9
 
4e44f9
 
4e44f9
 #ifndef __GDM_SETTINGS_DIRECT_H
4e44f9
 #define __GDM_SETTINGS_DIRECT_H
4e44f9
 
4e44f9
 #include <glib-object.h>
4e44f9
 #include "gdm-settings.h"
4e44f9
 
4e44f9
 G_BEGIN_DECLS
4e44f9
 
4e44f9
 gboolean              gdm_settings_direct_init                       (GdmSettings       *settings,
4e44f9
                                                                       const char        *schemas_file,
4e44f9
                                                                       const char        *root);
4e44f9
+
4e44f9
+void                  gdm_settings_direct_reload                     (void);
4e44f9
 void                  gdm_settings_direct_shutdown                   (void);
4e44f9
 
4e44f9
 gboolean              gdm_settings_direct_get                        (const char        *key,
4e44f9
                                                                       GValue            *value);
4e44f9
 gboolean              gdm_settings_direct_set                        (const char        *key,
4e44f9
                                                                       GValue            *value);
4e44f9
 gboolean              gdm_settings_direct_get_int                    (const char        *key,
4e44f9
                                                                       int               *value);
4e44f9
 gboolean              gdm_settings_direct_get_uint                   (const char        *key,
4e44f9
                                                                       uint              *value);
4e44f9
 gboolean              gdm_settings_direct_get_boolean                (const char        *key,
4e44f9
                                                                       gboolean          *value);
4e44f9
 gboolean              gdm_settings_direct_get_string                 (const char        *key,
4e44f9
                                                                       char             **value);
4e44f9
 
4e44f9
 G_END_DECLS
4e44f9
 
4e44f9
 #endif /* __GDM_SETTINGS_DIRECT_H */
4e44f9
diff --git a/common/gdm-settings.c b/common/gdm-settings.c
4e44f9
index e6f46ec3..96c2f8d3 100644
4e44f9
--- a/common/gdm-settings.c
4e44f9
+++ b/common/gdm-settings.c
4e44f9
@@ -157,84 +157,94 @@ gdm_settings_class_init (GdmSettingsClass *klass)
4e44f9
         object_class->finalize = gdm_settings_finalize;
4e44f9
 
4e44f9
         signals [VALUE_CHANGED] =
4e44f9
                 g_signal_new ("value-changed",
4e44f9
                               G_TYPE_FROM_CLASS (object_class),
4e44f9
                               G_SIGNAL_RUN_LAST,
4e44f9
                               0,
4e44f9
                               NULL,
4e44f9
                               NULL,
4e44f9
                               g_cclosure_marshal_generic,
4e44f9
                               G_TYPE_NONE,
4e44f9
                               3,
4e44f9
                               G_TYPE_STRING,
4e44f9
                               G_TYPE_STRING,
4e44f9
                               G_TYPE_STRING);
4e44f9
 }
4e44f9
 
4e44f9
 static void
4e44f9
 backend_value_changed (GdmSettingsBackend *backend,
4e44f9
                        const char         *key,
4e44f9
                        const char         *old_value,
4e44f9
                        const char         *new_value,
4e44f9
                        GdmSettings        *settings)
4e44f9
 {
4e44f9
         g_debug ("Emitting value-changed %s %s %s", key, old_value, new_value);
4e44f9
 
4e44f9
         /* proxy it to internal listeners */
4e44f9
         g_signal_emit (settings, signals [VALUE_CHANGED], 0, key, old_value, new_value);
4e44f9
 }
4e44f9
 
4e44f9
-static void
4e44f9
-gdm_settings_init (GdmSettings *settings)
4e44f9
+void
4e44f9
+gdm_settings_reload (GdmSettings *settings)
4e44f9
 {
4e44f9
         GList *l;
4e44f9
         GdmSettingsBackend *backend;
4e44f9
 
4e44f9
+        g_list_foreach (settings->backends, (GFunc) g_object_unref, NULL);
4e44f9
+        g_list_free (settings->backends);
4e44f9
+        settings->backends = NULL;
4e44f9
+
4e44f9
         backend = gdm_settings_desktop_backend_new (GDM_CUSTOM_CONF);
4e44f9
         if (backend)
4e44f9
                 settings->backends = g_list_prepend (NULL, backend);
4e44f9
 
4e44f9
         backend = gdm_settings_desktop_backend_new (GDM_RUNTIME_CONF);
4e44f9
         if (backend)
4e44f9
                 settings->backends = g_list_prepend (settings->backends, backend);
4e44f9
 
4e44f9
         for (l = settings->backends; l; l = g_list_next (l)) {
4e44f9
                 backend = l->data;
4e44f9
 
4e44f9
                 g_signal_connect (backend,
4e44f9
                                   "value-changed",
4e44f9
                                   G_CALLBACK (backend_value_changed),
4e44f9
                                   settings);
4e44f9
         }
4e44f9
 }
4e44f9
 
4e44f9
+static void
4e44f9
+gdm_settings_init (GdmSettings *settings)
4e44f9
+{
4e44f9
+        gdm_settings_reload (settings);
4e44f9
+}
4e44f9
+
4e44f9
 static void
4e44f9
 gdm_settings_finalize (GObject *object)
4e44f9
 {
4e44f9
         GdmSettings *settings;
4e44f9
 
4e44f9
         g_return_if_fail (object != NULL);
4e44f9
         g_return_if_fail (GDM_IS_SETTINGS (object));
4e44f9
 
4e44f9
         settings = GDM_SETTINGS (object);
4e44f9
 
4e44f9
         g_return_if_fail (settings != NULL);
4e44f9
 
4e44f9
         g_list_foreach (settings->backends, (GFunc) g_object_unref, NULL);
4e44f9
         g_list_free (settings->backends);
4e44f9
         settings->backends = NULL;
4e44f9
 
4e44f9
         settings_object = NULL;
4e44f9
 
4e44f9
         G_OBJECT_CLASS (gdm_settings_parent_class)->finalize (object);
4e44f9
 }
4e44f9
 
4e44f9
 GdmSettings *
4e44f9
 gdm_settings_new (void)
4e44f9
 {
4e44f9
         if (settings_object != NULL) {
4e44f9
                 g_object_ref (settings_object);
4e44f9
         } else {
4e44f9
                 settings_object = g_object_new (GDM_TYPE_SETTINGS, NULL);
4e44f9
         }
4e44f9
 
4e44f9
diff --git a/common/gdm-settings.h b/common/gdm-settings.h
4e44f9
index 786868a9..07b64785 100644
4e44f9
--- a/common/gdm-settings.h
4e44f9
+++ b/common/gdm-settings.h
4e44f9
@@ -13,45 +13,46 @@
4e44f9
  * GNU General Public License for more details.
4e44f9
  *
4e44f9
  * You should have received a copy of the GNU General Public License
4e44f9
  * along with this program; if not, write to the Free Software
4e44f9
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
4e44f9
  *
4e44f9
  */
4e44f9
 
4e44f9
 
4e44f9
 #ifndef __GDM_SETTINGS_H
4e44f9
 #define __GDM_SETTINGS_H
4e44f9
 
4e44f9
 #include <glib-object.h>
4e44f9
 
4e44f9
 G_BEGIN_DECLS
4e44f9
 
4e44f9
 #define GDM_TYPE_SETTINGS (gdm_settings_get_type ())
4e44f9
 G_DECLARE_FINAL_TYPE (GdmSettings, gdm_settings, GDM, SETTINGS, GObject)
4e44f9
 
4e44f9
 typedef enum
4e44f9
 {
4e44f9
         GDM_SETTINGS_ERROR_GENERAL,
4e44f9
         GDM_SETTINGS_ERROR_KEY_NOT_FOUND
4e44f9
 } GdmSettingsError;
4e44f9
 
4e44f9
 #define GDM_SETTINGS_ERROR gdm_settings_error_quark ()
4e44f9
 
4e44f9
 GQuark              gdm_settings_error_quark                    (void);
4e44f9
 
4e44f9
 GdmSettings *       gdm_settings_new                            (void);
4e44f9
+void                gdm_settings_reload                         (GdmSettings *settings);
4e44f9
 
4e44f9
 /* exported */
4e44f9
 
4e44f9
 gboolean            gdm_settings_get_value                      (GdmSettings *settings,
4e44f9
                                                                  const char  *key,
4e44f9
                                                                  char       **value,
4e44f9
                                                                  GError     **error);
4e44f9
 gboolean            gdm_settings_set_value                      (GdmSettings *settings,
4e44f9
                                                                  const char  *key,
4e44f9
                                                                  const char  *value,
4e44f9
                                                                  GError     **error);
4e44f9
 
4e44f9
 G_END_DECLS
4e44f9
 
4e44f9
 #endif /* __GDM_SETTINGS_H */
4e44f9
diff --git a/daemon/main.c b/daemon/main.c
4e44f9
index 1b893fe0..344d1b74 100644
4e44f9
--- a/daemon/main.c
4e44f9
+++ b/daemon/main.c
4e44f9
@@ -240,70 +240,62 @@ gdm_daemon_lookup_user (uid_t *uidp,
4e44f9
         if G_UNLIKELY (gid == 0) {
4e44f9
                 gdm_fail (_("The GDM group should not be root. Aborting!"));
4e44f9
         }
4e44f9
 
4e44f9
         if (uidp != NULL) {
4e44f9
                 *uidp = uid;
4e44f9
         }
4e44f9
 
4e44f9
         if (gidp != NULL) {
4e44f9
                 *gidp = gid;
4e44f9
         }
4e44f9
 
4e44f9
         g_free (username);
4e44f9
         g_free (groupname);
4e44f9
 }
4e44f9
 
4e44f9
 static gboolean
4e44f9
 on_shutdown_signal_cb (gpointer user_data)
4e44f9
 {
4e44f9
         GMainLoop *mainloop = user_data;
4e44f9
 
4e44f9
         g_main_loop_quit (mainloop);
4e44f9
 
4e44f9
         return FALSE;
4e44f9
 }
4e44f9
 
4e44f9
 static gboolean
4e44f9
 on_sighup_cb (gpointer user_data)
4e44f9
 {
4e44f9
         g_debug ("Got HUP signal");
4e44f9
-        /* Reread config stuff like system config files, VPN service
4e44f9
-         * files, etc
4e44f9
-         */
4e44f9
-        g_object_unref (settings);
4e44f9
-        settings = gdm_settings_new ();
4e44f9
-        if (settings != NULL) {
4e44f9
-                if (! gdm_settings_direct_init (settings, DATADIR "/gdm/gdm.schemas", "/")) {
4e44f9
-                        g_warning ("Unable to initialize settings");
4e44f9
-                }
4e44f9
-        }
4e44f9
+
4e44f9
+        gdm_settings_reload (settings);
4e44f9
 
4e44f9
         return TRUE;
4e44f9
 }
4e44f9
 
4e44f9
 static gboolean
4e44f9
 is_debug_set (void)
4e44f9
 {
4e44f9
         gboolean debug;
4e44f9
         gdm_settings_direct_get_boolean (GDM_KEY_DEBUG, &debug);
4e44f9
         return debug;
4e44f9
 }
4e44f9
 
4e44f9
 /* SIGUSR1 is used by the X server to tell us that we're ready, so
4e44f9
  * block it. We'll unblock it in the worker thread in gdm-server.c
4e44f9
  */
4e44f9
 static void
4e44f9
 block_sigusr1 (void)
4e44f9
 {
4e44f9
         sigset_t mask;
4e44f9
 
4e44f9
         sigemptyset (&mask);
4e44f9
         sigaddset (&mask, SIGUSR1);
4e44f9
         sigprocmask (SIG_BLOCK, &mask, NULL);
4e44f9
 }
4e44f9
 
4e44f9
 int
4e44f9
 main (int    argc,
4e44f9
       char **argv)
4e44f9
 {
4e44f9
         GMainLoop          *main_loop;
4e44f9
-- 
4e44f9
2.34.1
4e44f9