[wing] Always set error variable when wing_service_manager_stop_service fails



commit a3dfbc3dd0deaab643bf2feb313d67c437e2c40b
Author: Silvio Lazzeretti <silviola amazon com>
Date:   Mon Oct 23 15:35:24 2017 +0200

    Always set error variable when wing_service_manager_stop_service fails
    
    The wing_service_manager_stop_service function always sets the
    error variable in case of error.

 wing/wingservice.h        |    4 +++-
 wing/wingservicemanager.c |   19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/wing/wingservice.h b/wing/wingservice.h
index 3655c7d..061c36a 100644
--- a/wing/wingservice.h
+++ b/wing/wingservice.h
@@ -74,13 +74,15 @@ typedef enum
  * WingServiceErrorEnum:
  * @WING_SERVICE_ERROR_GENERIC_ERROR: a generic error
  * @WING_SERVICE_ERROR_FROM_CONSOLE: emitted if trying to register the service from a console
+ * @WING_SERVICE_ERROR_SERVICE_STOP_TIMEOUT: emitted if the stop of the service took more than 2 seconds
  *
  * The errors emitted by the service.
  */
 typedef enum
 {
   WING_SERVICE_ERROR_GENERIC,
-  WING_SERVICE_ERROR_FROM_CONSOLE
+  WING_SERVICE_ERROR_FROM_CONSOLE,
+  WING_SERVICE_ERROR_SERVICE_STOP_TIMEOUT
 } WingServiceErrorEnum;
 
 #define WING_SERVICE_ERROR (wing_service_error_quark())
diff --git a/wing/wingservicemanager.c b/wing/wingservicemanager.c
index 85fe54f..7b02dc0 100644
--- a/wing/wingservicemanager.c
+++ b/wing/wingservicemanager.c
@@ -370,12 +370,29 @@ wing_service_manager_stop_service (WingServiceManager  *manager,
               g_usleep (200);
 
               if (!QueryServiceStatus (service_handle, &status))
-                break;
+                {
+                  int errsv = GetLastError ();
+                  gchar *emsg = g_win32_error_message (errsv);
+
+                  g_set_error (error, G_IO_ERROR,
+                               g_io_error_from_win32_error (errsv),
+                               emsg);
+                  g_free (emsg);
+
+                  break;
+                }
 
               stopped = status.dwCurrentState == SERVICE_STOPPED;
               i++;
             }
 
+          if (!stopped && *error == NULL)
+            {
+              g_set_error (error, G_IO_ERROR,
+                           WING_SERVICE_ERROR_SERVICE_STOP_TIMEOUT,
+                           "Stopping the server took more than 2 seconds");
+            }
+
           result = stopped;
         }
       else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]