Added command line option to set supervisor's sanity points pool.

This allows controlling how long a child can hang before being killed.


git-svn-id: http://voip.null.ro/svn/yate@6156 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2016-12-20 14:40:04 +00:00
parent 0759258391
commit 5aaef1eca7
2 changed files with 21 additions and 4 deletions

View File

@ -84,6 +84,9 @@ Enable core dumps if supported by the operating system
.B \-F .B \-F
Increase the maximum file handle to compiled value Increase the maximum file handle to compiled value
.TP .TP
.B \-S
Set size of supervised sanity points pool
.TP
.B \-t .B \-t
Truncate the log file instead of appending to it Truncate the log file instead of appending to it
.TP .TP

View File

@ -139,7 +139,9 @@ using namespace TelEngine;
// Supervisor control constants // Supervisor control constants
// Maximum the child's sanity pool can grow // Minimum configurable size of child's sanity pool
#define MIN_SANITY 2
// Default maximum the child's sanity pool can grow
#define MAX_SANITY 5 #define MAX_SANITY 5
// Initial sanity buffer, allow some init time for the child // Initial sanity buffer, allow some init time for the child
#define INIT_SANITY 30 #define INIT_SANITY 30
@ -169,6 +171,7 @@ static bool s_keepclosing = false;
static bool s_nounload = false; static bool s_nounload = false;
static int s_super_handle = -1; static int s_super_handle = -1;
static int s_run_attempt = 0; static int s_run_attempt = 0;
static int s_max_sanity = MAX_SANITY;
static bool s_interactive = true; static bool s_interactive = true;
static bool s_localsymbol = false; static bool s_localsymbol = false;
static bool s_logtruncate = false; static bool s_logtruncate = false;
@ -1041,7 +1044,7 @@ static void copystream(int dest, int src)
static int supervise(int initDelay) static int supervise(int initDelay)
{ {
s_superpid = ::getpid(); s_superpid = ::getpid();
::fprintf(stderr,"Supervisor (%u) is starting\n",s_superpid); ::fprintf(stderr,"Supervisor (%d) is starting, max sanity %d\n",s_superpid,s_max_sanity);
::signal(SIGINT,superhandler); ::signal(SIGINT,superhandler);
::signal(SIGTERM,superhandler); ::signal(SIGTERM,superhandler);
::signal(SIGHUP,superhandler); ::signal(SIGHUP,superhandler);
@ -1136,8 +1139,8 @@ static int supervise(int initDelay)
if (tmp >= 0) { if (tmp >= 0) {
// Timer messages add one sanity point every second // Timer messages add one sanity point every second
tmp += sanity; tmp += sanity;
if (tmp > MAX_SANITY) if (tmp > s_max_sanity)
tmp = MAX_SANITY; tmp = s_max_sanity;
if (sanity < tmp) if (sanity < tmp)
sanity = tmp; sanity = tmp;
// Decrement inter-run delay each time child proves sanity // Decrement inter-run delay each time child proves sanity
@ -2319,6 +2322,7 @@ static void usage(bool client, FILE* f)
" -d Daemonify, suppress output unless logged\n" " -d Daemonify, suppress output unless logged\n"
" -s[=msec] Supervised, restart if crashes or locks up, optionally sleeps initially\n" " -s[=msec] Supervised, restart if crashes or locks up, optionally sleeps initially\n"
" -r Enable rotation of log file (needs -s and -l)\n" " -r Enable rotation of log file (needs -s and -l)\n"
" -S sanity Set size of supervised sanity points pool\n"
#endif #endif
,s_cfgfile.safe() ,s_cfgfile.safe()
,s_usrpath.safe()); ,s_usrpath.safe());
@ -2456,6 +2460,16 @@ int Engine::main(int argc, const char** argv, const char** env, RunMode mode, En
case 'r': case 'r':
s_logrotator = true; s_logrotator = true;
break; break;
case 'S':
GET_PARAM;
s_max_sanity = ::strtol(param,0,0);
if (s_max_sanity <= 0)
s_max_sanity = MAX_SANITY;
else if (s_max_sanity < MIN_SANITY)
s_max_sanity = MIN_SANITY;
else if (s_max_sanity > INIT_SANITY)
s_max_sanity = INIT_SANITY;
break;
#endif #endif
case 't': case 't':
s_logtruncate = true; s_logtruncate = true;