Blame SOURCES/fontconfig-fix-race-condition.patch

c5b8fc
From 0203055520206028eecee5d261887cdc91500e15 Mon Sep 17 00:00:00 2001
c5b8fc
From: Akira TAGOH <akira@tagoh.org>
c5b8fc
Date: Wed, 2 Oct 2013 16:34:34 +0900
c5b8fc
Subject: [PATCH] Workaround the race condition issue on updating cache
c5b8fc
c5b8fc
---
c5b8fc
 fc-cache/fc-cache.c     | 62 ++++++++++++++++++++++++++++---------------------
c5b8fc
 fontconfig/fontconfig.h |  3 +++
c5b8fc
 src/fcstr.c             |  6 +++++
c5b8fc
 3 files changed, 45 insertions(+), 26 deletions(-)
c5b8fc
c5b8fc
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
c5b8fc
index aeb0af2..af7ba6d 100644
c5b8fc
--- a/fc-cache/fc-cache.c
c5b8fc
+++ b/fc-cache/fc-cache.c
c5b8fc
@@ -118,7 +118,7 @@ usage (char *program, int error)
c5b8fc
 static FcStrSet *processed_dirs;
c5b8fc
 
c5b8fc
 static int
c5b8fc
-scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force, FcBool verbose, int *changed)
c5b8fc
+scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force, FcBool verbose, FcBool recursive, int *changed)
c5b8fc
 {
c5b8fc
     int		    ret = 0;
c5b8fc
     const FcChar8   *dir;
c5b8fc
@@ -141,7 +141,7 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force,
c5b8fc
 	    fflush (stdout);
c5b8fc
 	}
c5b8fc
 	
c5b8fc
-	if (FcStrSetMember (processed_dirs, dir))
c5b8fc
+	if (recursive && FcStrSetMember (processed_dirs, dir))
c5b8fc
 	{
c5b8fc
 	    if (verbose)
c5b8fc
 		printf ("skipping, looped directory detected\n");
c5b8fc
@@ -213,32 +213,37 @@ scanDirs (FcStrList *list, FcConfig *config, FcBool force, FcBool really_force,
c5b8fc
 		ret++;
c5b8fc
 	    }
c5b8fc
 	}
c5b8fc
-	
c5b8fc
-	subdirs = FcStrSetCreate ();
c5b8fc
-	if (!subdirs)
c5b8fc
+
c5b8fc
+	if (recursive)
c5b8fc
 	{
c5b8fc
-	    fprintf (stderr, "%s: Can't create subdir set\n", dir);
c5b8fc
-	    ret++;
c5b8fc
-	    FcDirCacheUnload (cache);
c5b8fc
-	    continue;
c5b8fc
-	}
c5b8fc
-	for (i = 0; i < FcCacheNumSubdir (cache); i++)
c5b8fc
-	    FcStrSetAdd (subdirs, FcCacheSubdir (cache, i));
c5b8fc
+	    subdirs = FcStrSetCreate ();
c5b8fc
+	    if (!subdirs)
c5b8fc
+	    {
c5b8fc
+		fprintf (stderr, "%s: Can't create subdir set\n", dir);
c5b8fc
+		ret++;
c5b8fc
+		FcDirCacheUnload (cache);
c5b8fc
+		continue;
c5b8fc
+	    }
c5b8fc
+	    for (i = 0; i < FcCacheNumSubdir (cache); i++)
c5b8fc
+		FcStrSetAdd (subdirs, FcCacheSubdir (cache, i));
c5b8fc
 	
c5b8fc
-	FcDirCacheUnload (cache);
c5b8fc
+	    FcDirCacheUnload (cache);
c5b8fc
 	
c5b8fc
-	sublist = FcStrListCreate (subdirs);
c5b8fc
-	FcStrSetDestroy (subdirs);
c5b8fc
-	if (!sublist)
c5b8fc
-	{
c5b8fc
-	    fprintf (stderr, "%s: Can't create subdir list\n", dir);
c5b8fc
-	    ret++;
c5b8fc
-	    continue;
c5b8fc
+	    sublist = FcStrListCreate (subdirs);
c5b8fc
+	    FcStrSetDestroy (subdirs);
c5b8fc
+	    if (!sublist)
c5b8fc
+	    {
c5b8fc
+		fprintf (stderr, "%s: Can't create subdir list\n", dir);
c5b8fc
+		ret++;
c5b8fc
+		continue;
c5b8fc
+	    }
c5b8fc
+	    FcStrSetAdd (processed_dirs, dir);
c5b8fc
+	    ret += scanDirs (sublist, config, force, really_force, verbose, recursive, changed);
c5b8fc
+	    FcStrListDone (sublist);
c5b8fc
 	}
c5b8fc
-	FcStrSetAdd (processed_dirs, dir);
c5b8fc
-	ret += scanDirs (sublist, config, force, really_force, verbose, changed);
c5b8fc
+	else
c5b8fc
+	    FcDirCacheUnload (cache);
c5b8fc
     }
c5b8fc
-    FcStrListDone (list);
c5b8fc
     return ret;
c5b8fc
 }
c5b8fc
 
c5b8fc
@@ -366,7 +371,11 @@ main (int argc, char **argv)
c5b8fc
     }
c5b8fc
 	
c5b8fc
     changed = 0;
