valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0214-swap-scan-proc-swaps-before-processing-waitid-result.patch

4bff0a
From a0c135f7771dbe3a6cd3da2aaa106900be0f4470 Mon Sep 17 00:00:00 2001
4bff0a
From: Lennart Poettering <lennart@poettering.net>
4bff0a
Date: Wed, 17 Jul 2019 18:58:44 +0200
4bff0a
Subject: [PATCH] swap: scan /proc/swaps before processing waitid() results
4bff0a
4bff0a
Similar to the previous commit, but for /proc/swaps, where the same
4bff0a
logic and rationale applies.
4bff0a
4bff0a
(cherry picked from commit bcce581d65de68cca01c73e1c890e261e72d20af)
4bff0a
4bff0a
Related: #1696178
4bff0a
---
4bff0a
 src/core/swap.c | 18 +++++++++++++++---
4bff0a
 1 file changed, 15 insertions(+), 3 deletions(-)
4bff0a
4bff0a
diff --git a/src/core/swap.c b/src/core/swap.c
4bff0a
index e01e61e56d..b644753a1c 100644
4bff0a
--- a/src/core/swap.c
4bff0a
+++ b/src/core/swap.c
4bff0a
@@ -40,6 +40,7 @@ static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
4bff0a
 
4bff0a
 static int swap_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
4bff0a
 static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
4bff0a
+static int swap_process_proc_swaps(Manager *m);
4bff0a
 
4bff0a
 static bool SWAP_STATE_WITH_PROCESS(SwapState state) {
4bff0a
         return IN_SET(state,
4bff0a
@@ -990,6 +991,10 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
4bff0a
         if (pid != s->control_pid)
4bff0a
                 return;
4bff0a
 
4bff0a
+        /* Let's scan /proc/swaps before we process SIGCHLD. For the reasoning see the similar code in
4bff0a
+         * mount.c */
4bff0a
+        (void) swap_process_proc_swaps(u->manager);
4bff0a
+
4bff0a
         s->control_pid = 0;
4bff0a
 
4bff0a
         if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
4bff0a
@@ -1125,13 +1130,11 @@ static int swap_load_proc_swaps(Manager *m, bool set_flags) {
4bff0a
         return r;
4bff0a
 }
4bff0a
 
4bff0a
-static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
4bff0a
-        Manager *m = userdata;
4bff0a
+static int swap_process_proc_swaps(Manager *m) {
4bff0a
         Unit *u;
4bff0a
         int r;
4bff0a
 
4bff0a
         assert(m);
4bff0a
-        assert(revents & EPOLLPRI);
4bff0a
 
4bff0a
         r = swap_load_proc_swaps(m, true);
4bff0a
         if (r < 0) {
4bff0a
@@ -1205,6 +1208,15 @@ static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, v
4bff0a
         return 1;
4bff0a
 }
4bff0a
 
4bff0a
+static int swap_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
4bff0a
+        Manager *m = userdata;
4bff0a
+
4bff0a
+        assert(m);
4bff0a
+        assert(revents & EPOLLPRI);
4bff0a
+
4bff0a
+        return swap_process_proc_swaps(m);
4bff0a
+}
4bff0a
+
4bff0a
 static Unit *swap_following(Unit *u) {
4bff0a
         Swap *s = SWAP(u);
4bff0a
         Swap *other, *first = NULL;