summaryrefslogtreecommitdiff
path: root/bin/bbackupd/BackupDaemon.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-01-02 23:05:14 +0000
committerChris Wilson <chris+github@qwirx.com>2015-01-02 23:05:14 +0000
commit3fbad79c920776be01e607431a2a1a8c0a158833 (patch)
tree7e417c92387c88dfa304e1414d75ade76f8c24bc /bin/bbackupd/BackupDaemon.cpp
parent867fa4265692090a7a51a1476b96c851208dd175 (diff)
Add rudimentary support for Windows mutexes.
Thanks to Achim for the patch! https://www.boxbackup.org/ticket/67
Diffstat (limited to 'bin/bbackupd/BackupDaemon.cpp')
-rw-r--r--bin/bbackupd/BackupDaemon.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 58a623e3..3c5f2bf2 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -164,6 +164,39 @@
}
}
# endif
+
+ // Mutex support by Achim: see https://www.boxbackup.org/ticket/67
+
+ // Creates the two mutexes checked for by the installer/uninstaller to
+ // see if the program is still running. One of the mutexes is created
+ // in the global name space (which makes it possible to access the
+ // mutex across user sessions in Windows XP); the other is created in
+ // the session name space (because versions of Windows NT prior to
+ // 4.0 TSE don't have a global name space and don't support the
+ // 'Global\' prefix).
+
+ void CreateMutexes(const std::string& rName)
+ {
+ SECURITY_DESCRIPTOR SecurityDesc;
+ SECURITY_ATTRIBUTES SecurityAttr;
+
+ /* By default on Windows NT, created mutexes are accessible only by the user
+ running the process. We need our mutexes to be accessible to all users, so
+ that the mutex detection can work across user sessions in Windows XP. To
+ do this we use a security descriptor with a null DACL.
+ */
+
+ InitializeSecurityDescriptor(&SecurityDesc, SECURITY_DESCRIPTOR_REVISION);
+ SetSecurityDescriptorDacl(&SecurityDesc, TRUE, NULL, FALSE);
+ SecurityAttr.nLength = sizeof(SecurityAttr);
+ SecurityAttr.lpSecurityDescriptor = &SecurityDesc;
+ SecurityAttr.bInheritHandle = FALSE;
+ // We don't care if this succeeds or fails. It's only used to
+ // ensure that an installer can detect if Box Backup is running.
+ CreateMutexA(&SecurityAttr, FALSE, rName.c_str());
+ std::string global_name = "Global\\" + rName;
+ CreateMutexA(&SecurityAttr, FALSE, global_name.c_str());
+ }
#endif
#include "MemLeakFindOn.h"
@@ -410,6 +443,8 @@ int BackupDaemon::Main(const std::string &rConfigFileName)
}
#endif
+ CreateMutexes("__boxbackup_mutex__");
+
int returnCode;
if (mRunAsService)
@@ -429,7 +464,7 @@ int BackupDaemon::Main(const std::string &rConfigFileName)
return returnCode;
}
-#endif
+#endif // WIN32
// --------------------------------------------------------------------------
//