Ensure we have a valid service exit time.
[nssm.git] / service.cpp
index 1477ba7..5a732b0 100644 (file)
@@ -1680,15 +1680,18 @@ void CALLBACK end_service(void *arg, unsigned char why) {
 \r
   service->rotate_stdout_online = service->rotate_stderr_online = NSSM_ROTATE_OFFLINE;\r
 \r
+  /* Use now as a dummy exit time. */\r
+  GetSystemTimeAsFileTime(&service->exit_time);\r
+\r
   /* Check exit code */\r
   unsigned long exitcode = 0;\r
   TCHAR code[16];\r
   if (service->process_handle) {\r
     GetExitCodeProcess(service->process_handle, &exitcode);\r
-    if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);\r
+    /* Check real exit time. */\r
+    if (exitcode != STILL_ACTIVE) get_process_exit_time(service->process_handle, &service->exit_time);\r
     CloseHandle(service->process_handle);\r
   }\r
-  else GetSystemTimeAsFileTime(&service->exit_time);\r
 \r
   service->process_handle = 0;\r
 \r