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

[virt-tools-list] [PATCH virt-viewer] Use a mutex to check if VirtViewer running, v2



We need to warn user that installer can't proceed if there is already
a running instance of VirtViewer or of the installer.

https://bugzilla.redhat.com/show_bug.cgi?id=864033
---
 data/virt-viewer.nsis.in | 11 +++++++++++
 src/virt-viewer-util.c   |  9 +++++++++
 2 files changed, 20 insertions(+)

diff --git a/data/virt-viewer.nsis.in b/data/virt-viewer.nsis.in
index 45af104..1ff49d9 100644
--- a/data/virt-viewer.nsis.in
+++ b/data/virt-viewer.nsis.in
@@ -45,6 +45,17 @@ Function RegisterApplication
     WriteRegDWord HKCU "${REG_IEPOLICY}" "Policy" 3
 FunctionEnd
 
+Function .onInit
+retry:
+ System::Call 'kernel32::CreateMutexA(i 0, i 0, t "VirtViewerMutex") i .r1 ?e'
+ Pop $R0
+ StrCmp $R0 0 end
+   System::Call 'kernel32::CloseHandle(i r1) i.s'
+   MessageBox MB_ICONEXCLAMATION|MB_RETRYCANCEL "VirtViewer is already running, quit any instance and retry." IDRETRY retry IDCANCEL cancel
+cancel:
+   Abort
+FunctionEnd
+
 Section "VirtViewer"
   SectionIn RO
   WriteRegStr HKCU "Software\virt-viewer" "" $INSTDIR
diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c
index 556638c..e99b106 100644
--- a/src/virt-viewer-util.c
+++ b/src/virt-viewer-util.c
@@ -263,6 +263,15 @@ gulong virt_viewer_signal_connect_object(gpointer instance,
 void virt_viewer_util_init(const gchar *appname)
 {
 #ifdef G_OS_WIN32
+    /*
+     * This named mutex will be kept around by Windows until the
+     * process terminates. This allows other instances to check if it
+     * already exists, indicating already running instances. It is
+     * used to warn the user that installer can't proceed in this
+     * case.
+     */
+    CreateMutexA(0, 0, "VirtViewerMutex");
+
     if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
         freopen("CONIN$", "r", stdin);
         freopen("CONOUT$", "w", stdout);
-- 
1.7.11.7


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