dcavalca / rpms / systemd

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