dryang / rpms / systemd

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