When any of our executables start on Windows create or open a "Wireshark
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 20 Feb 2013 01:19:42 +0000 (01:19 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 20 Feb 2013 01:19:42 +0000 (01:19 +0000)
is running" mutex. Have the NSIS installer check for this mutex and ask
the user to close Wireshark if it's found. While not perfect this makes
the WinSparkle update process much less annoying.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@47758 f5534014-38df-0310-8fa8-9805f1628bb7

14 files changed:
capinfos.c
dumpcap.c
editcap.c
mergecap.c
packaging/nsis/wireshark.nsi
randpkt.c
rawshark.c
text2pcap.c
tshark.c
ui/gtk/main.c
ui/qt/main.cpp
wsutil/file_util.c
wsutil/file_util.h
wsutil/libwsutil.def

index 96d7de998ab89c7e115bf5716e84a7316f8b392c..246afb3443a01cc22629a56cf59766bc6a5db34f 100644 (file)
@@ -155,7 +155,7 @@ static gboolean cap_file_hashes = TRUE;     /* Calculate file hashes */
 #ifdef USE_GOPTION
 static gboolean cap_help = FALSE;
 static gboolean table_report = FALSE;
+
 static GOptionEntry general_entries[] =
 {
 /* General */
@@ -490,7 +490,7 @@ print_stats(const gchar *filename, capture_info *cf_info)
   }
   if (cap_packet_size)    printf     ("Average packet size: %.2f bytes\n",        cf_info->packet_size);
   if (cf_info->times_known) {
-    if (cap_packet_rate) 
+    if (cap_packet_rate)
                           print_value("Average packet rate: ", 2, " packets/sec", cf_info->packet_rate);
   }
 #ifdef HAVE_LIBGCRYPT
@@ -1022,6 +1022,7 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
+  create_app_running_mutex();
 #endif /* _WIN32 */
 
   /*
@@ -1044,7 +1045,7 @@ main(int argc, char *argv[])
   /* Process the options */
 #ifdef USE_GOPTION
   ctx = g_option_context_new(" <infile> ... - print information about capture file(s)");
-  general_grp = g_option_group_new("gen", "General infos:", 
+  general_grp = g_option_group_new("gen", "General infos:",
                                "Show general options", NULL, NULL);
   size_grp = g_option_group_new("size", "Size infos:",
                               "Show size options", NULL, NULL);
index d2dfecabeef8c8a473dc09a68b140841973f69fc..c917b96d95fd8cbf3ad377772d4f9618744fb2ce 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -4177,9 +4177,8 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
     arg_list_utf_16to8(argc, argv);
-#endif /* _WIN32 */
+    create_app_running_mutex();
 
-#ifdef _WIN32
     /*
      * Initialize our DLL search path. MUST be called before LoadLibrary
      * or g_module_open.
index 03ef7465092b79d0c0c34b82f4d338b3cd059932..f1fdf7dcb51844ac3aa81d17158fa5289a9348c0 100644 (file)
--- a/editcap.c
+++ b/editcap.c
@@ -65,6 +65,7 @@
 #endif
 
 #ifdef _WIN32
+#include <wsutil/file_util.h>
 #include <wsutil/unicode-utils.h>
 #include <process.h>    /* getpid */
 #ifdef HAVE_WINSOCK2_H
@@ -870,6 +871,7 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
+  create_app_running_mutex();
 #endif /* _WIN32 */
 
   /*
index 685b0da686ffb58a0de1b404a9b76192d9da6633..d42b858cdee2e81a571092b8f2b0ff6d93f2d82e 100644 (file)
@@ -223,6 +223,7 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
+  create_app_running_mutex();
 #endif /* _WIN32 */
 
   /* Process the options first */
index d432933e1be31dbc60620a3583b43b37ea9456c0..d7d2f696094e5cd14a32da5fb099594f93957bba 100644 (file)
@@ -210,6 +210,17 @@ Function .onInit
     ${EndIf}
   !endif
 
+; See if Wireshark is running
+; http://nsis.sourceforge.net/Check_whether_your_application_is_running
+checkRunning:
+System::Call 'kernel32::OpenMutex(i 0x100000, b 0, t "${PROGRAM_NAME}-is-running-{9CA78EEA-EA4D-4490-9240-FC01FCEF464B}") i .R0'
+  IntCmp $R0 0 notRunning
+  System::Call 'kernel32::CloseHandle(i $R0)'
+  ; You'd better go catch it.
+  MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "${PROGRAM_NAME} or one is associated programs is running. Please close it first" /SD IDCANCEL IDRETRY checkRunning
+  Quit
+notRunning:
+
   ; Copied from http://nsis.sourceforge.net/Auto-uninstall_old_before_installing_new
   ReadRegStr $OLD_UNINSTALLER HKLM \
     "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}" \
index caf50fd0ed4e1ec327ee7c75c0e85b9f4344fe36..96d2b9ee97fa2536f542247b111d3235b8a51a49 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
@@ -512,6 +512,7 @@ main(int argc, char **argv)
 
 #ifdef _WIN32
        arg_list_utf_16to8(argc, argv);
+       create_app_running_mutex();
 #endif /* _WIN32 */
 
        while ((opt = getopt(argc, argv, "b:c:ht:")) != -1) {
index 28275f23b86fd45b1eb43c368fe91b3246a05a07..79ba9387367526742e25e44fd8a86df933104e69 100644 (file)
@@ -472,6 +472,7 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
     arg_list_utf_16to8(argc, argv);
+    create_app_running_mutex();
 #endif /* _WIN32 */
 
     /*
index 29af045fa47a2ec4b0d30e55f2d6e4d623522cba..14bc41911875543dca8045595c048dcc479b495a 100644 (file)
@@ -1369,6 +1369,7 @@ parse_options (int argc, char *argv[])
 
 #ifdef _WIN32
     arg_list_utf_16to8(argc, argv);
+    create_app_running_mutex();
 #endif /* _WIN32 */
 
     /* Scan CLI parameters */
index e1d36884740a9d85b79b1f01bf54a76f66535db5..c6a42782ee4137ebc9e5240a9e9e343aa677df71 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -950,6 +950,7 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
+  create_app_running_mutex();
 #if !GLIB_CHECK_VERSION(2,31,0)
   g_thread_init(NULL);
 #endif
index acc69e4ff1ef5aa2d9663a4e4fd76178de56f970..313e52a2c0c0b7ff2b5d83b955192205938e5b41 100644 (file)
@@ -2224,6 +2224,7 @@ main(int argc, char *argv[])
   setlocale(LC_ALL, "");
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
+  create_app_running_mutex();
 #endif /* _WIN32 */
 
   /*
@@ -3217,7 +3218,7 @@ main(int argc, char *argv[])
 #endif
 
   software_update_init();
-  
+
   /* we'll enter the GTK loop now and hand the control over to GTK ... */
   gtk_main();
   /* ... back from GTK, we're going down now! */
index cb1dc3acb3a72991e7cf575eb239b934e000619c..46533369c6d43ed9a27ec27bf07914c0b76297bd 100644 (file)
@@ -528,6 +528,7 @@ int main(int argc, char *argv[])
     int                  status;
 
     //initialize language !
+    create_app_running_mutex();
 
     QString locale = QLocale::system().name();
 
index c9186c423d59c6fe213b34421160afc97f1668b7..1efc7cc39cb6bf10607332f4337421ead6efd48e 100644 (file)
@@ -614,3 +614,10 @@ getenv_utf8(const char *varname)
 
        return envvar;
 }
+
+/** Create or open a "Wireshark is running" mutex.
+ */
+#define WIRESHARK_IS_RUNNING_UUID "9CA78EEA-EA4D-4490-9240-FC01FCEF464B"
+void create_app_running_mutex() {
+      CreateMutex(NULL, FALSE, _T("Wireshark-is-running-{") _T(WIRESHARK_IS_RUNNING_UUID) _T("}"));
+}
index 4710aa6a15613fba13529cb2e2d8d105d90b00c2..af5f94d996d41be39964e59e03d2d37d5a771da5 100644 (file)
@@ -113,6 +113,7 @@ gboolean ws_init_dll_search_path();
  */
 
 void *ws_load_library(gchar *library_name);
+
 /** Load a DLL using g_module_open.
  * Only the system and program directories are searched.
  *
@@ -127,6 +128,12 @@ GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
  */
 extern char *getenv_utf8(const char *varname);
 
+/** Create or open a "Wireshark is running" mutex.
+ * Create or open a mutex which signals that Wireshark or its associated
+ * executables is running. Used by the installer to test for a running application.
+ */
+extern void create_app_running_mutex();
+
 #else  /* _WIN32 */
 
 /*
index 49b9a39286da9769dba76558c2e7b925761fa9e7..bc30c3ab36a7946ecbe1998fb87740432d0b158e 100644 (file)
@@ -52,6 +52,7 @@ crc32_mpeg2_seed
 crc_drm
 
 ; file_util.c
+create_app_running_mutex
 getenv_utf8
 ws_stdio_fopen
 ws_stdio_freopen