Explorar el Código

Legacy quick'n'dirtiness.

On Windows 2000, StartService() and ControlService() return
ERROR_IO_PENDING immediately.  Later versions of Windows have a
builtin timeout before they will return that error.

As far as we're concerned, ERROR_IO_PENDING indicates that the service
control was sent successfully so we simply override the error and
return success.

If NSSM's service management functionality is ever expanded we can take
the time to handle service controls in a more robust way.
Iain Patterson hace 12 años
padre
commit
67795adae0
Se han modificado 1 ficheros con 20 adiciones y 0 borrados
  1. 20 0
      service.cpp

+ 20 - 0
service.cpp

@@ -907,6 +907,21 @@ int control_service(unsigned long control, int argc, TCHAR **argv) {
     CloseHandle(service_handle);
     CloseServiceHandle(services);
 
+    if (error == ERROR_IO_PENDING) {
+      /*
+        Older versions of Windows return immediately with ERROR_IO_PENDING
+        indicate that the operation is still in progress.  Newer versions
+        will return it if there really is a delay.  As far as we're
+        concerned the operation is a success.  We don't claim to offer a
+        fully-feature service control method; it's just a quick 'n' dirty
+        interface.
+
+        In the future we may identify and handle this situation properly.
+      */
+      ret = 1;
+      error = ERROR_SUCCESS;
+    }
+
     if (ret) {
       _tprintf(_T("%s: %s"), canonical_name, error_string(error));
       return 0;
@@ -949,6 +964,11 @@ int control_service(unsigned long control, int argc, TCHAR **argv) {
     CloseHandle(service_handle);
     CloseServiceHandle(services);
 
+    if (error == ERROR_IO_PENDING) {
+      ret = 1;
+      error = ERROR_SUCCESS;
+    }
+
     if (ret) {
       _tprintf(_T("%s: %s"), canonical_name, error_string(error));
       return 0;