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

[win-pv-devel] [PATCH 3/3] xenagent: remove the service when the package is removed



Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
Cc: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/coinst/coinst.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index ef646e8..fd1e93b 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -55,6 +55,8 @@ __user_code;
 #define SERVICE_KEY(_Driver)    \
         SERVICES_KEY ## "\\" ## #_Driver
 
+#define AGENT_NAME    "XENAGENT"
+
 static VOID
 #pragma prefast(suppress:6262) // Function uses '1036' bytes of stack: exceeds 
/analyze:stacksize'1024'
 __Log(
@@ -307,6 +309,78 @@ fail1:
     return FALSE;
 }
 
+static BOOL
+AgentDelete(
+    VOID
+    )
+{
+    SC_HANDLE           SCManager;
+    SC_HANDLE           Service;
+    BOOL                Success;
+    SERVICE_STATUS      Status;
+    HRESULT             Error;
+
+    Log("====>");
+
+    SCManager = OpenSCManager(NULL,
+                              NULL,
+                              SC_MANAGER_ALL_ACCESS);
+
+    if (SCManager == NULL)
+        goto fail1;
+
+    Service = OpenService(SCManager,
+                          AGENT_NAME,
+                          SERVICE_ALL_ACCESS);
+
+    if (Service == NULL)
+        goto fail2;
+
+    Success = ControlService(Service,
+                             SERVICE_CONTROL_STOP,
+                             &Status);
+
+    if (!Success)
+        goto fail3;
+
+    Success = DeleteService(Service);
+
+    if (!Success)
+        goto fail4;
+
+    CloseServiceHandle(Service);
+    CloseServiceHandle(SCManager);
+
+    Log("<====");
+
+    return TRUE;
+
+fail4:
+    Log("fail4");
+
+fail3:
+    Log("fail3");
+
+    CloseServiceHandle(Service);
+
+fail2:
+    Log("fail2");
+
+    CloseServiceHandle(SCManager);
+
+fail1:
+    Error = GetLastError();
+
+    {
+        PTCHAR  Message;
+        Message = GetErrorMessage(Error);
+        Log("fail1 (%s)", Message);
+        LocalFree(Message);
+    }
+
+    return FALSE;
+}
+
 static HRESULT
 DifInstallPreProcess(
     IN  HDEVINFO                    DeviceInfoSet,
@@ -437,7 +511,11 @@ DifRemovePreProcess(
     UNREFERENCED_PARAMETER(DeviceInfoData);
     UNREFERENCED_PARAMETER(Context);
 
-    Log("<===>");
+    Log("====>");
+
+    (VOID) AgentDelete();
+
+    Log("<====");
 
     return NO_ERROR;
 }
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.