summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorCody Russell <bratsche@gnome.org>2008-05-25 23:41:43 +0000
committerCody Russell <bratsche@src.gnome.org>2008-05-25 23:41:43 +0000
commit6b06d71c2a647956ba124270e43cfe90c6de41b9 (patch)
tree0930a8bae5354cdb337428d6f2f9e2f82c6f7a24 /gtk
parent4f84a5f292ed40074a063427e99a623c71476e8c (diff)
downloadgtk+-6b06d71c2a647956ba124270e43cfe90c6de41b9.tar.gz
Bug 523562 - gtk-update-icon-cache core dumps when run concurrently and
2008-05-25 Cody Russell <bratsche@gnome.org> Bug 523562 - gtk-update-icon-cache core dumps when run concurrently and when options are missing * gtk/updateiconcache.c: Open the cache file (O_CREAT | O_EXCL) so that other processes that try to open it will fail gracefully. Also fix a crasher caused by lack of a NULL check. Report and patch by Erwann Chenede. svn path=/trunk/; revision=20167
Diffstat (limited to 'gtk')
-rw-r--r--gtk/updateiconcache.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c
index f67210b9c9..1f748fa6a1 100644
--- a/gtk/updateiconcache.c
+++ b/gtk/updateiconcache.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -1435,16 +1436,25 @@ build_cache (const gchar *path)
struct stat path_stat, cache_stat;
struct utimbuf utime_buf;
GList *directories = NULL;
+ int fd;
+ mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
tmp_cache_path = g_build_filename (path, "."CACHE_NAME, NULL);
- cache = g_fopen (tmp_cache_path, "wb");
-
+
+ if ((fd = open (tmp_cache_path, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, mode)) == -1)
+ {
+ g_printerr (_("Failed to open file %s : %s\n"), tmp_cache_path, g_strerror (errno));
+ exit (1);
+ }
+
+ cache = fdopen (fd, "wb");
+
if (!cache)
{
g_printerr (_("Failed to write cache file: %s\n"), g_strerror (errno));
exit (1);
}
-
+
files = g_hash_table_new (g_str_hash, g_str_equal);
image_data_hash = g_hash_table_new (g_str_hash, g_str_equal);
icon_data_hash = g_hash_table_new (g_str_hash, g_str_equal);
@@ -1457,6 +1467,7 @@ build_cache (const gchar *path)
/* Empty table, just close and remove the file */
fclose (cache);
+ close (fd);
g_unlink (tmp_cache_path);
exit (0);
}
@@ -1464,6 +1475,7 @@ build_cache (const gchar *path)
/* FIXME: Handle failure */
retval = write_file (cache, files, directories);
fclose (cache);
+ close (fd);
g_list_foreach (directories, (GFunc)g_free, NULL);
g_list_free (directories);
@@ -1655,8 +1667,16 @@ main (int argc, char **argv)
if (!ignore_theme_index && !has_theme_index (path))
{
- g_printerr (_("No theme index file in '%s'.\n"
+ if (path)
+ {
+ g_printerr (_("No theme index file."));
+ }
+ else
+ {
+ g_printerr (_("No theme index file in '%s'.\n"
"If you really want to create an icon cache here, use --ignore-theme-index.\n"), path);
+ }
+
return 1;
}