pager,agent: insist that we are called from the main thread
authorLennart Poettering <lennart@poettering.net>
Fri, 29 Dec 2017 17:13:38 +0000 (18:13 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 4 Jan 2018 12:27:27 +0000 (13:27 +0100)
We maintain static process-wide variables in these subsystems without
locking, hence let's refuse operation unless we are called from the main
thread (which we do anyway) just as a safety precaution.

src/shared/pager.c
src/shared/spawn-ask-password-agent.c
src/shared/spawn-polkit-agent.c

index 18c8f6c..d26fa0e 100644 (file)
@@ -73,6 +73,9 @@ int pager_open(bool no_pager, bool jump_to_end) {
         if (terminal_is_dumb())
                 return 0;
 
+        if (!is_main_thread())
+                return -EPERM;
+
         pager = getenv("SYSTEMD_PAGER");
         if (!pager)
                 pager = getenv("PAGER");
index 17785fd..f78167c 100644 (file)
@@ -40,6 +40,9 @@ int ask_password_agent_open(void) {
         if (!isatty(STDIN_FILENO))
                 return 0;
 
+        if (!is_main_thread())
+                return -EPERM;
+
         r = fork_agent("(sd-askpwagent)",
                        NULL, 0,
                        &agent_pid,
index 886248b..3c93c79 100644 (file)
@@ -52,6 +52,9 @@ int polkit_agent_open(void) {
         if (!isatty(STDIN_FILENO))
                 return 0;
 
+        if (!is_main_thread())
+                return -EPERM;
+
         if (pipe2(pipe_fd, 0) < 0)
                 return -errno;