mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +00:00
[6830] Implement custom exit codes on server shutdown/restart
Added the possibility to use custom process return values instead of hardcoded 0 (shutdown) or 2 (restart) to allow using them for various custom external features / better handling. This can be used through 4 commands in ".server" family: - shutdown - restart - idleshutdown - idlerestart Those have from now on 2 arguments, where the second (return value) is optional: .server <command> <time> [return_value] If return_value is not specified, default value (0 or 2) is used. Signed-off-by: freghar <compmancz@gmail.com> Set restart exist code for SIGINT singnal case. Some code simplifications for original patch. Related code cleanups. Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
3d72b06fcd
commit
528a9d830a
8 changed files with 149 additions and 49 deletions
|
|
@ -4583,13 +4583,33 @@ bool ChatHandler::HandleShutDownCommand(const char* args)
|
|||
}
|
||||
else
|
||||
{
|
||||
int32 time = atoi(args);
|
||||
char* time_str = strtok ((char*) args, " ");
|
||||
char* exitcode_str = strtok (NULL, "");
|
||||
|
||||
int32 time = atoi (time_str);
|
||||
|
||||
///- Prevent interpret wrong arg value as 0 secs shutdown time
|
||||
if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
|
||||
if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ(time);
|
||||
if (exitcode_str)
|
||||
{
|
||||
int32 exitcode = atoi (exitcode_str);
|
||||
|
||||
// Handle atoi() errors
|
||||
if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
|
||||
return false;
|
||||
|
||||
// Exit code should be in range of 0-125, 126-255 is used
|
||||
// in many shells for their own return codes and code > 255
|
||||
// is not supported in many others
|
||||
if (exitcode < 0 || exitcode > 125)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ (time, 0, exitcode);
|
||||
}
|
||||
else
|
||||
sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -4605,13 +4625,33 @@ bool ChatHandler::HandleRestartCommand(const char* args)
|
|||
}
|
||||
else
|
||||
{
|
||||
int32 time = atoi(args);
|
||||
char* time_str = strtok ((char*) args, " ");
|
||||
char* exitcode_str = strtok (NULL, "");
|
||||
|
||||
int32 time = atoi (time_str);
|
||||
|
||||
///- Prevent interpret wrong arg value as 0 secs shutdown time
|
||||
if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
|
||||
if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
|
||||
if (exitcode_str)
|
||||
{
|
||||
int32 exitcode = atoi (exitcode_str);
|
||||
|
||||
// Handle atoi() errors
|
||||
if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
|
||||
return false;
|
||||
|
||||
// Exit code should be in range of 0-125, 126-255 is used
|
||||
// in many shells for their own return codes and code > 255
|
||||
// is not supported in many others
|
||||
if (exitcode < 0 || exitcode > 125)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
|
||||
}
|
||||
else
|
||||
sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -4627,13 +4667,33 @@ bool ChatHandler::HandleIdleRestartCommand(const char* args)
|
|||
}
|
||||
else
|
||||
{
|
||||
int32 time = atoi(args);
|
||||
char* time_str = strtok ((char*) args, " ");
|
||||
char* exitcode_str = strtok (NULL, "");
|
||||
|
||||
int32 time = atoi (time_str);
|
||||
|
||||
///- Prevent interpret wrong arg value as 0 secs shutdown time
|
||||
if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
|
||||
if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
|
||||
if (exitcode_str)
|
||||
{
|
||||
int32 exitcode = atoi (exitcode_str);
|
||||
|
||||
// Handle atoi() errors
|
||||
if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
|
||||
return false;
|
||||
|
||||
// Exit code should be in range of 0-125, 126-255 is used
|
||||
// in many shells for their own return codes and code > 255
|
||||
// is not supported in many others
|
||||
if (exitcode < 0 || exitcode > 125)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
|
||||
}
|
||||
else
|
||||
sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -4649,13 +4709,33 @@ bool ChatHandler::HandleIdleShutDownCommand(const char* args)
|
|||
}
|
||||
else
|
||||
{
|
||||
int32 time = atoi(args);
|
||||
char* time_str = strtok ((char*) args, " ");
|
||||
char* exitcode_str = strtok (NULL, "");
|
||||
|
||||
int32 time = atoi (time_str);
|
||||
|
||||
///- Prevent interpret wrong arg value as 0 secs shutdown time
|
||||
if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
|
||||
if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
|
||||
if (exitcode_str)
|
||||
{
|
||||
int32 exitcode = atoi (exitcode_str);
|
||||
|
||||
// Handle atoi() errors
|
||||
if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
|
||||
return false;
|
||||
|
||||
// Exit code should be in range of 0-125, 126-255 is used
|
||||
// in many shells for their own return codes and code > 255
|
||||
// is not supported in many others
|
||||
if (exitcode < 0 || exitcode > 125)
|
||||
return false;
|
||||
|
||||
sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
|
||||
}
|
||||
else
|
||||
sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue