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