Blame SOURCES/bz2109159-storage_mon-3-fix-child-process-exit.patch

98dd5d
From c6ea93fcb499c84c3d8e9aad2ced65065a3f6d51 Mon Sep 17 00:00:00 2001
98dd5d
From: Fujii Masao <fujii@postgresql.org>
98dd5d
Date: Tue, 19 Jul 2022 22:34:08 +0900
98dd5d
Subject: [PATCH] Fix bug in handling of child process exit.
98dd5d
98dd5d
When storage_mon detects that a child process exits with zero,
98dd5d
it resets the test_forks[] entry for the child process to 0, to avoid
98dd5d
waitpid() for the process again in the loop. But, previously,
98dd5d
storage_mon didn't do that when it detected that a child process
98dd5d
exited with non-zero. Which caused waitpid() to be called again
98dd5d
for the process already gone and to report an error like
98dd5d
"waitpid on XXX failed: No child processes" unexpectedly.
98dd5d
In this case, basically storage_mon should wait until all the child
98dd5d
processes exit and return the final score, instead.
98dd5d
98dd5d
This patch fixes this issue by making storage_mon reset test_works[]
98dd5d
entry even when a child process exits with non-zero.
98dd5d
---
98dd5d
 tools/storage_mon.c | 8 ++++----
98dd5d
 1 file changed, 4 insertions(+), 4 deletions(-)
98dd5d
98dd5d
diff --git a/tools/storage_mon.c b/tools/storage_mon.c
98dd5d
index 3c82d5ee8..83a48ca36 100644
98dd5d
--- a/tools/storage_mon.c
98dd5d
+++ b/tools/storage_mon.c
98dd5d
@@ -232,13 +232,13 @@ int main(int argc, char *argv[])
98dd5d
 
98dd5d
 				if (w == test_forks[i]) {
98dd5d
 					if (WIFEXITED(wstatus)) {
98dd5d
-						if (WEXITSTATUS(wstatus) == 0) {
98dd5d
-							finished_count++;
98dd5d
-							test_forks[i] = 0;
98dd5d
-						} else {
98dd5d
+						if (WEXITSTATUS(wstatus) != 0) {
98dd5d
 							syslog(LOG_ERR, "Error reading from device %s", devices[i]);
98dd5d
 							final_score += scores[i];
98dd5d
 						}
98dd5d
+
98dd5d
+						finished_count++;
98dd5d
+						test_forks[i] = 0;
98dd5d
 					}
98dd5d
 				}
98dd5d
 			}