|
|
51bd1a |
commit 8bbf383316f1bb16e45b05ad6e2ba9def88ba420
|
|
|
51bd1a |
Author: Tomas Korbar <tkorbar@redhat.com>
|
|
|
51bd1a |
Date: Mon May 18 14:57:39 2020 +0200
|
|
|
51bd1a |
|
|
|
51bd1a |
improve sig_handler function
|
|
|
51bd1a |
|
|
|
51bd1a |
diff --git a/memcached.c b/memcached.c
|
|
|
51bd1a |
index 3916a8c..2547305 100644
|
|
|
51bd1a |
--- a/memcached.c
|
|
|
51bd1a |
+++ b/memcached.c
|
|
|
51bd1a |
@@ -189,7 +189,7 @@ static enum transmit_result transmit(conn *c);
|
|
|
51bd1a |
* can block the listener via a condition.
|
|
|
51bd1a |
*/
|
|
|
51bd1a |
static volatile bool allow_new_conns = true;
|
|
|
51bd1a |
-static bool stop_main_loop = false;
|
|
|
51bd1a |
+static int stop_main_loop = NOT_STOP;
|
|
|
51bd1a |
static struct event maxconnsevent;
|
|
|
51bd1a |
static void maxconns_handler(const int fd, const short which, void *arg) {
|
|
|
51bd1a |
struct timeval t = {.tv_sec = 0, .tv_usec = 10000};
|
|
|
51bd1a |
@@ -7850,8 +7850,8 @@ static void remove_pidfile(const char *pid_file) {
|
|
|
51bd1a |
}
|
|
|
51bd1a |
|
|
|
51bd1a |
static void sig_handler(const int sig) {
|
|
|
51bd1a |
+ stop_main_loop = EXIT_NORMALLY;
|
|
|
51bd1a |
printf("Signal handled: %s.\n", strsignal(sig));
|
|
|
51bd1a |
- exit(EXIT_SUCCESS);
|
|
|
51bd1a |
}
|
|
|
51bd1a |
|
|
|
51bd1a |
static void sighup_handler(const int sig) {
|
|
|
51bd1a |
@@ -7860,7 +7860,7 @@ static void sighup_handler(const int sig) {
|
|
|
51bd1a |
|
|
|
51bd1a |
static void sig_usrhandler(const int sig) {
|
|
|
51bd1a |
printf("Graceful shutdown signal handled: %s.\n", strsignal(sig));
|
|
|
51bd1a |
- stop_main_loop = true;
|
|
|
51bd1a |
+ stop_main_loop = GRACE_STOP;
|
|
|
51bd1a |
}
|
|
|
51bd1a |
|
|
|
51bd1a |
#ifndef HAVE_SIGIGNORE
|
|
|
51bd1a |
@@ -9839,7 +9839,18 @@ int main (int argc, char **argv) {
|
|
|
51bd1a |
}
|
|
|
51bd1a |
}
|
|
|
51bd1a |
|
|
|
51bd1a |
- fprintf(stderr, "Gracefully stopping\n");
|
|
|
51bd1a |
+ switch (stop_main_loop) {
|
|
|
51bd1a |
+ case GRACE_STOP:
|
|
|
51bd1a |
+ fprintf(stderr, "Gracefully stopping\n");
|
|
|
51bd1a |
+ break;
|
|
|
51bd1a |
+ case EXIT_NORMALLY:
|
|
|
51bd1a |
+ fprintf(stderr, "Exiting normally\n");
|
|
|
51bd1a |
+ break;
|
|
|
51bd1a |
+ default:
|
|
|
51bd1a |
+ fprintf(stderr, "Exiting on error\n");
|
|
|
51bd1a |
+ break;
|
|
|
51bd1a |
+ }
|
|
|
51bd1a |
+
|
|
|
51bd1a |
stop_threads();
|
|
|
51bd1a |
int i;
|
|
|
51bd1a |
// FIXME: make a function callable from threads.c
|
|
|
51bd1a |
@@ -9848,7 +9859,7 @@ int main (int argc, char **argv) {
|
|
|
51bd1a |
conn_close(conns[i]);
|
|
|
51bd1a |
}
|
|
|
51bd1a |
}
|
|
|
51bd1a |
- if (memory_file != NULL) {
|
|
|
51bd1a |
+ if (memory_file != NULL && stop_main_loop == GRACE_STOP) {
|
|
|
51bd1a |
restart_mmap_close();
|
|
|
51bd1a |
}
|
|
|
51bd1a |
|
|
|
51bd1a |
diff --git a/memcached.h b/memcached.h
|
|
|
51bd1a |
index 77f52aa..795ea8f 100644
|
|
|
51bd1a |
--- a/memcached.h
|
|
|
51bd1a |
+++ b/memcached.h
|
|
|
51bd1a |
@@ -236,6 +236,12 @@ enum pause_thread_types {
|
|
|
51bd1a |
RESUME_WORKER_THREADS
|
|
|
51bd1a |
};
|
|
|
51bd1a |
|
|
|
51bd1a |
+enum stop_reasons {
|
|
|
51bd1a |
+ NOT_STOP,
|
|
|
51bd1a |
+ GRACE_STOP,
|
|
|
51bd1a |
+ EXIT_NORMALLY
|
|
|
51bd1a |
+};
|
|
|
51bd1a |
+
|
|
|
51bd1a |
#define IS_TCP(x) (x == tcp_transport)
|
|
|
51bd1a |
#define IS_UDP(x) (x == udp_transport)
|
|
|
51bd1a |
|