aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2017-06-21 16:50:03 -0400
committerAnders Broman <a.broman58@gmail.com>2017-06-22 02:41:59 +0000
commit7af770dfa72eaca512b658b3ed702ad27c491e91 (patch)
treefdf9c30af8d68efdcd0337f33e26d4cb27f40b59
parenta9c2697714b8053b2cd9b1e1e0f07baf9d345c1f (diff)
wsutil: Return error from profile_write_info_file
Change-Id: I1d91cef01ced6cceaa75d1618ffcb59eae5b8e6f Reviewed-on: https://code.wireshark.org/review/22325 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--wireshark-qt.cpp6
-rw-r--r--wsutil/filesystem.c26
-rw-r--r--wsutil/filesystem.h2
3 files changed, 27 insertions, 7 deletions
diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp
index 45cf6a80fb..e10f2e3f7b 100644
--- a/wireshark-qt.cpp
+++ b/wireshark-qt.cpp
@@ -915,7 +915,11 @@ int main(int argc, char *qt_argv[])
g_free(get_persconffile_path("io_graphs", TRUE));
profile_store_persconffiles(FALSE);
- profile_write_info_file();
+ if (!profile_write_info_file(&rf_path)) {
+ simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+ "Could not create file\n\"%s\"", rf_path);
+ g_free (rf_path);
+ }
ret_val = wsApp->exec();
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index 28f68eac33..efdfa7f779 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -1244,25 +1244,39 @@ compare_filename(gconstpointer dissector_a, gconstpointer dissector_b)
return strcmp((const char*)dissector_a, (const char*)dissector_b);
}
-void
-profile_write_info_file(void)
+gboolean
+profile_write_info_file(gchar **pf_dir_path_return)
{
gchar *profile_dir, *info_file, *filename;
GList *files, *file;
- ssize_t nwritten = 0;
+ ssize_t filename_len;
int fd;
profile_dir = get_profiles_dir();
info_file = g_strdup_printf("%s%s%s", profile_dir, G_DIR_SEPARATOR_S, PROFILES_INFO_NAME);
fd = ws_open(info_file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+ if (fd < 0) {
+ g_free (profile_dir);
+ *pf_dir_path_return = info_file;
+ return FALSE;
+ }
files = g_hash_table_get_keys(profile_files);
files = g_list_sort(files, compare_filename);
file = g_list_first(files);
while (file) {
filename = (gchar *)file->data;
- nwritten += ws_write(fd, filename, (unsigned int)strlen(filename));
- nwritten += ws_write(fd, "\n", 1);
+ filename_len = strlen(filename);
+ if ((ws_write(fd, filename, filename_len) != filename_len) ||
+ (ws_write(fd, "\n", 1) != 1))
+ {
+ ws_close(fd);
+ g_list_free(files);
+ g_free (profile_dir);
+
+ *pf_dir_path_return = info_file;
+ return FALSE;
+ }
file = g_list_next(file);
}
g_list_free(files);
@@ -1270,6 +1284,8 @@ profile_write_info_file(void)
ws_close(fd);
g_free(info_file);
g_free(profile_dir);
+
+ return TRUE;
}
/*
diff --git a/wsutil/filesystem.h b/wsutil/filesystem.h
index 8b2d9faf54..c28e0a48db 100644
--- a/wsutil/filesystem.h
+++ b/wsutil/filesystem.h
@@ -145,7 +145,7 @@ WS_DLL_PUBLIC void profile_store_persconffiles(gboolean store);
/*
* Store a list of all personal config files which belongs in a profile.
*/
-WS_DLL_PUBLIC void profile_write_info_file(void);
+WS_DLL_PUBLIC gboolean profile_write_info_file(gchar **pf_dir_path_return);
/*
* Check if given configuration profile exists.