[gnome-builder/wip/gtk4-port] libide/foundry: get stop signal from gsettings



commit f6ea6f0fda19b6ec0bf58e5bf0a2611a0e114b29
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 15 20:24:11 2022 -0700

    libide/foundry: get stop signal from gsettings
    
    This implements the functionality portion of being able to select the
    stop signal to send an application to exit. Generally we want to just
    use SIGKILL to be sure it's gone, but in some cases it might be nice to
    be able to shutdown gracefully, at the risk of it not actually stopping
    in a timely manner.
    
    To handle that, a secondary call to force_quit will ignore the stop
    signal gsetting.
    
    There isn't a way to configure this from settings yet, but it does need
    to be set for the per-project GSetting schema path, which makes it a
    bit annoying to control manually at the moment.
    
    To make this functionality somewhat useful, a preferences toggle will still
    be needed in the "Configure Project" settings window.
    
    Related #1685

 .../org.gnome.builder.project.gschema.xml          | 15 ++++++++++
 src/libide/foundry/ide-runner.c                    | 33 ++++++++++++++++++++--
 2 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.project.gschema.xml 
b/data/gsettings/org.gnome.builder.project.gschema.xml
index 0426f7828..0385faf80 100644
--- a/data/gsettings/org.gnome.builder.project.gschema.xml
+++ b/data/gsettings/org.gnome.builder.project.gschema.xml
@@ -8,5 +8,20 @@
       <description>The configuration that has been selected and will be restored the next time the project 
loads.</description>
     </key>
 
+    <key name="stop-signal" type="s">
+      <choices>
+        <choice value="SIGKILL"/>
+        <choice value="SIGINT"/>
+        <choice value="SIGHUP"/>
+        <choice value="SIGUSR1"/>
+        <choice value="SIGUSR2"/>
+        <choice value="SIGABRT"/>
+        <choice value="SIGQUIT"/>
+      </choices>
+      <default>"SIGKILL"</default>
+      <summary>The signal to send the app to stop</summary>
+      <description>This allows sending something other than sigkill to stop the target application. That 
might be useful when you want to gracefully shutdown a server process.</description>
+    </key>
+
   </schema>
 </schemalist>
diff --git a/src/libide/foundry/ide-runner.c b/src/libide/foundry/ide-runner.c
index c4cad8d53..72c2f6863 100644
--- a/src/libide/foundry/ide-runner.c
+++ b/src/libide/foundry/ide-runner.c
@@ -62,6 +62,7 @@ typedef struct
   guint failed : 1;
   guint run_on_host : 1;
   guint disable_pty : 1;
+  guint sent_force_exit_once : 1;
 } IdeRunnerPrivate;
 
 typedef struct
@@ -397,13 +398,41 @@ static void
 ide_runner_real_force_quit (IdeRunner *self)
 {
   IdeRunnerPrivate *priv = ide_runner_get_instance_private (self);
+  g_autoptr(GSettings) settings = NULL;
+  IdeContext *context;
+  const char *stop_signal;
+  int signum;
 
   IDE_ENTRY;
 
   g_assert (IDE_IS_RUNNER (self));
 
-  if (priv->subprocess != NULL)
-    ide_subprocess_force_exit (priv->subprocess);
+  if (priv->subprocess == NULL)
+    IDE_EXIT;
+
+  if (!priv->sent_force_exit_once)
+    {
+      ide_subprocess_force_exit (priv->subprocess);
+      IDE_EXIT;
+    }
+
+  priv->sent_force_exit_once = TRUE;
+
+  context = ide_object_get_context (IDE_OBJECT (self));
+  settings = ide_context_ref_project_settings (context);
+  stop_signal = g_settings_get_string (settings, NULL);
+
+  if (0) {}
+  else if (ide_str_equal0 (stop_signal, "SIGKILL")) signum = SIGKILL;
+  else if (ide_str_equal0 (stop_signal, "SIGINT"))  signum = SIGINT;
+  else if (ide_str_equal0 (stop_signal, "SIGHUP"))  signum = SIGHUP;
+  else if (ide_str_equal0 (stop_signal, "SIGUSR1")) signum = SIGUSR1;
+  else if (ide_str_equal0 (stop_signal, "SIGUSR2")) signum = SIGUSR2;
+  else if (ide_str_equal0 (stop_signal, "SIGABRT")) signum = SIGABRT;
+  else if (ide_str_equal0 (stop_signal, "SIGQUIT")) signum = SIGQUIT;
+  else signum = SIGKILL;
+
+  ide_subprocess_send_signal (priv->subprocess, signum);
 
   IDE_EXIT;
 }


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