summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dftest.c30
-rw-r--r--epan/prefs.c49
-rw-r--r--epan/prefs.h15
-rw-r--r--rawshark.c28
-rw-r--r--sharkd.c28
-rw-r--r--tfshark.c31
-rw-r--r--tshark.c31
-rw-r--r--ui/gtk/main.c33
-rw-r--r--ui/qt/wireshark_application.cpp33
9 files changed, 29 insertions, 249 deletions
diff --git a/dftest.c b/dftest.c
index 7d7c868e9c..81e5185260 100644
--- a/dftest.c
+++ b/dftest.c
@@ -58,9 +58,6 @@ main(int argc, char **argv)
{
char *init_progfile_dir_error;
char *text;
- char *gpf_path, *pf_path;
- int gpf_open_errno, gpf_read_errno;
- int pf_open_errno, pf_read_errno;
dfilter_t *df;
gchar *err_msg;
@@ -109,32 +106,7 @@ main(int argc, char **argv)
/* set the c-language locale to the native environment. */
setlocale(LC_ALL, "");
- read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- fprintf(stderr,
- "can't open global preferences file \"%s\": %s.\n",
- pf_path, g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- fprintf(stderr,
- "I/O error reading global preferences file \"%s\": %s.\n",
- pf_path, g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- fprintf(stderr,
- "can't open your preferences file \"%s\": %s.\n",
- pf_path, g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- fprintf(stderr,
- "I/O error reading your preferences file \"%s\": %s.\n",
- pf_path, g_strerror(pf_read_errno));
- }
- }
+ read_prefs();
/* notify all registered modules that have had any of their preferences
changed either from one of the preferences file or from the command
diff --git a/epan/prefs.c b/epan/prefs.c
index f2cee4aa88..293e8e1dbb 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -45,6 +45,7 @@
#include "print.h"
#include <wsutil/file_util.h>
#include <wsutil/ws_printf.h> /* ws_g_warning */
+#include <wsutil/report_message.h>
#include <epan/prefs-int.h>
#include <epan/uat-int.h>
@@ -4184,19 +4185,10 @@ prefs_reset(void)
/* Read the preferences file, fill in "prefs", and return a pointer to it.
- If we got an error (other than "it doesn't exist") trying to read
- the global preferences file, stuff the errno into "*gpf_errno_return"
- and a pointer to the path of the file into "*gpf_path_return", and
- return NULL.
-
- If we got an error (other than "it doesn't exist") trying to read
- the user's preferences file, stuff the errno into "*pf_errno_return"
- and a pointer to the path of the file into "*pf_path_return", and
- return NULL. */
+ If we got an error (other than "it doesn't exist") we report it through
+ the UI. */
e_prefs *
-read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
- char **gpf_path_return, int *pf_errno_return,
- int *pf_read_errno_return, char **pf_path_return)
+read_prefs(void)
{
int err;
char *pf_path;
@@ -4237,7 +4229,6 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
* XXX - if it failed for a reason other than "it doesn't exist",
* report the error.
*/
- *gpf_path_return = NULL;
if (pf != NULL) {
/*
* Start out the counters of "mgcp.{tcp,udp}.port" entries we've
@@ -4249,21 +4240,19 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
/* We succeeded in opening it; read it. */
err = read_prefs_file(gpf_path, pf, set_pref, NULL);
if (err != 0) {
- /* We had an error reading the file; return the errno and the
- pathname, so our caller can report the error. */
- *gpf_errno_return = 0;
- *gpf_read_errno_return = err;
- *gpf_path_return = gpf_path;
+ /* We had an error reading the file; report it. */
+ report_warning("Error reading global preferences file \"%s\": %s.",
+ gpf_path, g_strerror(err));
}
fclose(pf);
} else {
/* We failed to open it. If we failed for some reason other than
- "it doesn't exist", return the errno and the pathname, so our
- caller can report the error. */
+ "it doesn't exist", report the error. */
if (errno != ENOENT) {
- *gpf_errno_return = errno;
- *gpf_read_errno_return = 0;
- *gpf_path_return = gpf_path;
+ if (errno != 0) {
+ report_warning("Can't open global preferences file \"%s\": %s.",
+ gpf_path, g_strerror(errno));
+ }
}
}
@@ -4271,7 +4260,6 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
pf_path = get_persconffile_path(PF_NAME, TRUE);
/* Read the user's preferences file, if it exists. */
- *pf_path_return = NULL;
if ((pf = ws_fopen(pf_path, "r")) != NULL) {
/*
* Start out the counters of "mgcp.{tcp,udp}.port" entries we've
@@ -4283,11 +4271,9 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
/* We succeeded in opening it; read it. */
err = read_prefs_file(pf_path, pf, set_pref, NULL);
if (err != 0) {
- /* We had an error reading the file; return the errno and the
- pathname, so our caller can report the error. */
- *pf_errno_return = 0;
- *pf_read_errno_return = err;
- *pf_path_return = pf_path;
+ /* We had an error reading the file; report it. */
+ report_warning("Error reading your preferences file \"%s\": %s.",
+ pf_path, g_strerror(err));
} else
g_free(pf_path);
fclose(pf);
@@ -4296,9 +4282,8 @@ read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
"it doesn't exist", return the errno and the pathname, so our
caller can report the error. */
if (errno != ENOENT) {
- *pf_errno_return = errno;
- *pf_read_errno_return = 0;
- *pf_path_return = pf_path;
+ report_warning("Can't open your preferences file \"%s\": %s.",
+ pf_path, g_strerror(errno));
} else
g_free(pf_path);
}
diff --git a/epan/prefs.h b/epan/prefs.h
index 74ea1a0217..77a3624ff5 100644
--- a/epan/prefs.h
+++ b/epan/prefs.h
@@ -589,18 +589,9 @@ char *prefs_pref_to_str(pref_t *pref, pref_source_t source);
/* Read the preferences file, fill in "prefs", and return a pointer to it.
- If we got an error (other than "it doesn't exist") trying to read
- the global preferences file, stuff the errno into "*gpf_errno_return"
- on an open error and into "*gpf_read_errno_return" on a read error,
- stuff a pointer to the path of the file into "*gpf_path_return", and
- return NULL.
-
- If we got an error (other than "it doesn't exist") trying to read
- the user's preferences file, stuff the errno into "*pf_errno_return"
- on an open error and into "*pf_read_errno_return" on a read error,
- stuff a pointer to the path of the file into "*pf_path_return", and
- return NULL. */
-WS_DLL_PUBLIC e_prefs *read_prefs(int *, int *, char **, int *, int *, char **);
+ If we got an error (other than "it doesn't exist") we report it through
+ the UI. */
+WS_DLL_PUBLIC e_prefs *read_prefs(void);
/* Write out "prefs" to the user's preferences file, and return 0.
diff --git a/rawshark.c b/rawshark.c
index 248edfd228..43d76be232 100644
--- a/rawshark.c
+++ b/rawshark.c
@@ -436,9 +436,6 @@ main(int argc, char *argv[])
struct rlimit limit;
#endif /* _WIN32 */
- char *gpf_path, *pf_path;
- int gpf_open_errno, gpf_read_errno;
- int pf_open_errno, pf_read_errno;
gchar *pipe_name = NULL;
gchar *rfilters[64];
e_prefs *prefs_p;
@@ -544,30 +541,7 @@ main(int argc, char *argv[])
goto clean_exit;
}
- prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- cmdarg_err("Can't open global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- cmdarg_err("I/O error reading global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- cmdarg_err("Can't open your preferences file \"%s\": %s.", pf_path,
- g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- cmdarg_err("I/O error reading your preferences file \"%s\": %s.",
- pf_path, g_strerror(pf_read_errno));
- }
- g_free(pf_path);
- pf_path = NULL;
- }
+ prefs_p = read_prefs();
/*
* Read the files that enable and disable protocols and heuristic
diff --git a/sharkd.c b/sharkd.c
index 64669455d8..3b10167338 100644
--- a/sharkd.c
+++ b/sharkd.c
@@ -122,11 +122,8 @@ main(int argc, char *argv[])
GString *runtime_info_str;
char *init_progfile_dir_error;
- char *gpf_path, *pf_path;
char *cf_path;
char *err_msg = NULL;
- int gpf_open_errno, gpf_read_errno;
- int pf_open_errno, pf_read_errno;
int cf_open_errno;
e_prefs *prefs_p;
int ret = EXIT_SUCCESS;
@@ -209,30 +206,7 @@ main(int argc, char *argv[])
/* load the decode as entries of this profile */
load_decode_as_entries();
- prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- cmdarg_err("Can't open global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- cmdarg_err("I/O error reading global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- cmdarg_err("Can't open your preferences file \"%s\": %s.", pf_path,
- g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- cmdarg_err("I/O error reading your preferences file \"%s\": %s.",
- pf_path, g_strerror(pf_read_errno));
- }
- g_free(pf_path);
- pf_path = NULL;
- }
+ prefs_p = read_prefs();
read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
if (cf_path != NULL) {
diff --git a/tfshark.c b/tfshark.c
index 0993b6181e..e72645aedb 100644
--- a/tfshark.c
+++ b/tfshark.c
@@ -334,9 +334,6 @@ main(int argc, char *argv[])
};
gboolean arg_error = FALSE;
- char *gpf_path, *pf_path;
- int gpf_open_errno, gpf_read_errno;
- int pf_open_errno, pf_read_errno;
int err;
volatile int exit_status = 0;
gboolean quiet = FALSE;
@@ -560,8 +557,7 @@ main(int argc, char *argv[])
if (strcmp(argv[2], "column-formats") == 0)
column_dump_column_formats();
else if (strcmp(argv[2], "currentprefs") == 0) {
- read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
+ read_prefs();
write_prefs(NULL);
}
else if (strcmp(argv[2], "decodes") == 0)
@@ -601,30 +597,7 @@ main(int argc, char *argv[])
goto clean_exit;
}
- prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- cmdarg_err("Can't open global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- cmdarg_err("I/O error reading global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- cmdarg_err("Can't open your preferences file \"%s\": %s.", pf_path,
- g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- cmdarg_err("I/O error reading your preferences file \"%s\": %s.",
- pf_path, g_strerror(pf_read_errno));
- }
- g_free(pf_path);
- pf_path = NULL;
- }
+ prefs_p = read_prefs();
/*
* Read the files that enable and disable protocols and heuristic
diff --git a/tshark.c b/tshark.c
index 348b68f0ad..b3149cb6a3 100644
--- a/tshark.c
+++ b/tshark.c
@@ -665,10 +665,7 @@ main(int argc, char *argv[])
WSADATA wsaData;
#endif /* _WIN32 */
- char *gpf_path, *pf_path;
char *cf_path;
- int gpf_open_errno, gpf_read_errno;
- int pf_open_errno, pf_read_errno;
int cf_open_errno;
int err;
volatile int exit_status = EXIT_SUCCESS;
@@ -958,8 +955,7 @@ main(int argc, char *argv[])
if (strcmp(argv[2], "column-formats") == 0)
column_dump_column_formats();
else if (strcmp(argv[2], "currentprefs") == 0) {
- read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
+ read_prefs();
write_prefs(NULL);
}
else if (strcmp(argv[2], "decodes") == 0)
@@ -1011,30 +1007,7 @@ main(int argc, char *argv[])
tshark_debug("tshark reading preferences");
- prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- cmdarg_err("Can't open global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- cmdarg_err("I/O error reading global preferences file \"%s\": %s.",
- pf_path, g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- cmdarg_err("Can't open your preferences file \"%s\": %s.", pf_path,
- g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- cmdarg_err("I/O error reading your preferences file \"%s\": %s.",
- pf_path, g_strerror(pf_read_errno));
- }
- g_free(pf_path);
- pf_path = NULL;
- }
+ prefs_p = read_prefs();
read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
if (cf_path != NULL) {
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index bfc3aac287..197610f769 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -1905,46 +1905,15 @@ get_wireshark_runtime_info(GString *str)
static e_prefs *
read_configuration_files(void)
{
- int gpf_open_errno, gpf_read_errno;
int cf_open_errno, df_open_errno;
- char *gpf_path, *pf_path;
char *cf_path, *df_path;
- int pf_open_errno, pf_read_errno;
e_prefs *prefs_p;
/* load the decode as entries of this profile */
load_decode_as_entries();
/* Read the preference files. */
- prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
-
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open global preferences file\n\"%s\": %s.",
- gpf_path, g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading global preferences file\n\"%s\": %s.",
- gpf_path, g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your preferences file\n\"%s\": %s.",
- pf_path, g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading your preferences file\n\"%s\": %s.",
- pf_path, g_strerror(pf_read_errno));
- }
- g_free(pf_path);
- pf_path = NULL;
- }
+ prefs_p = read_prefs();
#ifdef _WIN32
/* if the user wants a console to be always there, well, we should open one for him */
diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp
index f1ef200574..a9428d534f 100644
--- a/ui/qt/wireshark_application.cpp
+++ b/ui/qt/wireshark_application.cpp
@@ -1095,11 +1095,8 @@ void WiresharkApplication::allSystemsGo()
_e_prefs *WiresharkApplication::readConfigurationFiles(bool reset)
{
- int gpf_open_errno, gpf_read_errno;
int cf_open_errno, df_open_errno;
- char *gpf_path, *pf_path;
char *cf_path, *df_path;
- int pf_open_errno, pf_read_errno;
e_prefs *prefs_p;
if (reset) {
@@ -1116,35 +1113,7 @@ _e_prefs *WiresharkApplication::readConfigurationFiles(bool reset)
load_decode_as_entries();
/* Read the preference files. */
- prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
-
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open global preferences file\n\"%s\": %s.", gpf_path,
- g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading global preferences file\n\"%s\": %s.", gpf_path,
- g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your preferences file\n\"%s\": %s.", pf_path,
- g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading your preferences file\n\"%s\": %s.", pf_path,
- g_strerror(pf_read_errno));
- }
- g_free(pf_path);
- pf_path = NULL;
- }
+ prefs_p = read_prefs();
#ifdef _WIN32
/* if the user wants a console to be always there, well, we should open one for him */