]> git.sur5r.net Git - bacula/bacula/commitdiff
small vss improvement (more complete shutdown and startup after each backup instead...
authorThorsten Engel <thorsten.engel@matrix-computer.com>
Fri, 5 Aug 2005 08:16:51 +0000 (08:16 +0000)
committerThorsten Engel <thorsten.engel@matrix-computer.com>
Fri, 5 Aug 2005 08:16:51 +0000 (08:16 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2295 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/win32/compat/vss.cpp
bacula/src/win32/compat/vss.h
bacula/src/win32/compat/vss_generic.cpp

index d08409eddccae872cd9138157b81f8203783f36a..8234aad31794e88bcfc6bf0bcc77eef2c17dc3f5 100644 (file)
@@ -72,6 +72,7 @@ using namespace std;
 VSSClient::VSSClient()
 {
     m_bCoInitializeCalled = false;
+    m_bCoInitializeSecurityCalled = false;
     m_dwContext = 0; // VSS_CTX_BACKUP;
     m_bDuringRestore = false;
     m_bBackupIsInitialized = false;
index f3726ada87712af27fea26794b6f98b04fe4cb89..65ae9380eb08b0499b2cb7648d40c3f3409877ad 100644 (file)
@@ -63,6 +63,7 @@ protected:
     HMODULE                         m_hLib;
 
     BOOL                            m_bCoInitializeCalled;
+    BOOL                            m_bCoInitializeSecurityCalled;
     DWORD                           m_dwContext;
 
     IUnknown*                       m_pVssObject;
index ccb981fbc085b4e102674f84cae03117cee49575..54a2d3153dbd6791080c5467a0593d1b6170dcb2 100644 (file)
@@ -215,10 +215,11 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore)
          errno = b_errno_win32;
          return FALSE;
       }
-
       m_bCoInitializeCalled = true;
+   }
 
-      // Initialize COM security
+   // Initialize COM security
+   if (!m_bCoInitializeSecurityCalled) {
       hr =
          CoInitializeSecurity(
          NULL,                           //  Allow *all* VSS writers to communicate back!
@@ -236,6 +237,7 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore)
          errno = b_errno_win32;
          return FALSE;
       }
+      m_bCoInitializeSecurityCalled = true;      
    }
    
    // Release the IVssBackupComponents interface 
@@ -388,43 +390,47 @@ BOOL VSSClientGeneric::CreateSnapshots(char* szDriveLetters)
 
 BOOL VSSClientGeneric::CloseBackup()
 {
-   if (!m_pVssObject) {
+   BOOL bRet = FALSE;
+   if (!m_pVssObject)
       errno = ENOSYS;
-      return FALSE;
-   }
+   else {
+      IVssBackupComponents* pVss = (IVssBackupComponents*) m_pVssObject;
+      CComPtr<IVssAsync>  pAsync;
+      
+      m_bBackupIsInitialized = false;
 
-   BOOL bRet = FALSE;
-   IVssBackupComponents* pVss = (IVssBackupComponents*) m_pVssObject;
-   CComPtr<IVssAsync>  pAsync;
-   
-   m_bBackupIsInitialized = false;
+      if (SUCCEEDED(pVss->BackupComplete(&pAsync))) {
+         // Waits for the async operation to finish and checks the result
+         WaitAndCheckForAsyncOperation(pAsync);
+         bRet = TRUE;     
+      } else {
+         errno = b_errno_win32;
+         pVss->AbortBackup();
+      }
 
-   if (SUCCEEDED(pVss->BackupComplete(&pAsync))) {
-     // Waits for the async operation to finish and checks the result
-     WaitAndCheckForAsyncOperation(pAsync);
-     bRet = TRUE;     
-   } else {
-      errno = b_errno_win32;
-      pVss->AbortBackup();
-   }
+      if (m_uidCurrentSnapshotSet != GUID_NULL) {
+         VSS_ID idNonDeletedSnapshotID = GUID_NULL;
+         LONG lSnapshots;
 
-   if (m_uidCurrentSnapshotSet != GUID_NULL) {
-      VSS_ID idNonDeletedSnapshotID = GUID_NULL;
-      LONG lSnapshots;
+         pVss->DeleteSnapshots(
+            m_uidCurrentSnapshotSet, 
+            VSS_OBJECT_SNAPSHOT_SET,
+            FALSE,
+            &lSnapshots,
+            &idNonDeletedSnapshotID);
 
-      pVss->DeleteSnapshots(
-         m_uidCurrentSnapshotSet, 
-         VSS_OBJECT_SNAPSHOT_SET,
-         FALSE,
-         &lSnapshots,
-         &idNonDeletedSnapshotID);
+         m_uidCurrentSnapshotSet = GUID_NULL;
+      }
 
-      m_uidCurrentSnapshotSet = GUID_NULL;
+      pVss->Release();
+      m_pVssObject = NULL;
    }
 
-
-   pVss->Release();
-   m_pVssObject = NULL;
+   // Call CoUninitialize if the CoInitialize was performed sucesfully
+   if (m_bCoInitializeCalled) {
+      CoUninitialize();
+      m_bCoInitializeCalled = false;
+   }
 
    return bRet;
 }