Skip to content

Commit c96f001

Browse files
Zhdanov0Alexander Zhdanov
authored andcommitted
Added shutdown handler for server (#8165)
Co-authored-by: Alexander Zhdanov <alexander.zhdanov@red-soft.ru>
1 parent 070ee0b commit c96f001

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
@@ -116,6 +116,7 @@ const char* TEMP_DIR = "/tmp";
116116

117117
static void set_signal(int, void (*)(int));
118118
static void signal_handler(int);
119+
static void shutdown_handler(int);
119120

120121
static TEXT protocol[128];
121122
static int INET_SERVER_start = 0;
@@ -312,6 +313,13 @@ int CLIB_ROUTINE main( int argc, char** argv)
312313
// activate paths set with -e family of switches
313314
ISC_set_prefix(0, 0);
314315

316+
// set shutdown signals handler for listener
317+
if (standaloneClassic)
318+
{
319+
set_signal(SIGTERM, shutdown_handler);
320+
set_signal(SIGINT, shutdown_handler);
321+
}
322+
315323
// ignore some signals
316324
set_signal(SIGPIPE, signal_handler);
317325
set_signal(SIGUSR1, signal_handler);
@@ -502,6 +510,13 @@ int CLIB_ROUTINE main( int argc, char** argv)
502510
}
503511
}
504512

513+
// set default handlers for child processes
514+
if (standaloneClassic)
515+
{
516+
signal(SIGTERM, SIG_DFL);
517+
signal(SIGINT, SIG_DFL);
518+
}
519+
505520
if (classic)
506521
{
507522
port = INET_server(channel);
@@ -626,6 +641,23 @@ static void signal_handler(int)
626641
++INET_SERVER_start;
627642
}
628643

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

630662
#ifdef FB_RAISE_LIMITS
631663
static void raiseLimit(int resource)

0 commit comments

Comments
 (0)