Skip to content

Commit 6e7596f

Browse files
Zhdanov0Alexander Zhdanov
andauthored
Added shutdown handler for server (#8165)
Co-authored-by: Alexander Zhdanov <alexander.zhdanov@red-soft.ru>
1 parent 262af1d commit 6e7596f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/remote/server/os/posix/inet_server.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const char* TEMP_DIR = "/tmp";
115115

116116
static void set_signal(int, void (*)(int));
117117
static void signal_handler(int);
118+
static void shutdown_handler(int);
118119

119120
static TEXT protocol[128];
120121
static int INET_SERVER_start = 0;
@@ -314,6 +315,13 @@ int CLIB_ROUTINE main( int argc, char** argv)
314315
// activate paths set with -e family of switches
315316
ISC_set_prefix(0, 0);
316317

318+
// set shutdown signals handler for listener
319+
if (standaloneClassic)
320+
{
321+
set_signal(SIGTERM, shutdown_handler);
322+
set_signal(SIGINT, shutdown_handler);
323+
}
324+
317325
// ignore some signals
318326
set_signal(SIGPIPE, signal_handler);
319327
set_signal(SIGUSR1, signal_handler);
@@ -507,6 +515,13 @@ int CLIB_ROUTINE main( int argc, char** argv)
507515
}
508516
}
509517

518+
// set default handlers for child processes
519+
if (standaloneClassic)
520+
{
521+
signal(SIGTERM, SIG_DFL);
522+
signal(SIGINT, SIG_DFL);
523+
}
524+
510525
if (classic)
511526
{
512527
port = INET_server(channel);
@@ -631,6 +646,23 @@ static void signal_handler(int)
631646
++INET_SERVER_start;
632647
}
633648

649+
static void shutdown_handler(int)
650+
{
651+
/**************************************
652+
*
653+
* s h u t d o w n _ h a n d l e r
654+
*
655+
**************************************
656+
*
657+
* Functional description
658+
* Forward sigterm signal to all child processes.
659+
*
660+
**************************************/
661+
662+
kill(-1 * getpid(), SIGTERM);
663+
664+
exit(FINI_OK);
665+
}
634666

635667
#ifdef FB_RAISE_LIMITS
636668
static void raiseLimit(int resource)

0 commit comments

Comments
 (0)