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

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