From 97243c6c325f980fcc90d7c814207070262efc7e Mon Sep 17 00:00:00 2001
From: Haru <haru@dotalux.com>
Date: Sun, 24 Jun 2018 01:57:03 +0200
Subject: Use the correct shutdown callback when the server receives a
 termination signal

This fixes a regression introduced in 22bd368e5d4d8d61a7189d03f52c3afd90c0729e

Signed-off-by: Haru <haru@dotalux.com>
---
 src/common/core.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/common/core.c b/src/common/core.c
index 1bd332eec..406bb7629 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -80,9 +80,6 @@
 // And don't complain to us if the XYZ plugin you installed wiped your hard disk, or worse.
 // Note: This feature is deprecated, and should not be used.
 
-/// Called when a terminate signal is received.
-void (*shutdown_callback)(void) = NULL;
-
 struct core_interface core_s;
 struct core_interface *core = &core_s;
 
@@ -128,8 +125,8 @@ static BOOL WINAPI console_handler(DWORD c_event)
 		case CTRL_CLOSE_EVENT:
 		case CTRL_LOGOFF_EVENT:
 		case CTRL_SHUTDOWN_EVENT:
-			if( shutdown_callback != NULL )
-				shutdown_callback();
+			if (core->shutdown_callback != NULL)
+				core->shutdown_callback();
 			else
 				core->runflag = CORE_ST_STOP;// auto-shutdown
 			break;
@@ -158,8 +155,8 @@ static void sig_proc(int sn)
 		case SIGTERM:
 			if (++is_called > 3)
 				exit(EXIT_SUCCESS);
-			if( shutdown_callback != NULL )
-				shutdown_callback();
+			if (core->shutdown_callback != NULL)
+				core->shutdown_callback();
 			else
 				core->runflag = CORE_ST_STOP;// auto-shutdown
 			break;
-- 
cgit v1.2.3-70-g09d2


From 9852b6ac5eea101aa71d80b01a41d46cb4add5d1 Mon Sep 17 00:00:00 2001
From: Haru <haru@dotalux.com>
Date: Sun, 24 Jun 2018 02:26:58 +0200
Subject: Call the shutdown callback when terminating through the server exit
 console command

Signed-off-by: Haru <haru@dotalux.com>
---
 src/common/console.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/common/console.c b/src/common/console.c
index 0b0a900f6..e7edd7e1e 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -133,7 +133,10 @@ int console_parse_key_pressed(void)
  **/
 CPCMD_C(exit, server)
 {
-	core->runflag = 0;
+	if (core->shutdown_callback != NULL)
+		core->shutdown_callback();
+	else
+		core->runflag = CORE_ST_STOP;
 }
 
 /**
-- 
cgit v1.2.3-70-g09d2