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