[gnome-shell/benzea/systemd-clean-shutdown-with-extension-disabling: 5/6] main: Create/delete a gnome-shell-stable file



commit f061bbeb78fd809203b03c6f9094fe4c66457ddd
Author: Benjamin Berg <bberg redhat com>
Date:   Mon Nov 25 17:38:52 2019 +0100

    main: Create/delete a gnome-shell-stable file
    
    The file is placed in the runtime directory. The sole purpose for it is
    to be consumed by the gnome-shell-disable-extensions.service so that
    extensions are less likely to be disabled without a good reason.

 src/main.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
---
diff --git a/src/main.c b/src/main.c
index 6faf9934fb..1bcaba6d9a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,6 +7,7 @@
 #endif
 #include <stdlib.h>
 #include <string.h>
+#include <fcntl.h>
 
 #include <cogl-pango/cogl-pango.h>
 #include <clutter/clutter.h>
@@ -32,6 +33,9 @@ extern GType gnome_shell_plugin_get_type (void);
 #define WM_NAME "GNOME Shell"
 #define GNOME_WM_KEYBINDINGS "Mutter,GNOME Shell"
 
+#define SHELL_STABLE_TIMEOUT 120
+#define SHELL_STABLE_MARKER "gnome-shell-stable"
+
 static gboolean is_gdm_mode = FALSE;
 static char *session_mode = NULL;
 static int caught_signal = 0;
@@ -46,6 +50,34 @@ enum {
 static int _shell_debug;
 static gboolean _tracked_signals[NSIG] = { 0 };
 
+
+static void
+delete_stable_marker (void)
+{
+  g_autofree gchar *path = NULL;
+
+  path = g_build_filename (g_get_user_runtime_dir (),
+                           SHELL_STABLE_MARKER,
+                           NULL);
+  unlink (path);
+}
+
+static gboolean
+create_stable_marker (void)
+{
+  g_autofree gchar *path = NULL;
+  gint fd;
+
+  path = g_build_filename (g_get_user_runtime_dir (),
+                           SHELL_STABLE_MARKER,
+                           NULL);
+  fd = open (path, O_CREAT | O_WRONLY, 00600);
+  if (fd > 0)
+    close (fd);
+
+  return G_SOURCE_REMOVE;
+}
+
 static void
 shell_dbus_acquire_name (GDBusProxy  *bus,
                          guint32      request_name_flags,
@@ -492,6 +524,15 @@ main (int argc, char **argv)
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
 
+  /* Delete/create stable marker.
+   * The sole purpose of this marker is to prevent extensions from being
+   * disabled after a gnome-shell crash.
+   */
+  delete_stable_marker ();
+  g_timeout_add_seconds (SHELL_STABLE_TIMEOUT,
+                         G_SOURCE_FUNC (create_stable_marker),
+                         NULL);
+
   session_mode = (char *) g_getenv ("GNOME_SHELL_SESSION_MODE");
 
   ctx = meta_get_option_context ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]