Blame SOURCES/polkit-0.112-pkttyagent-tty-echo-off-on-fail.patch

236044
diff -up ./src/programs/pkttyagent.c.ori ./src/programs/pkttyagent.c
236044
--- ./src/programs/pkttyagent.c.ori	2019-03-21 15:28:00.058408349 +0100
236044
+++ ./src/programs/pkttyagent.c	2019-03-21 15:32:55.499744167 +0100
236044
@@ -24,11 +24,44 @@
236044
 #endif
236044
 
236044
 #include <stdio.h>
236044
+#include <signal.h>
236044
+#include <termios.h>
236044
 #include <glib/gi18n.h>
236044
 #include <polkit/polkit.h>
236044
 #define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
236044
 #include <polkitagent/polkitagent.h>
236044
 
236044
+
236044
+static volatile sig_atomic_t tty_flags_saved;
236044
+struct termios ts;
236044
+FILE *tty = NULL;
236044
+struct sigaction savesigterm, savesigint, savesigtstp;
236044
+
236044
+
236044
+static void tty_handler(int signal)
236044
+{
236044
+  switch (signal)
236044
+  {
236044
+    case SIGTERM:
236044
+      sigaction (SIGTERM, &savesigterm, NULL);
236044
+      break;
236044
+    case SIGINT:
236044
+      sigaction (SIGINT, &savesigint, NULL);
236044
+      break;
236044
+    case SIGTSTP:
236044
+      sigaction (SIGTSTP, &savesigtstp, NULL);
236044
+      break;
236044
+  }
236044
+
236044
+  if (tty_flags_saved)
236044
+  {
236044
+    tcsetattr (fileno (tty), TCSAFLUSH, &ts);
236044
+  }
236044
+
236044
+  kill(getpid(), signal);
236044
+}
236044
+
236044
+
236044
 int
236044
 main (int argc, char *argv[])
236044
 {
236044
@@ -73,6 +106,8 @@ main (int argc, char *argv[])
236044
   GMainLoop *loop = NULL;
236044
   guint ret = 126;
236044
   GVariantBuilder builder;
236044
+  struct sigaction sa;
236044
+  const char *tty_name = NULL;
236044
 
236044
   g_type_init ();
236044
 
236044
@@ -202,6 +237,27 @@ main (int argc, char *argv[])
236044
         }
236044
     }
236044
 
236044
+/* Bash leaves tty echo disabled if SIGINT/SIGTERM comes to polkitagenttextlistener.c::on_request(),
236044
+   but due to threading the handlers cannot take care of the signal there.
236044
+   Though if controlling terminal cannot be found, the world won't stop spinning.
236044
+*/
236044
+  tty_name = ctermid(NULL);
236044
+  if (tty_name != NULL)
236044
+  {
236044
+    tty = fopen(tty_name, "r+");
236044
+  }
236044
+
236044
+  if (tty != NULL && !tcgetattr (fileno (tty), &ts))
236044
+  {
236044
+	  tty_flags_saved = TRUE;
236044
+  }
236044
+
236044
+  memset (&sa, 0, sizeof (sa));
236044
+  sa.sa_handler = &tty_handler;
236044
+  sigaction (SIGTERM, &sa, &savesigterm);
236044
+  sigaction (SIGINT, &sa, &savesigint);
236044
+  sigaction (SIGTSTP, &sa, &savesigtstp);
236044
+
236044
   loop = g_main_loop_new (NULL, FALSE);
236044
   g_main_loop_run (loop);
236044