[gnome-builder/gnome-builder-3-32] main: use SHLVL=0 to detect we are not run from a terminal



commit 4616dd6f1ee1ed9a7acba8946a7832f243340300
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 15 12:22:35 2019 -0700

    main: use SHLVL=0 to detect we are not run from a terminal
    
    This can allow us to disable gdb self-inspection helpers when run directly
    from gnome-shell or other desktop shells.

 src/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/src/main.c b/src/main.c
index d230634ae..ec7fe14e4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -99,6 +99,15 @@ home_contains_symlink (void)
 static gboolean
 is_running_in_shell (void)
 {
+  const gchar *shlvl = g_getenv ("SHLVL");
+
+  /* GNOME Shell, among other desktop shells may set SHLVL=0 to indicate
+   * that we are not running within a shell. Use that before checking any
+   * file-descriptors since it is more reliable.
+   */
+  if (ide_str_equal0 (shlvl, "0"))
+    return FALSE;
+
   /* If stdin is not a TTY, then assume we have no access to communicate
    * with the user via console. We use stdin instead of stdout as a logging
    * system may have a PTY for stdout to get colorized output.


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