803fb7
From caca204d23babbdb0c688f543f3ee8d66a1a2001 Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Wed, 4 May 2016 19:01:56 +0200
803fb7
Subject: [PATCH] logind: process session/inhibitor fds at higher priority
803fb7
803fb7
Let's make sure we process session and inhibitor pipe fds (that signal
803fb7
sessions/inhibtors going away) at a higher priority
803fb7
than new bus calls that might create new sessions or inhibitors. This helps
803fb7
ensuring that the number of open sessions stays minimal.
803fb7
803fb7
Cherry-picked from: e11544a8305ab9dea097c74bb16e296150c9cc10
803fb7
Resolves: #1305608
803fb7
---
803fb7
 src/login/logind-inhibit.c | 2 +-
803fb7
 src/login/logind-session.c | 4 +++-
803fb7
 src/login/logind.c         | 2 +-
803fb7
 3 files changed, 5 insertions(+), 3 deletions(-)
803fb7
803fb7
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
803fb7
index 84fee0e77..bf96898f2 100644
803fb7
--- a/src/login/logind-inhibit.c
803fb7
+++ b/src/login/logind-inhibit.c
803fb7
@@ -303,7 +303,7 @@ int inhibitor_create_fifo(Inhibitor *i) {
803fb7
                 if (r < 0)
803fb7
                         return r;
803fb7
 
803fb7
-                r = sd_event_source_set_priority(i->event_source, SD_EVENT_PRIORITY_IDLE);
803fb7
+                r = sd_event_source_set_priority(i->event_source, SD_EVENT_PRIORITY_IDLE-10);
803fb7
                 if (r < 0)
803fb7
                         return r;
803fb7
         }
803fb7
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
803fb7
index dc24539f1..59f5a7ad5 100644
803fb7
--- a/src/login/logind-session.c
803fb7
+++ b/src/login/logind-session.c
803fb7
@@ -905,7 +905,9 @@ int session_create_fifo(Session *s) {
803fb7
                 if (r < 0)
803fb7
                         return r;
803fb7
 
803fb7
-                r = sd_event_source_set_priority(s->fifo_event_source, SD_EVENT_PRIORITY_IDLE);
803fb7
+                /* Let's make sure we noticed dead sessions before we process new bus requests (which might create new
803fb7
+                 * sessions). */
803fb7
+                r = sd_event_source_set_priority(s->fifo_event_source, SD_EVENT_PRIORITY_NORMAL-10);
803fb7
                 if (r < 0)
803fb7
                         return r;
803fb7
         }
803fb7
diff --git a/src/login/logind.c b/src/login/logind.c
803fb7
index 3afbf34a1..e8d0669bb 100644
803fb7
--- a/src/login/logind.c
803fb7
+++ b/src/login/logind.c
803fb7
@@ -685,7 +685,7 @@ static int manager_connect_bus(Manager *m) {
803fb7
         if (r < 0)
803fb7
                 return log_error_errno(r, "Failed to register name: %m");
803fb7
 
803fb7
-        r = sd_bus_attach_event(m->bus, m->event, 0);
803fb7
+        r = sd_bus_attach_event(m->bus, m->event, SD_EVENT_PRIORITY_NORMAL);
803fb7
         if (r < 0)
803fb7
                 return log_error_errno(r, "Failed to attach bus to event loop: %m");
803fb7