From 700765870207f2507316f379227267bc3d9eb1cd Mon Sep 17 00:00:00 2001 From: Alexander Zhdanov Date: Fri, 21 Jun 2024 16:33:25 +0300 Subject: [PATCH 1/2] Added shutdown handler for server to avoid active connections after termination --- src/remote/server/os/posix/inet_server.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/remote/server/os/posix/inet_server.cpp b/src/remote/server/os/posix/inet_server.cpp index 3b062564cab..d527519ebd9 100644 --- a/src/remote/server/os/posix/inet_server.cpp +++ b/src/remote/server/os/posix/inet_server.cpp @@ -115,6 +115,7 @@ const char* TEMP_DIR = "/tmp"; static void set_signal(int, void (*)(int)); static void signal_handler(int); +static void shutdown_handler(int); static TEXT protocol[128]; static int INET_SERVER_start = 0; @@ -314,6 +315,10 @@ int CLIB_ROUTINE main( int argc, char** argv) // activate paths set with -e family of switches ISC_set_prefix(0, 0); + // set shutdown signals handler for listener + set_signal(SIGTERM, shutdown_handler); + set_signal(SIGINT, shutdown_handler); + // ignore some signals set_signal(SIGPIPE, signal_handler); set_signal(SIGUSR1, signal_handler); @@ -507,6 +512,10 @@ int CLIB_ROUTINE main( int argc, char** argv) } } + // set default handlers for child processes + signal(SIGTERM, SIG_DFL); + signal(SIGINT, SIG_DFL); + if (classic) { port = INET_server(channel); @@ -631,6 +640,23 @@ static void signal_handler(int) ++INET_SERVER_start; } +static void shutdown_handler(int) +{ +/************************************** + * + * s h u t d o w n _ h a n d l e r + * + ************************************** + * + * Functional description + * Forward sigterm signal to all child processes. + * + **************************************/ + + kill(-1 * getpid(), SIGTERM); + + exit(FINI_OK); +} #ifdef FB_RAISE_LIMITS static void raiseLimit(int resource) From 440376765cf70f8661a6c3a564f58e04563e8767 Mon Sep 17 00:00:00 2001 From: Alexander Zhdanov Date: Mon, 24 Jun 2024 19:59:08 +0300 Subject: [PATCH 2/2] Setting handlers for classic only --- src/remote/server/os/posix/inet_server.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/remote/server/os/posix/inet_server.cpp b/src/remote/server/os/posix/inet_server.cpp index d527519ebd9..e0bbdeb39d2 100644 --- a/src/remote/server/os/posix/inet_server.cpp +++ b/src/remote/server/os/posix/inet_server.cpp @@ -316,8 +316,11 @@ int CLIB_ROUTINE main( int argc, char** argv) ISC_set_prefix(0, 0); // set shutdown signals handler for listener - set_signal(SIGTERM, shutdown_handler); - set_signal(SIGINT, shutdown_handler); + if (standaloneClassic) + { + set_signal(SIGTERM, shutdown_handler); + set_signal(SIGINT, shutdown_handler); + } // ignore some signals set_signal(SIGPIPE, signal_handler); @@ -513,8 +516,11 @@ int CLIB_ROUTINE main( int argc, char** argv) } // set default handlers for child processes - signal(SIGTERM, SIG_DFL); - signal(SIGINT, SIG_DFL); + if (standaloneClassic) + { + signal(SIGTERM, SIG_DFL); + signal(SIGINT, SIG_DFL); + } if (classic) {