Allow configuring throttling threshold.
[nssm.git] / service.cpp
index 6292698..283cbea 100644 (file)
@@ -10,6 +10,7 @@ char exe[EXE_LENGTH];
 char flags[CMD_LENGTH];\r
 char dir[MAX_PATH];\r
 bool stopping;\r
+unsigned long throttle_delay;\r
 CRITICAL_SECTION throttle_section;\r
 CONDITION_VARIABLE throttle_condition;\r
 \r
@@ -199,7 +200,7 @@ void WINAPI service_main(unsigned long argc, char **argv) {
   }\r
 \r
   service_status.dwCurrentState = SERVICE_START_PENDING;\r
-  service_status.dwWaitHint = NSSM_RESET_THROTTLE_RESTART + NSSM_WAITHINT_MARGIN;\r
+  service_status.dwWaitHint = throttle_delay + NSSM_WAITHINT_MARGIN;\r
   SetServiceStatus(service_handle, &service_status);\r
 \r
   /* Try to create the exit action parameters; we don't care if it fails */\r
@@ -294,7 +295,7 @@ int start_service() {
   ZeroMemory(&pi, sizeof(pi));\r
 \r
   /* Get startup parameters */\r
-  int ret = get_parameters(service_name, exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir));\r
+  int ret = get_parameters(service_name, exe, sizeof(exe), flags, sizeof(flags), dir, sizeof(dir), &throttle_delay);\r
   if (ret) {\r
     log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_PARAMETERS_FAILED, service_name, 0);\r
     return stop_service(2, true, true);\r
@@ -321,7 +322,7 @@ int start_service() {
   SetServiceStatus(service_handle, &service_status);\r
 \r
   /* Wait for a clean startup. */\r
-  if (WaitForSingleObject(process_handle, NSSM_RESET_THROTTLE_RESTART) == WAIT_TIMEOUT) throttle = 0;\r
+  if (WaitForSingleObject(process_handle, throttle_delay) == WAIT_TIMEOUT) throttle = 0;\r
 \r
   return 0;\r
 }\r
@@ -449,7 +450,7 @@ void throttle_restart() {
   if (throttle > 7) throttle = 8;\r
 \r
   char threshold[8], milliseconds[8];\r
-  _snprintf(threshold, sizeof(threshold), "%d", NSSM_RESET_THROTTLE_RESTART);\r
+  _snprintf(threshold, sizeof(threshold), "%d", throttle_delay);\r
   _snprintf(milliseconds, sizeof(milliseconds), "%d", ms);\r
   log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service_name, threshold, milliseconds, 0);\r
 \r