]> xenbits.xensource.com Git - pvdrivers/win/xeniface.git/commitdiff
Standardise on spaces, not tabs, for indentation in lite agent
authorBen Chalmers <Ben.Chalmers@citrix.com>
Fri, 13 Dec 2013 14:27:36 +0000 (14:27 +0000)
committerBen Chalmers <Ben.Chalmers@citrix.com>
Fri, 13 Dec 2013 14:28:10 +0000 (14:28 +0000)
Signed-off-by: Ben Chalmers <Ben.Chalmers@citrix.com>
src/win32stubagent/WmiAccessor.cpp
src/win32stubagent/XSAccessor.cpp
src/win32stubagent/XService.cpp

index 821e1c204e407c8ba726ec901474f94276bc0afe..2d5a1037dcd38d5e4f9c9cf892a7b19a98a2c8ae 100644 (file)
@@ -120,13 +120,13 @@ class WatchSink : public IWbemObjectSink
     LONG m_lRef;
     bool bDone; 
     HANDLE triggerevent;
-       HANDLE triggererror;
+    HANDLE triggererror;
 public:
     char *path;
     WatchSink(HANDLE event, HANDLE errorevent, const char *path) { 
         m_lRef = 1; 
         triggerevent = event;
-               triggererror = errorevent;
+        triggererror = errorevent;
         this->path = NULL;
         if (path) {
             this->path=(char *)XsAlloc(strlen(path)+1);
@@ -203,10 +203,10 @@ HRESULT WatchSink::SetStatus(
             /* [in] */ IWbemClassObject __RPC_FAR *pObjParam
         )
 {
-       if (FAILED(hResult)) {
-               XsLog("WMI Asyc watch failed %p\n", this);
-               SetEvent(this->triggererror);
-       }
+    if (FAILED(hResult)) {
+        XsLog("WMI Asyc watch failed %p\n", this);
+        SetEvent(this->triggererror);
+    }
     return WBEM_S_NO_ERROR;
 }
 
@@ -246,14 +246,14 @@ static string wstring2string(const wstring& wstr)
                               NULL,
                               NULL);
 
-       return str;
+    return str;
 }
 
 static string bstr2string(const BSTR& bstr)
 {
-       wstring wstr(bstr);
+    wstring wstr(bstr);
 
-       return wstring2string(wstr);
+    return wstring2string(wstr);
 }
 
 IWbemClassObject *getClass(WMIAccessor **wmi, BSTR path) {
@@ -261,7 +261,7 @@ IWbemClassObject *getClass(WMIAccessor **wmi, BSTR path) {
         return NULL;
 
     if ((*wmi)->mpXSSvc == NULL)
-               return NULL;
+        return NULL;
 
     IWbemClassObject *returnedObject;
     HRESULT hres = (*wmi)->mpXSSvc->GetObject(path,WBEM_FLAG_RETURN_WBEM_COMPLETE,
@@ -282,9 +282,9 @@ IWbemClassObject *getObject(WMIAccessor **wmi, BSTR path) {
                                             NULL, 
                                             &returnedEnum);
     if (FAILED(hres)) {
-               OutputDebugString("GetEnum failed\n");
+        OutputDebugString("GetEnum failed\n");
         returnedObject =NULL;
-               return returnedObject;
+        return returnedObject;
     }
     ULONG objects;
 
@@ -357,10 +357,10 @@ static IEnumWbemClassObject* runXSQuery(WMIAccessor **wmi, BSTR query)
                                          &pEnumerator);
     if (FAILED(hres))
     {
-               DBGPRINT(("ExecQuery failed\n"));
-               pEnumerator = NULL;
+        DBGPRINT(("ExecQuery failed\n"));
+        pEnumerator = NULL;
     }
-       return pEnumerator;
+    return pEnumerator;
 }
 static IEnumWbemClassObject* runQuery(WMIAccessor *wmi, BSTR query)
 {
@@ -379,161 +379,161 @@ static IEnumWbemClassObject* runQuery(WMIAccessor *wmi, BSTR query)
                                          &pEnumerator);
     if (FAILED(hres))
     {
-               DBGPRINT(("ExecQuery failed\n"));
-               pEnumerator = NULL;
+        DBGPRINT(("ExecQuery failed\n"));
+        pEnumerator = NULL;
     }
-       return pEnumerator;
+    return pEnumerator;
 }
 
 LONG wmicount = 0;
 static BOOLEAN com_initialized = false;
 static IWbemLocator *locator = 0;
 BOOL InitCom(void) {
-       HRESULT hres;
-       XsLog("Init COM");
-       hres = CoInitializeEx(0, COINIT_MULTITHREADED);
-       if (FAILED(hres)) {
-               goto err_out;
-       }
-       com_initialized = TRUE;
-       //wmi->owning_thread = GetCurrentThread();
-       //XsLog("Wmi connect thread %p", GetCurrentThread());
-       // Initialize COM security.  Most of this is irrelevant to us.
-       XsLog("Init security");
-       hres = CoInitializeSecurity(
-               NULL,     /* Security descriptor. Only relevant to servers */
-               -1,       /* Nr. of auth services. Only relevant to servers */
-               NULL,     /* List of auth services. Only relevant to servers */
-               NULL,     /* Reserved */
-               RPC_C_AUTHN_LEVEL_DEFAULT, /* Default authentication.  The
-                                                                               details don't really matter when
-                                                                               you're localhost. */
-               RPC_C_IMP_LEVEL_IMPERSONATE, /* WMI needs to be able to
-                                                                               impersonate us. */
-               NULL,             /* Authentication info */
-               EOAC_NONE,        /* Additional capabilities */
-               NULL              /* Reserved */
-               );
-       if (FAILED(hres)) {
-               goto err_out;
-       }
-                       OutputDebugString("CreateInstance\n");
-               hres = CoCreateInstance(
-                       CLSID_WbemLocator,
-                       0, 
-                       CLSCTX_INPROC_SERVER, 
-                       IID_IWbemLocator,
-                       (LPVOID *) &locator);
-               OutputDebugString("Check hres\n");
-               if (FAILED(hres)) {
-                       goto err_out;
-               }
-               if (locator == NULL) {
-                       OutputDebugString("Null locator");
-                       goto err_out;
-               }
-       return true;
+    HRESULT hres;
+    XsLog("Init COM");
+    hres = CoInitializeEx(0, COINIT_MULTITHREADED);
+    if (FAILED(hres)) {
+        goto err_out;
+    }
+    com_initialized = TRUE;
+    //wmi->owning_thread = GetCurrentThread();
+    //XsLog("Wmi connect thread %p", GetCurrentThread());
+    // Initialize COM security.  Most of this is irrelevant to us.
+    XsLog("Init security");
+    hres = CoInitializeSecurity(
+        NULL,     /* Security descriptor. Only relevant to servers */
+        -1,       /* Nr. of auth services. Only relevant to servers */
+        NULL,     /* List of auth services. Only relevant to servers */
+        NULL,     /* Reserved */
+        RPC_C_AUTHN_LEVEL_DEFAULT, /* Default authentication.  The
+                                        details don't really matter when
+                                        you're localhost. */
+        RPC_C_IMP_LEVEL_IMPERSONATE, /* WMI needs to be able to
+                                        impersonate us. */
+        NULL,             /* Authentication info */
+        EOAC_NONE,        /* Additional capabilities */
+        NULL              /* Reserved */
+        );
+    if (FAILED(hres)) {
+        goto err_out;
+    }
+            OutputDebugString("CreateInstance\n");
+        hres = CoCreateInstance(
+            CLSID_WbemLocator,
+            0, 
+            CLSCTX_INPROC_SERVER, 
+            IID_IWbemLocator,
+            (LPVOID *) &locator);
+        OutputDebugString("Check hres\n");
+        if (FAILED(hres)) {
+            goto err_out;
+        }
+        if (locator == NULL) {
+            OutputDebugString("Null locator");
+            goto err_out;
+        }
+    return true;
 err_out:
-       return false;
+    return false;
 }
 
 BOOL ConnectToWMI(void)
 {
-               InitCom();
-               HRESULT hres;
-               OutputDebugString("Connect to WMI");
-               wmicount++;
-
-               wmi = (struct WMIAccessor *)XsAlloc(sizeof(*wmi));
-               if (wmi == NULL) {
-                       return false;
-               }
-               memset(wmi, 0, sizeof(*wmi));
-
-
-               OutputDebugString("Connect Server\n");
-               try {
-                       hres = locator->ConnectServer(
-                               L"root\\CIMV2",          // WMI namespace
-                               NULL,                    // User name
-                               NULL,                    // User password
-                               NULL,                    // Locale
-                               0,                       // Security flags
-                               NULL,                    // Authority
-                               NULL,                    // Context object
-                               &(wmi->mpSvc)              // IWbemServices proxy
-                               );
-               }
-               catch(...) {
-                       OutputDebugString("Exception connecting to server\n");
-                       goto err_out;
-               }
-
-               OutputDebugString("Check result\n");
-               if (FAILED(hres)) {
-                       goto err_out;
-               }
-               /* WMI needs to impersonate us, because it normally runs as an
-                  unprivileged user and needs our authority in order to access
-                  device files and so forth.  Turn impersonation on. */
-               OutputDebugString("Proxy blanket\n");
-               hres = CoSetProxyBlanket(
-                       wmi->mpSvc,                  // the proxy to set
-                       RPC_C_AUTHN_WINNT,           /* LAN manager authentication,
-                                                                                       although it doesn't really
-                                                                                       matter on localhost. */
-                       RPC_C_AUTHZ_NONE,            // LANMAN can't do much authorization.
-                       NULL,                        // Server principal name
-                       RPC_C_AUTHN_LEVEL_CALL,      // Do authentication on every call
-                       RPC_C_IMP_LEVEL_IMPERSONATE, // Allow full impersonation.
-                       NULL,                        // Use current client identity
-                       EOAC_NONE                    // No extended proxy capabilities
-               );
-               if (FAILED(hres)) {
-                       goto err_out;
-               }
-               OutputDebugString("WMI Server\n");
-               hres = locator->ConnectServer(
-                       L"root\\WMI",          // WMI namespace
-                       NULL,                    // User name
-                       NULL,                    // User password
-                       NULL,                    // Locale
-                       0,                       // Security flags
-                       NULL,                    // Authority
-                       NULL,                    // Context object
-                       &wmi->mpXSSvc              // IWbemServices proxy
-                       );
-
-               if (FAILED(hres)) {
-                       goto err_out;
-               }
-               OutputDebugString("Impersonation\n");
-               /* WMI needs to impersonate us, because it normally runs as an
-                  unprivileged user and needs our authority in order to access
-                  device files and so forth.  Turn impersonation on. */
-               hres = CoSetProxyBlanket(
-                       wmi->mpXSSvc,                  // the proxy to set
-                       RPC_C_AUTHN_WINNT,           /* LAN manager authentication,
-                                                                                       although it doesn't really
-                                                                                       matter on localhost. */
-                       RPC_C_AUTHZ_NONE,            // LANMAN can't do much authorization.
-                       NULL,                        // Server principal name
-                       RPC_C_AUTHN_LEVEL_CALL,      // Do authentication on every call
-                       RPC_C_IMP_LEVEL_IMPERSONATE, // Allow full impersonation.
-                       NULL,                        // Use current client identity
-                       EOAC_NONE                    // No extended proxy capabilities
-               );
-               if (FAILED(hres)) {
-                       goto err_out;
-               }
-
-
-       OutputDebugString("Wmi connected\n");
+        InitCom();
+        HRESULT hres;
+        OutputDebugString("Connect to WMI");
+        wmicount++;
+
+        wmi = (struct WMIAccessor *)XsAlloc(sizeof(*wmi));
+        if (wmi == NULL) {
+            return false;
+        }
+        memset(wmi, 0, sizeof(*wmi));
+
+
+        OutputDebugString("Connect Server\n");
+        try {
+            hres = locator->ConnectServer(
+                L"root\\CIMV2",          // WMI namespace
+                NULL,                    // User name
+                NULL,                    // User password
+                NULL,                    // Locale
+                0,                       // Security flags
+                NULL,                    // Authority
+                NULL,                    // Context object
+                &(wmi->mpSvc)              // IWbemServices proxy
+                );
+        }
+        catch(...) {
+            OutputDebugString("Exception connecting to server\n");
+            goto err_out;
+        }
+
+        OutputDebugString("Check result\n");
+        if (FAILED(hres)) {
+            goto err_out;
+        }
+        /* WMI needs to impersonate us, because it normally runs as an
+           unprivileged user and needs our authority in order to access
+           device files and so forth.  Turn impersonation on. */
+        OutputDebugString("Proxy blanket\n");
+        hres = CoSetProxyBlanket(
+            wmi->mpSvc,                  // the proxy to set
+            RPC_C_AUTHN_WINNT,           /* LAN manager authentication,
+                                            although it doesn't really
+                                            matter on localhost. */
+            RPC_C_AUTHZ_NONE,            // LANMAN can't do much authorization.
+            NULL,                        // Server principal name
+            RPC_C_AUTHN_LEVEL_CALL,      // Do authentication on every call
+            RPC_C_IMP_LEVEL_IMPERSONATE, // Allow full impersonation.
+            NULL,                        // Use current client identity
+            EOAC_NONE                    // No extended proxy capabilities
+        );
+        if (FAILED(hres)) {
+            goto err_out;
+        }
+        OutputDebugString("WMI Server\n");
+        hres = locator->ConnectServer(
+            L"root\\WMI",          // WMI namespace
+            NULL,                    // User name
+            NULL,                    // User password
+            NULL,                    // Locale
+            0,                       // Security flags
+            NULL,                    // Authority
+            NULL,                    // Context object
+            &wmi->mpXSSvc              // IWbemServices proxy
+            );
+
+        if (FAILED(hres)) {
+            goto err_out;
+        }
+        OutputDebugString("Impersonation\n");
+        /* WMI needs to impersonate us, because it normally runs as an
+           unprivileged user and needs our authority in order to access
+           device files and so forth.  Turn impersonation on. */
+        hres = CoSetProxyBlanket(
+            wmi->mpXSSvc,                  // the proxy to set
+            RPC_C_AUTHN_WINNT,           /* LAN manager authentication,
+                                            although it doesn't really
+                                            matter on localhost. */
+            RPC_C_AUTHZ_NONE,            // LANMAN can't do much authorization.
+            NULL,                        // Server principal name
+            RPC_C_AUTHN_LEVEL_CALL,      // Do authentication on every call
+            RPC_C_IMP_LEVEL_IMPERSONATE, // Allow full impersonation.
+            NULL,                        // Use current client identity
+            EOAC_NONE                    // No extended proxy capabilities
+        );
+        if (FAILED(hres)) {
+            goto err_out;
+        }
+
+
+    OutputDebugString("Wmi connected\n");
     /* All done. */
     return true;
 
 err_out:
-       OutputDebugString("WMI connection failed\n");
+    OutputDebugString("WMI connection failed\n");
     ReleaseWMIAccessor(&wmi);
     return false;
 }
