teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0604-process-util-make-our-freeze-routine-do-something-us.patch

dd65c9
From 04213418a4e8d4e7f74f5b8b03713172a658d9e4 Mon Sep 17 00:00:00 2001
dd65c9
From: Michal Sekletar <msekleta@redhat.com>
dd65c9
Date: Fri, 12 Jan 2018 13:05:48 +0100
dd65c9
Subject: [PATCH] process-util: make our freeze() routine do something useful
dd65c9
dd65c9
When we crash we freeze() our-self (or possibly we reboot the machine if
dd65c9
that is configured). However, calling pause() is very unhelpful thing to
dd65c9
do. We should at least continue to do what init systems being doing
dd65c9
since 70's and that is reaping zombies. Otherwise zombies start to
dd65c9
accumulate on the system which is a very bad thing. As that can prevent
dd65c9
admin from taking manual steps to reboot the machine in somewhat
dd65c9
graceful manner (e.g. manually stopping services, unmounting data
dd65c9
volumes  and calling reboot -f).
dd65c9
dd65c9
Fixes #7783
dd65c9
dd65c9
(cherry picked from commit 8647283e453e4039029e2b21270241fa4010b3d8)
dd65c9
dd65c9
Resolves: #1540941
dd65c9
---
dd65c9
 src/shared/util.c | 11 +++++++++++
dd65c9
 1 file changed, 11 insertions(+)
dd65c9
dd65c9
diff --git a/src/shared/util.c b/src/shared/util.c
c62b8e
index 39359fcc8a..af09532733 100644
dd65c9
--- a/src/shared/util.c
dd65c9
+++ b/src/shared/util.c
dd65c9
@@ -4158,6 +4158,17 @@ noreturn void freeze(void) {
dd65c9
 
dd65c9
         sync();
dd65c9
 
dd65c9
+        /* Let's not freeze right away, but keep reaping zombies. */
dd65c9
+        for (;;) {
dd65c9
+                int r;
dd65c9
+                siginfo_t si = {};
dd65c9
+
dd65c9
+                r = waitid(P_ALL, 0, &si, WEXITED);
dd65c9
+                if (r < 0 && errno != EINTR)
dd65c9
+                        break;
dd65c9
+        }
dd65c9
+
dd65c9
+        /* waitid() failed with an unexpected error, things are really borked. Freeze now! */
dd65c9
         for (;;)
dd65c9
                 pause();
dd65c9
 }