c5b8fc
-    ret = scanDirs (list, config, force, really_force, verbose, &changed);
c5b8fc
+    ret = scanDirs (list, config, force, really_force, verbose, FcTrue, &changed);
c5b8fc
+    /* Update the directory cache again to avoid the race condition as much as possible */
c5b8fc
+    FcStrListFirst (list);
c5b8fc
+    ret += scanDirs (list, config, FcTrue, really_force, verbose, FcFalse, &changed);
c5b8fc
+    FcStrListDone (list);
c5b8fc
 
c5b8fc
     /*
c5b8fc
      * Try to create CACHEDIR.TAG anyway.
c5b8fc
@@ -379,6 +388,8 @@ main (int argc, char **argv)
c5b8fc
 
c5b8fc
     cleanCacheDirectories (config, verbose);
c5b8fc
 
c5b8fc
+    FcConfigDestroy (config);
c5b8fc
+    FcFini ();
c5b8fc
     /* 
c5b8fc
      * Now we need to sleep a second  (or two, to be extra sure), to make
c5b8fc
      * sure that timestamps for changes after this run of fc-cache are later
c5b8fc
@@ -386,8 +397,7 @@ main (int argc, char **argv)
c5b8fc
      * sleep(3) can't be interrupted by a signal here -- this isn't in the
c5b8fc
      * library, and there aren't any signals flying around here.
c5b8fc
      */
c5b8fc
-    FcConfigDestroy (config);
c5b8fc
-    FcFini ();
c5b8fc
+    /* the resolution of mtime on FAT is 2 seconds */
c5b8fc
     if (changed)
c5b8fc
 	sleep (1);
c5b8fc
     if (verbose)
c5b8fc
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
c5b8fc
index 58912f5..e588579 100644
c5b8fc
--- a/fontconfig/fontconfig.h
c5b8fc
+++ b/fontconfig/fontconfig.h
c5b8fc
@@ -974,6 +974,9 @@ FcStrSetDestroy (FcStrSet *set);
c5b8fc
 FcPublic FcStrList *
c5b8fc
 FcStrListCreate (FcStrSet *set);
c5b8fc
 
c5b8fc
+FcPublic void
c5b8fc
+FcStrListFirst (FcStrList *list);
c5b8fc
+
c5b8fc
 FcPublic FcChar8 *
c5b8fc
 FcStrListNext (FcStrList *list);
c5b8fc
 
c5b8fc
diff --git a/src/fcstr.c b/src/fcstr.c
c5b8fc
index 3a32031..5707172 100644
c5b8fc
--- a/src/fcstr.c
c5b8fc
+++ b/src/fcstr.c
c5b8fc
@@ -1374,6 +1374,12 @@ FcStrListCreate (FcStrSet *set)
c5b8fc
     return list;
c5b8fc
 }
c5b8fc
 
c5b8fc
+void
c5b8fc
+FcStrListFirst (FcStrList *list)
c5b8fc
+{
c5b8fc
+    list->n = 0;
c5b8fc
+}
c5b8fc
+
c5b8fc
 FcChar8 *
c5b8fc
 FcStrListNext (FcStrList *list)
c5b8fc
 {
c5b8fc
-- 
c5b8fc
1.8.3.1
c5b8fc
c5b8fc
From 9a4310176bb11e1e826d238eb0761b7895b48883 Mon Sep 17 00:00:00 2001
c5b8fc
From: Akira TAGOH <akira@tagoh.org>
c5b8fc
Date: Wed, 9 Oct 2013 12:19:35 +0900
c5b8fc
Subject: [PATCH] Add missing doc for FcStrListFirst and fix a typo
c5b8fc
c5b8fc
---
c5b8fc
 doc/fcstrset.fncs | 10 +++++++++-
c5b8fc
 1 file changed, 9 insertions(+), 1 deletion(-)
c5b8fc
c5b8fc
diff --git a/doc/fcstrset.fncs b/doc/fcstrset.fncs
c5b8fc
index 737347b..b96489a 100644
c5b8fc
--- a/doc/fcstrset.fncs
c5b8fc
+++ b/doc/fcstrset.fncs
c5b8fc
@@ -98,12 +98,20 @@ Destroys <parameter>set</parameter>.
c5b8fc
 Creates an iterator to list the strings in <parameter>set</parameter>.
c5b8fc
 @@
c5b8fc
 
c5b8fc
+@RET@		void
c5b8fc
+@FUNC@		FcStrListFirst
c5b8fc
+@TYPE1@		FcStrList *			@ARG1@		list
c5b8fc
+@PURPOSE@	get first string in iteration
c5b8fc
+@DESC@
c5b8fc
+Returns the first string in <parameter>list</parameter>.
c5b8fc
+@@
c5b8fc
+
c5b8fc
 @RET@		FcChar8 *
c5b8fc
 @FUNC@		FcStrListNext
c5b8fc
 @TYPE1@		FcStrList *			@ARG1@		list	
c5b8fc
 @PURPOSE@	get next string in iteration
c5b8fc
 @DESC@
c5b8fc
-Returns the next string in <parameter>set</parameter>.
c5b8fc
+Returns the next string in <parameter>list</parameter>.
c5b8fc
 @@
c5b8fc
 
c5b8fc
 @RET@		void
c5b8fc
-- 
c5b8fc
1.8.3.1
c5b8fc