@@ -541,15 +541,15 @@ err_out:
 
 void ReleaseCom(void) {
 
-       if (com_initialized) {
-               OutputDebugString("Release locator\n");
-               locator->Release();
-               //XsLog("Wmi disconnect thread %p", GetCurrentThread());
+    if (com_initialized) {
+        OutputDebugString("Release locator\n");
+        locator->Release();
+        //XsLog("Wmi disconnect thread %p", GetCurrentThread());
         //ASSERT((*wmi)->owning_thread == GetCurrentThread());
-               com_initialized = 0;
-               OutputDebugString("Uninitialize com\n");
+        com_initialized = 0;
+        OutputDebugString("Uninitialize com\n");
         CoUninitialize();
-               
+        
     }
 }
 
@@ -557,10 +557,10 @@ void ReleaseCom(void) {
    allocated them. */
 void ReleaseWMIAccessor(struct WMIAccessor **wmi)
 {
-       OutputDebugString("Should I release wmi?\n");
+    OutputDebugString("Should I release wmi?\n");
     if (*wmi == NULL)
         return;
-       OutputDebugString("Get rid of WMI servers\n");
+    OutputDebugString("Get rid of WMI servers\n");
     if ((*wmi)->mpXSSvc != NULL)
         (*wmi)->mpXSSvc->Release();
     if ((*wmi)->mpSvc != NULL)
@@ -569,9 +569,9 @@ void ReleaseWMIAccessor(struct WMIAccessor **wmi)
     /* Poison wmi to make use-after-free()s a bit more obvious. */
     memset((*wmi), 0xab, sizeof(**wmi));
     XsFree(*wmi);
-       *wmi = NULL;
-       ReleaseCom();
-       OutputDebugString("Released WMI\n");
+    *wmi = NULL;
+    ReleaseCom();
+    OutputDebugString("Released WMI\n");
 }
 
 /* The fact that something is documented as being a uint64_t field
@@ -733,21 +733,21 @@ public:
 IWbemClassObject *getBase(WMIAccessor** wmi) 
 {
     IWbemClassObject* base = getObject(wmi, L"CitrixXenStoreBase");
-       if (base == NULL) {
-               *wmi = NULL;
-               return NULL;
-       }
-       return base;
+    if (base == NULL) {
+        *wmi = NULL;
+        return NULL;
+    }
+    return base;
 }
 
 IWbemClassObject *getBaseClass(WMIAccessor** wmi) 
 {
     IWbemClassObject* baseclass =  getClass(wmi, L"CitrixXenStoreBase");
-       if (baseclass == NULL) {
-               *wmi = NULL;
-               return NULL;
-       }
-       return baseclass;
+    if (baseclass == NULL) {
+        *wmi = NULL;
+        return NULL;
+    }
+    return baseclass;
 }
 
 ULONGLONG get64BitUnsigned(VARIANT *var) {
@@ -772,7 +772,7 @@ ULONGLONG get64BitUnsigned(VARIANT *var) {
 FILETIME WmiGetXenTime(WMIAccessor **wmi) {
      FILETIME out;
      
-        IWbemClassObject *base = getBase(wmi);
+     IWbemClassObject *base = getBase(wmi);
      if (base == NULL) {
          DBGPRINT(("Unable to find base WMI session\n"));
          goto getbasefailed;
@@ -780,13 +780,13 @@ FILETIME WmiGetXenTime(WMIAccessor **wmi) {
 
      VARIANT timevar;
      BSTR timename = mkBstr("XenTime", 7);
-        if (timename == NULL)
-                goto buildtimenamefailed;
-                
+     if (timename == NULL)
+         goto buildtimenamefailed;
+         
 
 
      if (FAILED(base->Get(timename, 0, &timevar, NULL, NULL)))
-                goto gettimefailed;
+         goto gettimefailed;
 
      ULONGLONG time =get64BitUnsigned(&timevar);;
 
@@ -797,7 +797,7 @@ FILETIME WmiGetXenTime(WMIAccessor **wmi) {
 gettimefailed:
 buildtimenamefailed:
 getbasefailed:
-        out.dwLowDateTime = 0;
+     out.dwLowDateTime = 0;
      out.dwHighDateTime = 0;
      return out ;
 }
@@ -807,8 +807,8 @@ IWbemClassObject *openSession(WMIAccessor** wmi, const char *sessionname)
     HRESULT hres;
 
     BSTR query = formatBstr("SELECT * FROM CitrixXenStoreSession WHERE Id=\"Citrix Xen Win32 Service : %s\"", sessionname);
-       if (query == NULL)
-               goto formatsessionbstrfailed;
+    if (query == NULL)
+        goto formatsessionbstrfailed;
 
     IEnumWbemClassObject * sessions = runXSQuery(wmi, query);
     SysFreeString(query);
@@ -817,13 +817,13 @@ IWbemClassObject *openSession(WMIAccessor** wmi, const char *sessionname)
         IWbemClassObject *returnedObject;
         ULONG count;
         hres = sessions->Next(WBEM_INFINITE, 1, &returnedObject, &count);
-               sessions->Release();
+        sessions->Release();
 
         if (count>0) {
             if (sessionname !=NULL ) {
                 if (!WmiSessionEnd(wmi, returnedObject)) {
-                                       return NULL;
-                               }
+                    return NULL;
+                }
             }
             else {
                 return returnedObject;
@@ -839,91 +839,91 @@ IWbemClassObject *openSession(WMIAccessor** wmi, const char *sessionname)
 
     IWbemClassObject *baseclass = getBaseClass(wmi);
 
-       if (baseclass == NULL)
-               goto getbaseclassfailed;
+    if (baseclass == NULL)
+        goto getbaseclassfailed;
 
     IWbemClassObject *inMethod;
 
     IWbemClassObject *inMethodInst;
     IWbemClassObject *outMethodInst;
     if (FAILED(baseclass->GetMethod(L"AddSession",0,&inMethod, NULL)))
-               goto getmethodaddsessionfailed;
+        goto getmethodaddsessionfailed;
 
     if (FAILED(inMethod->SpawnInstance(0, &inMethodInst)))
-               goto inmethodspawnfailed;
+        goto inmethodspawnfailed;
 
     VARIANT var;
     var.vt = VT_BSTR;
     var.bstrVal=formatBstr("Citrix Xen Win32 Service : %s", sessionname);
 
-       if (var.bstrVal == NULL)
-               goto formatnamebstrfailed;
+    if (var.bstrVal == NULL)
+        goto formatnamebstrfailed;
 
     if (FAILED(inMethodInst->Put(L"Id", 0, &var, 0)))
-               goto methodputfailed;
+        goto methodputfailed;
 
     if (FAILED(methodExec(wmi, base, L"AddSession", inMethodInst, &outMethodInst)))
-               goto methodexecaddsessionfailed;
+        goto methodexecaddsessionfailed;
     
     if (FAILED(outMethodInst->Get(L"SessionId", 0, &var, NULL, NULL)))
-               goto outmethodgetfailed;
+        goto outmethodgetfailed;
 
     ULONG query_len;
     query_len = strlen("SELECT * FROM CitrixXenStoreSession WHERE SessionId=")+10;
     query = SysAllocStringLen(NULL, query_len);
 
-       if (query == NULL)
-               goto allocqueryfailed;
+    if (query == NULL)
+        goto allocqueryfailed;
 
     swprintf_s(query,query_len, L"SELECT * FROM CitrixXenStoreSession WHERE SessionId=%d", var.uintVal);
 
     sessions = runXSQuery(wmi, query );
-       SysFreeString(query);
+    SysFreeString(query);
 
     if (sessions) {
         IWbemClassObject *returnedObject;
         ULONG count;
         hres = sessions->Next(WBEM_INFINITE, 1, &returnedObject, &count);
-               sessions->Release();
+        sessions->Release();
         if (count>0) {
             return returnedObject;
         }
         
     }
-       
-       outMethodInst->Release();
-       VariantClear(&var);
-       inMethodInst->Release();
-       inMethod->Release();
+    
+    outMethodInst->Release();
+    VariantClear(&var);
+    inMethodInst->Release();
+    inMethod->Release();
     base->Release();
-       baseclass->Release();
+    baseclass->Release();
     return NULL;
 
 allocqueryfailed:
 outmethodgetfailed:
-       outMethodInst->Release();
+    outMethodInst->Release();
 
 methodexecaddsessionfailed:
 methodputfailed:
-       VariantClear(&var);
+    VariantClear(&var);
 
 formatnamebstrfailed:
-       inMethodInst->Release();
+    inMethodInst->Release();
 inmethodspawnfailed:
-       inMethod->Release();
+    inMethod->Release();
 
 
 getmethodaddsessionfailed:
-       baseclass->Release();
+    baseclass->Release();
 
 getbaseclassfailed:
-       base->Release();
+    base->Release();
 
 getbasefailed:
 
 
 formatsessionbstrfailed:
-       return NULL;
+    return NULL;
 }
 
 IWbemClassObject* sessionMethodStart(WMIAccessor**wmi,  
@@ -932,33 +932,33 @@ IWbemClassObject* sessionMethodStart(WMIAccessor**wmi,
     IWbemClassObject *inMethod;
     IWbemClassObject *inMethodInst = NULL;
     IWbemClassObject *sessionClass;
-       HRESULT hr;
+    HRESULT hr;
 
-       ASSERT(wmi != NULL);
+    ASSERT(wmi != NULL);
 
     sessionClass = getClass(wmi, L"CitrixXenStoreSession");
-       if (sessionClass == NULL)
-               goto getclassfailed;
+    if (sessionClass == NULL)
+        goto getclassfailed;
 
     hr = sessionClass->GetMethod(methodname,0,&inMethod, NULL);
-       if (FAILED(hr))
-               goto getmethodfailed;
+    if (FAILED(hr))
+        goto getmethodfailed;
 
     hr = inMethod->SpawnInstance(0, &inMethodInst);
-       if (FAILED(hr))
-               goto spawninstancefailed;
+    if (FAILED(hr))
+        goto spawninstancefailed;
 
-       inMethod->Release();
+    inMethod->Release();
 
-       sessionClass->Release();
-       return inMethodInst;
+    sessionClass->Release();
+    return inMethodInst;
 
 
 spawninstancefailed:
-       inMethod->Release();
-       
+    inMethod->Release();
+    
 getmethodfailed:
-       sessionClass->Release();
+    sessionClass->Release();
 
 getclassfailed:
     return NULL;
@@ -968,7 +968,7 @@ getclassfailed:
 char * bstrToChar(BSTR bst, size_t *len) {
     *len = wcslen(bst);
     char *space = (char *)XsAlloc(*len+1);
-       if (space)
+    if (space)
         wcstombs_s(len, space, *len+1, bst,  _TRUNCATE);
     return space;
 }
@@ -978,10 +978,10 @@ void WmiSessionLog(WMIAccessor** wmi,  void **sessionhandle,const char *fmt, va_
     
     char* message = formatCharStrInt(fmt,args);
     
-       OutputDebugString(message);
-       if (((*wmi)==NULL) || ((*sessionhandle)==NULL) ) {
-               goto nowmi;
-       }
+    OutputDebugString(message);
+    if (((*wmi)==NULL) || ((*sessionhandle)==NULL) ) {
+        goto nowmi;
+    }
     VARIANT vmessage;
     if (setVariantString(&vmessage, message))
         goto setvmessage;
@@ -991,14 +991,14 @@ void WmiSessionLog(WMIAccessor** wmi,  void **sessionhandle,const char *fmt, va_
         goto sessionstart;
     
      if (FAILED(inMethodInst->Put(L"Message",0,&vmessage,0)))
-                goto methodputfailed;
+         goto methodputfailed;
 
      if (FAILED(methodExec(wmi,*session, L"Log", inMethodInst, NULL)))
-                goto methodexecfailed;
+         goto methodexecfailed;
 
 methodexecfailed:
 methodputfailed:
-        inMethodInst->Release();
+     inMethodInst->Release();
 
 sessionstart:
     VariantClear(&vmessage);
@@ -1021,11 +1021,11 @@ char* WmiSessionGetEntry(WMIAccessor** wmi, void **sessionhandle,
     IWbemClassObject *outMethodInst;
 
     IWbemClassObject *inMethodInst = sessionMethodStart( wmi, L"GetValue");
-       if (inMethodInst == NULL) 
-               goto sessionmethodstartfailed;
+    if (inMethodInst == NULL) 
+        goto sessionmethodstartfailed;
     
-       if (FAILED(inMethodInst->Put(L"PathName",0,&vpath,0))) 
-               goto methodexecfailed;
+    if (FAILED(inMethodInst->Put(L"PathName",0,&vpath,0))) 
+        goto methodexecfailed;
 
     methodExec(wmi,*session, L"GetValue", inMethodInst, &outMethodInst);
     if (outMethodInst==NULL)
@@ -1035,7 +1035,7 @@ char* WmiSessionGetEntry(WMIAccessor** wmi, void **sessionhandle,
     VariantInit(&outval);
 
     if (FAILED(outMethodInst->Get(L"value", 0, &outval, NULL, NULL)))
-               goto methodgetfailed;
+        goto methodgetfailed;
 
     char *space = NULL;
     
@@ -1044,21 +1044,21 @@ char* WmiSessionGetEntry(WMIAccessor** wmi, void **sessionhandle,
         space = bstrToChar(outval.bstrVal, len);
     }
 
-       outMethodInst->Release();
-       inMethodInst->Release();
-       VariantClear(&vpath);
+    outMethodInst->Release();
+    inMethodInst->Release();
+    VariantClear(&vpath);
     VariantClear(&outval); 
     return space;
 
 methodgetfailed:
-       outMethodInst->Release();
+    outMethodInst->Release();
 
 methodexecfailed:
 sessionExec:
-       inMethodInst->Release();
+    inMethodInst->Release();
 
 sessionmethodstartfailed:
-       VariantClear(&vpath);
+    VariantClear(&vpath);
 
 setvpath:
     return NULL;
@@ -1088,12 +1088,12 @@ int WmiSessionSetEntry(WMIAccessor** wmi,  void **sessionhandle,
     inMethodInst->Put(L"value",0,&vvalue,0);
 
     if (FAILED(methodExec(wmi,*session, L"SetValue", inMethodInst, &outMethodInst)))
-               goto methodexecfailed;
+        goto methodexecfailed;
 
     if (outMethodInst!=NULL) 
         outMethodInst->Release();
 
-       inMethodInst->Release();
+    inMethodInst->Release();
     SysFreeString(vvalue.bstrVal);
     SysFreeString(vpath.bstrVal);
 
@@ -1101,7 +1101,7 @@ int WmiSessionSetEntry(WMIAccessor** wmi,  void **sessionhandle,
 
 methodexecfailed:
     XsLog("WmiSessionSetEntry:MethodExec Failed");
-       inMethodInst->Release();
+    inMethodInst->Release();
 
 sessionstart:
     XsLog("WmiSessionSetEntry:SessionStart Failed");
@@ -1136,12 +1136,12 @@ int WmiSessionRemoveEntry(WMIAccessor** wmi,  void **sessionhandle,
         goto sessionstart;
 
     if (FAILED(inMethodInst->Put(L"PathName",0,&vpath,0)))
-               goto methodputfailed;
+        goto methodputfailed;
 
     IWbemClassObject* outMethodInst;
 
     if (FAILED(methodExec(wmi,*session, L"RemoveValue", inMethodInst, &outMethodInst)))
-               goto methodexecfailed;
+        goto methodexecfailed;
 
     if (outMethodInst==NULL)
         goto sessionExec;
@@ -1150,7 +1150,7 @@ int WmiSessionRemoveEntry(WMIAccessor** wmi,  void **sessionhandle,
     err=0;
 methodexecfailed:
 methodputfailed:
-       inMethodInst->Release();
+    inMethodInst->Release();
 
 sessionstart:
     VariantClear(&vpath);
@@ -1164,7 +1164,7 @@ setvpath:
 BOOL WmiSessionUnwatch(WMIAccessor** wmi,  void **sessionhandle,
                          void *watchhandle) {
     IWbemClassObject **session = (IWbemClassObject **)sessionhandle;
-       XsLog("Unwatch %p",watchhandle);
+    XsLog("Unwatch %p",watchhandle);
     WatchSink * sink = (WatchSink *)watchhandle;
 
     VARIANT vpath;
@@ -1178,7 +1178,7 @@ BOOL WmiSessionUnwatch(WMIAccessor** wmi,  void **sessionhandle,
 
     inMethodInst->Put(L"PathName",0,&vpath,0);
     if FAILED(methodExec(wmi,*session, L"RemoveWatch", inMethodInst, &outMethodInst))
-               goto methodexecfailed;
+        goto methodexecfailed;
     if (outMethodInst==NULL)
         goto sessionexecfailed;
 
@@ -1191,36 +1191,36 @@ sessionexecfailed:
 sessionstart:
 setvpath:
     sink->Release();
-       return true;
+    return true;
 }
 
 BOOL WmiSessionStart(WMIAccessor** wmi,  void **sessionhandle, const char* sessionname) 
 {
     IWbemClassObject **session = (IWbemClassObject **)sessionhandle;
     if ((*session = openSession(wmi, sessionname)) == NULL) {
-               return false;
-       }
-       return true;
+        return false;
+    }
+    return true;
 }
 
 
 BOOL WmiSessionEnd(WMIAccessor** wmi,  void *sessionhandle) 
 {
-       HRESULT hr;
-       ASSERT(*wmi != NULL);
+    HRESULT hr;
+    ASSERT(*wmi != NULL);
 
     IWbemClassObject *session = (IWbemClassObject *)sessionhandle;
     if (session==NULL) {
         return false;
     }
     hr = methodExec(wmi, session, L"EndSession", NULL,NULL);
-       if FAILED(hr)
-               goto execmethodfailed;
+    if FAILED(hr)
+        goto execmethodfailed;
     session->Release();
-       return true;
+    return true;
 
 execmethodfailed:
-       return false;
+    return false;
 
 }
 
@@ -1231,20 +1231,20 @@ void *WmiSessionWatch(WMIAccessor** wmi,  void **sessionhandle,
 
     IWbemClassObject **session = (IWbemClassObject **)sessionhandle;
     
-       ASSERT((*wmi) != NULL);
-       ASSERT((*sessionhandle) != NULL);
+    ASSERT((*wmi) != NULL);
+    ASSERT((*sessionhandle) != NULL);
 
     WatchSink * sink = new WatchSink(event, errorevent, path);
     BSTR query=formatBstr("SELECT * from CitrixXenStoreWatchEvent WHERE EventId=\"%s\"", path);
-       if (query == NULL) {
-               goto formatstringfailed;
-       }
+    if (query == NULL) {
+        goto formatstringfailed;
+    }
 
-       hr = (*wmi)->mpXSSvc->ExecNotificationQueryAsync(L"WQL", query,0,NULL, sink);
+    hr = (*wmi)->mpXSSvc->ExecNotificationQueryAsync(L"WQL", query,0,NULL, sink);
     if (FAILED(hr)){
-               *wmi = NULL;
-               goto wmifailed;
-       }
+        *wmi = NULL;
+        goto wmifailed;
+    }
 
     VARIANT vpath;
     if (setVariantString(&vpath, path)){
@@ -1257,61 +1257,61 @@ void *WmiSessionWatch(WMIAccessor** wmi,  void **sessionhandle,
         goto sessionstart;
 
     hr = inMethodInst->Put(L"PathName",0,&vpath,0);
-       if (FAILED(hr))
-               goto methodputfailed;
+    if (FAILED(hr))
+        goto methodputfailed;
 
     hr = methodExec(wmi,*session, L"SetWatch", inMethodInst, NULL);
-       if (FAILED(hr))
-               goto methodexecfailed;
+    if (FAILED(hr))
+        goto methodexecfailed;
 
-       VariantClear(&vpath);
+    VariantClear(&vpath);
 
-       SysFreeString(query);
+    SysFreeString(query);
 
-       return sink;
+    return sink;
 
 
 methodexecfailed:
-       OutputDebugString(__FUNCTION__ " : methodexecfailed\n");
+    OutputDebugString(__FUNCTION__ " : methodexecfailed\n");
 methodputfailed:
-       OutputDebugString(__FUNCTION__ " : methodputfailed\n");
-       inMethodInst->Release();
+    OutputDebugString(__FUNCTION__ " : methodputfailed\n");
+    inMethodInst->Release();
 sessionstart:
-       OutputDebugString(__FUNCTION__ " : sessionstart\n");
-       VariantClear(&vpath);
+    OutputDebugString(__FUNCTION__ " : sessionstart\n");
+    VariantClear(&vpath);
 setvpath:
-       OutputDebugString(__FUNCTION__ " : setvpath\n");
+    OutputDebugString(__FUNCTION__ " : setvpath\n");
 wmifailed:
-       SysFreeString(query);
+    SysFreeString(query);
 formatstringfailed:
-       OutputDebugString(__FUNCTION__ " : formatstringfailed\n");
-       delete sink;
+    OutputDebugString(__FUNCTION__ " : formatstringfailed\n");
+    delete sink;
     return NULL;
 }
 
 void *WmiUnsuspendedEventWatch(WMIAccessor **wmi, HANDLE event, HANDLE errorevent) 
 {
-       HRESULT hr;
+    HRESULT hr;
 
-       ASSERT(*wmi != NULL);
+    ASSERT(*wmi != NULL);
 
     WatchSink * sink = new WatchSink(event, errorevent, NULL);
     BSTR query=formatBstr("SELECT * from CitrixXenStoreUnsuspendedEvent");
-       if (query==NULL) {
-               goto formatstringfailed;
-       }
+    if (query==NULL) {
+        goto formatstringfailed;
+    }
 
     hr = (*wmi)->mpXSSvc->ExecNotificationQueryAsync(L"WQL", query,0,NULL, sink);
-       if FAILED(hr)
-               goto asyncqueryfailed;
+    if FAILED(hr)
+        goto asyncqueryfailed;
 
-       SysFreeString(query);
+    SysFreeString(query);
     return sink;
 
 asyncqueryfailed:
-       SysFreeString(query);
+    SysFreeString(query);
 formatstringfailed:
-       delete sink;
-       return NULL;
+    delete sink;
+    return NULL;
 }
 
index b6f74b32005cf424b7e690150051bac84ce9c17d..da730aef57d9508d033a7138cd7ace4ab42aec8d 100644 (file)
@@ -87,20 +87,20 @@ BOOL InitXSAccessor()
 {
     OutputDebugString("XSAccessor\n");
     if (wmicount != localwmicount) {
-               
+        
         if (localthreadcount == 0) {
             localthreadcount = InterlockedIncrement(&threadcount);
         }
         char wminame[12];
         _snprintf(wminame, 12, "XS%x", localthreadcount);
         if (WmiSessionStart(&wmi, &WmiSessionHandle, wminame)) {
-                       localwmicount = wmicount;
-                       return true;
-               }
-               OutputDebugString("XSAccessor Failed\n");
-               return false;
+            localwmicount = wmicount;
+            return true;
+        }
+        OutputDebugString("XSAccessor Failed\n");
+        return false;
     }
-       return true;
+    return true;
 }
 
 void XsLog(const char *fmt, ...)
@@ -115,12 +115,12 @@ void XsLog(const char *fmt, ...)
 
 BOOL ShutdownXSAccessor(void)
 {
-       if (wmi == NULL) {
-               return false;
-       }
-       if (WmiSessionHandle == NULL) {
-               return false;
-       }
+    if (wmi == NULL) {
+        return false;
+    }
+    if (WmiSessionHandle == NULL) {
+        return false;
+    }
     return WmiSessionEnd(&wmi, WmiSessionHandle);
 
 }
@@ -138,7 +138,7 @@ int XenstorePrintf(const char *path, const char *fmt, ...)
         DBGPRINT (("Cannot format data for XenstorePrintf!"));
         return -1;
     }
-       OutputDebugString(buf);
+    OutputDebugString(buf);
     /* Now have the thing we're trying to write. */
     return WmiSessionSetEntry(&wmi, &WmiSessionHandle, path, buf);
 }
@@ -148,26 +148,26 @@ BOOL XenstoreKickXapi()
     /* New protocol */
     if (XenstorePrintf("data/update_cnt", "%I64d", update_cnt)){
         XsLog("New kick failed ");
-               return false;
+        return false;
     }
     /* Old protocol */
     if (WmiSessionSetEntry(&wmi, &WmiSessionHandle, "data/updated", "1")){
         XsLog("Old kick failed");
-               return false;
+        return false;
     }
     update_cnt++;
-       return true;
+    return true;
 }
 
 
 int
 XenstoreRemove(const char *path)
 {
-       if (wmi == NULL)
-               return -1;
+    if (wmi == NULL)
+        return -1;
 
-       if (WmiSessionHandle == NULL)
-               return -1;
+    if (WmiSessionHandle == NULL)
+        return -1;
 
     if (WmiSessionRemoveEntry(&wmi, &WmiSessionHandle, path))
         return -1;
@@ -190,14 +190,14 @@ void *
 XenstoreWatch(const char *path, HANDLE event, HANDLE errorevent)
 {
  
-       if (wmi == NULL) {
-               OutputDebugString("WMI is null\n");
-               return NULL;
-       }
-       if (WmiSessionHandle == NULL) {
-               OutputDebugString("Session is null\n");
-               return NULL;
-       }
+    if (wmi == NULL) {
+        OutputDebugString("WMI is null\n");
+        return NULL;
+    }
+    if (WmiSessionHandle == NULL) {
+        OutputDebugString("Session is null\n");
+        return NULL;
+    }
     return WmiSessionWatch(&wmi, &WmiSessionHandle, path, event, errorevent);
 }
 
index e58ed3ad04015a1237322ea4493b2ccc702bd81a..f15889e7a08a26550a26d6f84d96a5ba14dbd4f4 100644 (file)
@@ -73,31 +73,31 @@ static void GetWindowsVersion();
 
 void PrintError(const char *func, DWORD err)
 {
-       LPVOID lpMsgBuf;
-       FormatMessage(
-               FORMAT_MESSAGE_ALLOCATE_BUFFER |
-               FORMAT_MESSAGE_FROM_SYSTEM,
-               NULL,
-               err,
-               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-               (LPTSTR) &lpMsgBuf,
-               0,
-               NULL);
-       OutputDebugString((LPTSTR)lpMsgBuf);
+    LPVOID lpMsgBuf;
+    FormatMessage(
+        FORMAT_MESSAGE_ALLOCATE_BUFFER |
+        FORMAT_MESSAGE_FROM_SYSTEM,
+        NULL,
+        err,
+        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+        (LPTSTR) &lpMsgBuf,
+        0,
+        NULL);
+    OutputDebugString((LPTSTR)lpMsgBuf);
     XenstorePrintf("control/error", "%s failed: %s (%x)", func, lpMsgBuf, err);
-       LocalFree(lpMsgBuf);
+    LocalFree(lpMsgBuf);
 }
 
 void PrintError(const char *func)
 {
-       PrintError(func, GetLastError());
+    PrintError(func, GetLastError());
 }
 
 void PrintUsage()
 {
-       printf("Usage: xenservice [-u]\n");
+    printf("Usage: xenservice [-u]\n");
 
-       printf("\t -u: uninstall service\n");
+    printf("\t -u: uninstall service\n");
 }
 
 
@@ -142,7 +142,7 @@ EstablishWatch(const char *path, HANDLE errorevent)
 {
     struct watch_event *we;
     DWORD err;
-       XsLog("Establish watch %s",path);
+    XsLog("Establish watch %s",path);
     we = (struct watch_event *)malloc(sizeof(*we));
     if (!we) {
         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@@ -154,7 +154,7 @@ EstablishWatch(const char *path, HANDLE errorevent)
     if (we->event != INVALID_HANDLE_VALUE)
         we->watch = XenstoreWatch(path, we->event, errorevent);
     if (we->watch == NULL) {
-               OutputDebugString("Watch is null\n");
+        OutputDebugString("Watch is null\n");
         err = GetLastError();
         ReleaseWatch(we);
         SetLastError(err);
@@ -199,7 +199,7 @@ AddFeature(struct watch_feature_set *wfs, const char *path,
     if (wfs->features[n].name == NULL)
         goto failname;
     wfs->nr_features++;
-       return true;
+    return true;
 
 failname:
     PrintError("Failed to allocate string");
@@ -212,14 +212,14 @@ failfeatures:
 }
 
 static void RemoveFeatures(struct watch_feature_set *wfs) {
-       unsigned x;
+    unsigned x;
     for (x = 0; x < wfs->nr_features; x++) {
-               ReleaseWatch(wfs->features[x].watch);
-               wfs->features[x].watch = NULL;
+        ReleaseWatch(wfs->features[x].watch);
+        wfs->features[x].watch = NULL;
         FreeString(wfs->features[x].name);
-               XenstoreRemove(wfs->features[x].feature_flag);
-       }
-       wfs->nr_features = 0;
+        XenstoreRemove(wfs->features[x].feature_flag);
+    }
+    wfs->nr_features = 0;
 }
 
 static BOOL
@@ -232,44 +232,44 @@ AdvertiseFeatures(struct watch_feature_set *wfs)
                 XsLog("Failed to advertise %s",wfs->features[x].name);
             }
     }
-       return true;
+    return true;
 }
 
 
 void ServiceUninstall()
 {
-       SC_HANDLE   hSvc;
-       SC_HANDLE   hMgr;
-       
-       hMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
-
-       if ( hMgr )
-       {
-               hSvc = OpenService(hMgr, SVC_NAME, SERVICE_ALL_ACCESS);
-
-               if (hSvc)
-               {
-                        // try to stop the service
-                        if ( ControlService( hSvc, SERVICE_CONTROL_STOP, &ServiceStatus ) )
-                        {
-                               printf("Stopping %s.", SVC_DISPLAYNAME);
-                               Sleep( 1000 );
-
-                               while ( QueryServiceStatus( hSvc, &ServiceStatus ) )
-                               {
-                                       if ( ServiceStatus.dwCurrentState == SERVICE_STOP_PENDING )
-                                       {
-                                               printf(".");
-                                               Sleep( 1000 );
-                                       }
-                                       else
-                                               break;
-                               }
-
-                               if ( ServiceStatus.dwCurrentState == SERVICE_STOPPED )
-                                       printf("\n%s stopped.\n", SVC_DISPLAYNAME );
-                               else
-                                       printf("\n%s failed to stop.\n", SVC_DISPLAYNAME );
+    SC_HANDLE   hSvc;
+    SC_HANDLE   hMgr;
+    
+    hMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+
+    if ( hMgr )
+    {
+        hSvc = OpenService(hMgr, SVC_NAME, SERVICE_ALL_ACCESS);
+
+        if (hSvc)
+        {
+             // try to stop the service
+             if ( ControlService( hSvc, SERVICE_CONTROL_STOP, &ServiceStatus ) )
+             {
+                printf("Stopping %s.", SVC_DISPLAYNAME);
+                Sleep( 1000 );
+
+                while ( QueryServiceStatus( hSvc, &ServiceStatus ) )
+                {
+                    if ( ServiceStatus.dwCurrentState == SERVICE_STOP_PENDING )
+                    {
+                        printf(".");
+                        Sleep( 1000 );
+                    }
+                    else
+                        break;
+                }
+
+                if ( ServiceStatus.dwCurrentState == SERVICE_STOPPED )
+                    printf("\n%s stopped.\n", SVC_DISPLAYNAME );
+                else
+                    printf("\n%s failed to stop.\n", SVC_DISPLAYNAME );
          }
 
          // now remove the service
@@ -299,28 +299,28 @@ WinMain(HINSTANCE hInstance, HINSTANCE ignore,
     local_hinstance = hInstance;
 
     if (strlen(lpCmdLine) == 0) {
-               SERVICE_TABLE_ENTRY ServiceTable[2];
-               ServiceTable[0].lpServiceName = SVC_NAME;
-               ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
-
-               ServiceTable[1].lpServiceName = NULL;
-               ServiceTable[1].lpServiceProc = NULL;
-
-               DBGPRINT(("XenSvc: starting ctrl dispatcher "));
-
-               // Start the control dispatcher thread for our service
-               if (!StartServiceCtrlDispatcher(ServiceTable))
-               {
-                       int err = GetLastError();
-                       if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
-                       {
-                               DBGPRINT(("XenSvc: unable to start ctrl dispatcher - %d", GetLastError()));
-                       }
-               }
-               else
-               {
-                       // We get here when the service is shut down.
-               }
+        SERVICE_TABLE_ENTRY ServiceTable[2];
+        ServiceTable[0].lpServiceName = SVC_NAME;
+        ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
+
+        ServiceTable[1].lpServiceName = NULL;
+        ServiceTable[1].lpServiceProc = NULL;
+
+        DBGPRINT(("XenSvc: starting ctrl dispatcher "));
+
+        // Start the control dispatcher thread for our service
+        if (!StartServiceCtrlDispatcher(ServiceTable))
+        {
+            int err = GetLastError();
+            if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
+            {
+                DBGPRINT(("XenSvc: unable to start ctrl dispatcher - %d", GetLastError()));
+            }
+        }
+        else
+        {
+            // We get here when the service is shut down.
+        }
     } else if (!strcmp(lpCmdLine, "-u") || !strcmp(lpCmdLine, "\"-u\"")) {
         ServiceUninstall();
     } else {
@@ -359,45 +359,45 @@ static void AcquireSystemShutdownPrivilege(void)
 }
 
 enum XShutdownType {
-       XShutdownPoweroff,
-       XShutdownReboot,
-       XShutdownSuspend,
+    XShutdownPoweroff,
+    XShutdownReboot,
+    XShutdownSuspend,
     XShutdownS3
 };
 
 static BOOL maybeReboot(void *ctx)
 {
-       char *shutdown_type;
-       BOOL res;
-       enum XShutdownType type;
+    char *shutdown_type;
+    BOOL res;
+    enum XShutdownType type;
     int cntr = 0;
     HANDLE eventLog;
 
     XsLog("Check if we need to shutdown");
 
-       if (XenstoreRead("control/shutdown", &shutdown_type) < 0) {
+    if (XenstoreRead("control/shutdown", &shutdown_type) < 0) {
         XsLog("No need to shutdown");
-               return true;
+        return true;
+    }
+    XsLog("Shutdown type %s\n", shutdown_type);
+    if (strcmp(shutdown_type, "poweroff") == 0 ||
+        strcmp(shutdown_type, "halt") == 0) {
+        type = XShutdownPoweroff;
+    } else if (strcmp(shutdown_type, "reboot") == 0) {
+        type = XShutdownReboot;
+    } else if (strcmp(shutdown_type, "hibernate") == 0) {
+        type = XShutdownSuspend;
+    } else if (strcmp(shutdown_type, "s3") == 0) {
+        type = XShutdownS3;
+    } else {
+        DBGPRINT(("Bad shutdown type %s\n", shutdown_type));
+        goto out;
     }
-       XsLog("Shutdown type %s\n", shutdown_type);
-       if (strcmp(shutdown_type, "poweroff") == 0 ||
-           strcmp(shutdown_type, "halt") == 0) {
-               type = XShutdownPoweroff;
-       } else if (strcmp(shutdown_type, "reboot") == 0) {
-               type = XShutdownReboot;
-       } else if (strcmp(shutdown_type, "hibernate") == 0) {
-               type = XShutdownSuspend;
-       } else if (strcmp(shutdown_type, "s3") == 0) {
-               type = XShutdownS3;
-       } else {
-               DBGPRINT(("Bad shutdown type %s\n", shutdown_type));
-               goto out;
-       }
 
     XsLog("Report Shutdown Event");
-       /* We try to shutdown even if this fails, since it might work
-          and it can't do any harm. */
-       AcquireSystemShutdownPrivilege();
+    /* We try to shutdown even if this fails, since it might work
+       and it can't do any harm. */
+    AcquireSystemShutdownPrivilege();
 
     eventLog = RegisterEventSource(NULL, "xensvc");
     if (eventLog) {
@@ -424,10 +424,10 @@ static BOOL maybeReboot(void *ctx)
 
     XsLog("Do the shutdown");
 
-       /* do the shutdown */
-       switch (type) {
-       case XShutdownPoweroff:
-       case XShutdownReboot:
+    /* do the shutdown */
+    switch (type) {
+    case XShutdownPoweroff:
+    case XShutdownReboot:
         if (WindowsVersion >= 0x500 && WindowsVersion < 0x600)
         {
             /* Windows 2000 InitiateSystemShutdownEx is funny in
@@ -440,8 +440,8 @@ static BOOL maybeReboot(void *ctx)
                InitiateSystemShutdownEx behaves so badly. */
             /* If this is a legacy hal then use EWX_SHUTDOWN when shutting
                down instead of EWX_POWEROFF. */
-           /* Similar problem on XP. Shutdown/Reboot will hang until the Welcome
-               screen screensaver is dismissed by the guest */
+        /* Similar problem on XP. Shutdown/Reboot will hang until the Welcome
+        screen screensaver is dismissed by the guest */
 #pragma warning (disable : 28159)
             res = ExitWindowsEx((type == XShutdownReboot ? 
                                     EWX_REBOOT : 
@@ -455,13 +455,13 @@ static BOOL maybeReboot(void *ctx)
 #pragma warning (default: 28159)
             if (!res) {
                 PrintError("ExitWindowsEx");
-                               return false;
-                       }
+                return false;
+            }
             else
             {
-                               if (XenstoreRemove("control/shutdown"))
-                                       return false;
-                       }
+                if (XenstoreRemove("control/shutdown"))
+                    return false;
+            }
         } else {
 #pragma warning (disable : 28159)
             res = InitiateSystemShutdownEx(
@@ -476,46 +476,46 @@ static BOOL maybeReboot(void *ctx)
 #pragma warning (default: 28159)
             if (!res) {
                 PrintError("InitiateSystemShutdownEx");
-                               return false;
+                return false;
             } else {
                 if (XenstoreRemove("control/shutdown"))
-                                       return false;
+                    return false;
             }
         }
-               break;
-       case XShutdownSuspend:
+        break;
+    case XShutdownSuspend:
         if (XenstorePrintf ("control/hibernation-state", "started"))
-                       return false;
+            return false;
         /* Even if we think hibernation is disabled, try it anyway.
            It's not like it can do any harm. */
-               res = SetSystemPowerState(FALSE, FALSE);
+        res = SetSystemPowerState(FALSE, FALSE);
         if (XenstoreRemove ("control/shutdown"))
-               
-                       return false;   
-               }
+        { 
+            return false;    
+        }
         if (!res) {
             /* Tell the tools that we've failed. */
             PrintError("SetSystemPowerState");
             if (XenstorePrintf ("control/hibernation-state", "failed"))
-                               return false;
+                return false;
         }
-               break;
+        break;
     case XShutdownS3:
         if (XenstorePrintf ("control/s3-state", "started"))
-                       return false;
+            return false;
         res = SetSuspendState(FALSE, TRUE, FALSE);
         XenstoreRemove ("control/shutdown");
         if (!res) {
             PrintError("SetSuspendState");
             if (XenstorePrintf ("control/s3-state", "failed"))
-                               return false;
+                return false;
         }
         break;
-       }
+    }
 
 out:
-       XenstoreFree(shutdown_type);
-       return true;
+    XenstoreFree(shutdown_type);
+    return true;
 }
 
 /* We need to resync the clock when we recover from suspend/resume. */
@@ -528,10 +528,10 @@ finishSuspend(void)
 
     DBGPRINT(("Coming back from suspend.\n"));
     GetXenTime(&now);
-       if ((now.dwLowDateTime == 0) && (now.dwHighDateTime == 0)) {
-               XsLog("Cannot set system time to xentime, unable to contact WMI");
-               return;
-       }
+    if ((now.dwLowDateTime == 0) && (now.dwHighDateTime == 0)) {
+        XsLog("Cannot set system time to xentime, unable to contact WMI");
+        return;
+    }
     XsLog("Xen time is %I64x", now);
     if (!FileTimeToSystemTime(&now, &sys_time)) {
         PrintError("FileTimeToSystemTime()");
@@ -568,49 +568,49 @@ BOOL Run()
     struct watch_feature_set features;
     BOOL snap = FALSE;
 
-       OutputDebugString("Trying to connect to WMI\n");
-       while (!ConnectToWMI()) {
-               OutputDebugString("Unable to connect to WMI, sleeping\n");
-               if (WaitForSingleObject(hServiceExitEvent, 1000*10) == WAIT_OBJECT_0) {
-                       exit = true;
-                       return exit;
-               }
-       }
-       while (InitXSAccessor()==false) {
-               OutputDebugString("Unable to initialise WMI session, sleeping\n");
-               if (WaitForSingleObject(hServiceExitEvent, 1000*10) == WAIT_OBJECT_0) {
-                       exit = true;
-                       return exit;
-               }
-       }
+    OutputDebugString("Trying to connect to WMI\n");
+    while (!ConnectToWMI()) {
+        OutputDebugString("Unable to connect to WMI, sleeping\n");
+        if (WaitForSingleObject(hServiceExitEvent, 1000*10) == WAIT_OBJECT_0) {
+            exit = true;
+            return exit;
+        }
+    }
+    while (InitXSAccessor()==false) {
+        OutputDebugString("Unable to initialise WMI session, sleeping\n");
+        if (WaitForSingleObject(hServiceExitEvent, 1000*10) == WAIT_OBJECT_0) {
+            exit = true;
+            return exit;
+        }
+    }
     XsLog("Guest agent lite main loop starting");
 
     memset(&features, 0, sizeof(features));
 
-       HANDLE wmierrorEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+    HANDLE wmierrorEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
     if (!wmierrorEvent) {
         PrintError("CreateEvent() wmierrorEvent");
-               return exit;
+        return exit;
     }
    
 
     XsLog("About to add feature shutdown");
     if (!AddFeature(&features, "control/shutdown", "control/feature-shutdown", 
-                                       "shutdown", maybeReboot, NULL, wmierrorEvent)) {
-               return exit;
-       }
+                    "shutdown", maybeReboot, NULL, wmierrorEvent)) {
+        return exit;
+    }
 
     suspendEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
     if (!suspendEvent) {
         PrintError("CreateEvent() suspendEvent");
-               return exit;
+        return exit;
     }
-       
+    
     if (ListenSuspend(suspendEvent, wmierrorEvent) < 0) {
-               PrintError("ListenSuspend()");
-               CloseHandle(suspendEvent);
-               suspendEvent = NULL;
-               return exit;
+        PrintError("ListenSuspend()");
+        CloseHandle(suspendEvent);
+        suspendEvent = NULL;
+        return exit;
     }
 
 
@@ -618,7 +618,7 @@ BOOL Run()
     AdvertiseFeatures(&features);
     
     XsLog("About to kick xapi ");
-       XenstoreKickXapi();
+    XenstoreKickXapi();
 
     while (1)
     {
@@ -628,8 +628,8 @@ BOOL Run()
         unsigned x;
 
         handles[0] = hServiceExitEvent;
-               if (wmierrorEvent)
-                       handles[nr_handles++] = wmierrorEvent;
+        if (wmierrorEvent)
+            handles[nr_handles++] = wmierrorEvent;
         if (suspendEvent)
             handles[nr_handles++] = suspendEvent;
         for (x = 0; x < features.nr_features; x++)
@@ -653,7 +653,7 @@ BOOL Run()
             if (event == hServiceExitEvent)
             {
                 XsLog("service exit event");
-                               exit = true;
+                exit = true;
                 break;
             }
             else if (event == suspendEvent)
@@ -661,34 +661,34 @@ BOOL Run()
                 XsLog("Suspend event");
                 finishSuspend();
                 AdvertiseFeatures(&features);
-                               XenstoreKickXapi();
+                XenstoreKickXapi();
                 XsLog("Handled suspend event");
             }
-                       else if (event == wmierrorEvent)
-                       {
-                               break;
-                       }
+            else if (event == wmierrorEvent)
+            {
+                break;
+            }
             else
             {
-                               BOOL fail = false;
+                BOOL fail = false;
                 for (x = 0; x < features.nr_features; x++) {
                     if (features.features[x].watch->event == event) {
                         XsLog("Fire %p",features.features[x].name);
                         XsLog("fire feature %s", features.features[x].name);
-                                               OutputDebugString("Event triggered\n");
+                        OutputDebugString("Event triggered\n");
                         if (!(features.features[x].handler(features.features[x].ctx)))
-                                               {
+                        {
                             XsLog("Firing feature failed");
-                                                   PrintError("Feature failed");
-                                                   fail = true;
-                                               }
+                            PrintError("Feature failed");
+                            fail = true;
+                        }
                         XsLog("fired feature %s",
                                 features.features[x].name);
                     }
                 }
-                               if (fail) {
+                if (fail) {
                     XsLog("Resetting");
-                                       break;
+                    break;
                 }
             }
         }
@@ -698,9 +698,9 @@ BOOL Run()
             break;
         }
     }
-       OutputDebugString("WMI Watch loop terminated\n");
-       RemoveFeatures(&features);
-       XenstoreKickXapi();
+    OutputDebugString("WMI Watch loop terminated\n");
+    RemoveFeatures(&features);
+    XenstoreKickXapi();
 
     XsLog("Guest agent lite loop finishing");
     ReleaseWMIAccessor(&wmi);
@@ -709,14 +709,14 @@ BOOL Run()
   
 
     XsLog("Guest agent lite loop finished %d", exit);
-       return exit;
+    return exit;
 }
 
 
 // Service initialization
 bool ServiceInit()
 {
-       ServiceStatus.dwServiceType        = SERVICE_WIN32; 
+    ServiceStatus.dwServiceType        = SERVICE_WIN32; 
     ServiceStatus.dwCurrentState       = SERVICE_START_PENDING; 
     ServiceStatus.dwControlsAccepted   =
         SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN |
@@ -727,20 +727,20 @@ bool ServiceInit()
     ServiceStatus.dwWaitHint           = 0; 
  
     hStatus = RegisterServiceCtrlHandlerEx(
-               "XenService", 
-               ServiceControlHandler,
+        "XenService", 
+        ServiceControlHandler,
         NULL);
     if (hStatus == (SERVICE_STATUS_HANDLE)0) 
     { 
         // Registering Control Handler failed
-               DBGPRINT(("XenSvc: Registering service control handler failed - %d\n", GetLastError()));
+        DBGPRINT(("XenSvc: Registering service control handler failed - %d\n", GetLastError()));
         return false; 
     }  
 
-       ServiceStatus.dwCurrentState = SERVICE_RUNNING; 
-       SetServiceStatus (hStatus, &ServiceStatus);
+    ServiceStatus.dwCurrentState = SERVICE_RUNNING; 
+    SetServiceStatus (hStatus, &ServiceStatus);
 
-       return true;
+    return true;
 }
 
 void WINAPI ServiceMain(int argc, char** argv)
@@ -758,23 +758,23 @@ void WINAPI ServiceMain(int argc, char** argv)
         DBGPRINT(("XenSvc: Unable to init xenservice\n"));
         return;
     }
-       BOOL stopping;
-
-       do {
-               
-               __try
-               {
-                       stopping = Run();
-                       
-               }
-               __except(EXCEPTION_EXECUTE_HANDLER)
-               {
-               }
-       } while (!stopping);
-       
+    BOOL stopping;
+
+    do {
+        
+        __try
+        {
+            stopping = Run();
+            
+        }
+        __except(EXCEPTION_EXECUTE_HANDLER)
+        {
+        }
+    } while (!stopping);
+    
     XsLog("Guest agent service stopped");
     ShutdownXSAccessor();
-       ServiceControlManagerUpdate(0, SERVICE_STOPPED);
+    ServiceControlManagerUpdate(0, SERVICE_STOPPED);
     return;
 }
 
@@ -807,7 +807,7 @@ static DWORD WINAPI ServiceControlHandler(DWORD request, DWORD evtType,
             return NO_ERROR;
 
         default:
-           DBGPRINT(("XenSvc: unknown request."));
+        DBGPRINT(("XenSvc: unknown request."));
             break;
     }