]>
Commit | Line | Data |
---|---|---|
7c388770 TL |
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 | |
5 | ||
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 | |
12 | finished. | |
13 | ||
14 | This patch changes logic towards scheduling EXIT to the nearest | |
15 | point when there is no monitored device. | |
16 | ||
17 | EXIT is never forgotten. | |
18 | ||
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 | |
22 | started. | |
23 | ||
24 | cherry picked from commit 9940c2f754e3292b6d96628682c254941ae6cc58 | |
25 | ||
26 | Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> | |
27 | --- | |
28 | daemons/dmeventd/dmeventd.c | 13 ++++++++----- | |
29 | 1 files changed, 8 insertions(+), 5 deletions(-) | |
30 | ||
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 | |
35 | @@ -62,6 +62,8 @@ | |
36 | ||
37 | #include <syslog.h> | |
38 | ||
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 */ | |
42 | ||
43 | /* List (un)link macros. */ | |
44 | @@ -1750,7 +1752,7 @@ static void _init_thread_signals(void) | |
45 | */ | |
46 | static void _exit_handler(int sig __attribute__((unused))) | |
47 | { | |
48 | - _exit_now = 1; | |
49 | + _exit_now = DM_SIGNALED_EXIT; | |
50 | } | |
51 | ||
52 | #ifdef __linux__ | |
53 | @@ -2248,6 +2250,8 @@ int main(int argc, char *argv[]) | |
54 | for (;;) { | |
55 | if (_idle_since) { | |
56 | if (_exit_now) { | |
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[]) | |
63 | break; | |
64 | } | |
65 | } | |
66 | - } else if (_exit_now) { | |
67 | - _exit_now = 0; | |
68 | + } else if (_exit_now == DM_SIGNALED_EXIT) { | |
69 | + _exit_now = DM_SCHEDULED_EXIT; | |
70 | /* | |
71 | * When '_exit_now' is set, signal has been received, | |
72 | * but can not simply exit unless all | |
73 | * threads are done processing. | |
74 | */ | |
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."); | |
78 | } | |
79 | _process_request(&fifos); | |
80 | _cleanup_unused_threads(); | |
81 | -- | |
82 | 2.9.3 |