1 From 9940c2f754e3292b6d96628682c254941ae6cc58 Mon Sep 17 00:00:00 2001
2 From: Zdenek Kabelac <zkabelac@redhat.com>
3 Date: Wed, 4 Oct 2017 13:58:21 +0200
4 Subject: [PATCH] dmeventd: schedule exit on break
6 When dmeventd receives SIGTERM/INT/HUP/QUIT it validates if exit is possible.
7 If there was any device still monitored, such exit request used to
8 be ignored/refused. This 'usually' worked reasonably well, however if there
9 is very short time period between last device is unmonitored and signal
10 reception - there was possibility such EXIT was ignored, as dmeventd has
11 not yet got into idle state even commands like 'vgchange -an' has already
14 This patch changes logic towards scheduling EXIT to the nearest
15 point when there is no monitored device.
17 EXIT is never forgotten.
19 NOTE: if there is only a single monitored device and someone sends
20 SIGTERM and later someone uses i.e. 'lvchange --refresh' after
21 unmonitoring dmeventd will exit and new instance needs to be
24 cherry picked from commit 9940c2f754e3292b6d96628682c254941ae6cc58
26 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
28 daemons/dmeventd/dmeventd.c | 13 ++++++++-----
29 1 files changed, 8 insertions(+), 5 deletions(-)
31 diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
32 index 3a92ab6..cc520d3 100644
33 --- a/daemons/dmeventd/dmeventd.c
34 +++ b/daemons/dmeventd/dmeventd.c
39 +#define DM_SIGNALED_EXIT 1
40 +#define DM_SCHEDULED_EXIT 2
41 static volatile sig_atomic_t _exit_now = 0; /* set to '1' when signal is given to exit */
43 /* List (un)link macros. */
44 @@ -1750,7 +1752,7 @@ static void _init_thread_signals(void)
46 static void _exit_handler(int sig __attribute__((unused)))
49 + _exit_now = DM_SIGNALED_EXIT;
53 @@ -2248,6 +2250,8 @@ int main(int argc, char *argv[])
57 + if (_exit_now == DM_SCHEDULED_EXIT)
58 + break; /* Only prints shutdown message */
59 log_info("dmeventd detected break while being idle "
60 "for %ld second(s), exiting.",
61 (long) (time(NULL) - _idle_since));
62 @@ -2264,15 +2268,14 @@ int main(int argc, char *argv[])
66 - } else if (_exit_now) {
68 + } else if (_exit_now == DM_SIGNALED_EXIT) {
69 + _exit_now = DM_SCHEDULED_EXIT;
71 * When '_exit_now' is set, signal has been received,
72 * but can not simply exit unless all
73 * threads are done processing.
75 - log_warn("WARNING: There are still devices being monitored.");
76 - log_warn("WARNING: Refusing to exit.");
77 + log_info("dmeventd received break, scheduling exit.");
79 _process_request(&fifos);
80 _cleanup_unused_threads();