profiles: Try to better sync on disk config state
authorJim Young <jyoung@gsu.edu>
Wed, 11 Dec 2019 03:01:16 +0000 (22:01 -0500)
committerAnders Broman <a.broman58@gmail.com>
Mon, 16 Dec 2019 05:34:28 +0000 (05:34 +0000)
Profile specific column settings are split across the `preferences'
file and the `recent' file.  At any given moment the GUI column
settings held within the `preferences' file and the `recent' file
may be inconsistent with one another and with the GUI itself. These
inconsistencies occur because of when the GUI chooses to write
config changes to disk.

If Wireshark is not shutdown gracefully (for example when killed
or should crash) the column preferences saved on disk may not be
consistent between the current profile's `preferences` and `recent`
files and the most recently used profile may not be recorded within
the `recent_common' file. On restarting Wireshark these config file
inconsistencies can lead to unexpected artifacts.

Normally the column config state saved within the current profile's
`preferences' and `recent` files are made consistent when a
different profile is selected or when Wireshark is closed
gracefully.

This patch set attempts to improve the constancy of the on disk
config state with the GUI state by invoking the functions to write
the `recent' and `recent_common' files in a more timely manner.

Fix a typo while here.

Change-Id: I2af9d9eb2dcf9cc0d422e9840aa05f4f6b1aa086
Reviewed-on: https://code.wireshark.org/review/35407
Petri-Dish: Jim Young <jim.young.ws@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Jim Young <jim.young.ws@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
ui/preference_utils.c
ui/qt/wireshark_application.cpp
ui/qt/wireshark_application.h
ui/recent.c
ui/recent.h

index 70684f5a55235e245bc5e69912441cd3426d9f9f..404c13c997ef590385afdf85737a5208e8ebbd7c 100644 (file)
@@ -19,6 +19,7 @@
 #include <epan/packet.h>
 #include <epan/decode_as.h>
 #include <epan/uat-int.h>
+#include <ui/recent.h>
 
 #ifdef HAVE_LIBPCAP
 #include "capture_opts.h"
@@ -62,7 +63,7 @@ prefs_main_write(void)
                 g_strerror(errno));
         g_free(pf_dir_path);
     } else {
-        /* Write the preferencs out. */
+        /* Write the preferences out. */
         err = write_prefs(&pf_path);
         if (err != 0) {
             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
@@ -70,6 +71,9 @@ prefs_main_write(void)
                     g_strerror(err));
             g_free(pf_path);
         }
+        /* Write recent and recent_common files out to ensure sync with prefs. */
+        write_profile_recent();
+        write_recent();
     }
 }
 
index 7fb754652f4b473b8ce9b065a728f98774e8ac67..eb56e2f167f2dda8d4c89ad9817be8438010ac0d 100644 (file)
@@ -359,7 +359,7 @@ int WiresharkApplication::monospaceTextSize(const char *str)
 #endif
 }
 
-void WiresharkApplication::setConfigurationProfile(const gchar *profile_name, bool write_recent)
+void WiresharkApplication::setConfigurationProfile(const gchar *profile_name, bool write_recent_file)
 {
     char  *rf_path;
     int    rf_open_errno;
@@ -402,7 +402,7 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name, bo
     /* Get the current geometry, before writing it to disk */
     emit profileChanging();
 
-    if (write_recent && profile_exists(get_profile_name(), FALSE))
+    if (write_recent_file && profile_exists(get_profile_name(), FALSE))
     {
         /* Write recent file for profile we are leaving, if it still exists */
         write_profile_recent();
@@ -454,6 +454,9 @@ void WiresharkApplication::setConfigurationProfile(const gchar *profile_name, bo
 
     emit localInterfaceListChanged();
     emit packetDissectionChanged();
+
+    /* Write recent_common file to ensure last used profile setting is stored. */
+    write_recent();
 }
 
 void WiresharkApplication::reloadLuaPluginsDelayed()
index 704caf633de49b9c7ea193e6fefb70b1a7799871..09e8fe4c5628ae90803b6ae00ffc166279eae48d 100644 (file)
@@ -112,7 +112,7 @@ public:
     const QFont monospaceFont(bool zoomed = false) const;
     void setMonospaceFont(const char *font_string);
     int monospaceTextSize(const char *str);
-    void setConfigurationProfile(const gchar *profile_name, bool write_recent = true);
+    void setConfigurationProfile(const gchar *profile_name, bool write_recent_file = true);
     void reloadLuaPluginsDelayed();
     bool isInitialized() { return initialized_; }
     void setReloadingLua(bool is_reloading) { is_reloading_lua_ = is_reloading; }
index ad954d12a9468c3790d8bcc25184eee51c7a60b0..330cb4b92a2d9ea0055f49061720bf65a6105448 100644 (file)
@@ -634,7 +634,7 @@ write_recent_enum(FILE *rf, const char *description, const char *name,
         fprintf(rf, "%s: %s\n", name, if_invalid != NULL ? if_invalid : "Unknown");
 }
 
-/* Attempt to write out "recent common" to the user's recent common file.
+/* Attempt to write out "recent common" to the user's recent_common file.
    If we got an error report it with a dialog box and return FALSE,
    otherwise return TRUE. */
 gboolean
@@ -671,9 +671,10 @@ write_recent(void)
     }
     g_free(rf_path);
 
-    fputs("# Recent settings file for Wireshark " VERSION ".\n"
+    fputs("# Common recent settings file for Wireshark " VERSION ".\n"
             "#\n"
-            "# This file is regenerated each time Wireshark is quit.\n"
+            "# This file is regenerated each time Wireshark is quit\n"
+            "# and when changing configuration profile.\n"
             "# So be careful, if you want to make manual changes here.\n"
             "\n"
             "######## Recent capture files (latest last), cannot be altered through command line ########\n"
index 1df131003995545429ef52801272c1b18423650e..c1200c9ff54e60579674921e3d24b728c2e23660 100644 (file)
@@ -140,7 +140,7 @@ extern void recent_init(void);
 /** Cleanup/Frees recent settings (done at shutdown) */
 extern void recent_cleanup(void);
 
-/** Write recent settings file.
+/** Write recent_common settings file.
  *
  * @return TRUE if succeeded, FALSE if failed
  */