Add new FcAtomic datatype for config file locking
This commit is contained in:
parent
d23a2a6dfa
commit
134f6011f3
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $XFree86: xc/lib/fontconfig/fontconfig/fontconfig.h,v 1.4 2002/02/28 16:51:48 keithp Exp $
|
* $XFree86: xc/lib/fontconfig/fontconfig/fontconfig.h,v 1.5 2002/03/01 01:00:54 keithp Exp $
|
||||||
*
|
*
|
||||||
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
|
||||||
*
|
*
|
||||||
|
@ -212,6 +212,8 @@ typedef enum _FcSetName {
|
||||||
FcSetApplication = 1
|
FcSetApplication = 1
|
||||||
} FcSetName;
|
} FcSetName;
|
||||||
|
|
||||||
|
typedef struct _FcAtomic FcAtomic;
|
||||||
|
|
||||||
#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
|
#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
|
||||||
#define _FCFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */
|
#define _FCFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */
|
||||||
#define _FCFUNCPROTOEND }
|
#define _FCFUNCPROTOEND }
|
||||||
|
@ -417,6 +419,32 @@ FcFontList (FcConfig *config,
|
||||||
FcPattern *p,
|
FcPattern *p,
|
||||||
FcObjectSet *os);
|
FcObjectSet *os);
|
||||||
|
|
||||||
|
/* fcatomic.c */
|
||||||
|
|
||||||
|
FcAtomic *
|
||||||
|
FcAtomicCreate (const FcChar8 *file);
|
||||||
|
|
||||||
|
FcBool
|
||||||
|
FcAtomicLock (FcAtomic *atomic);
|
||||||
|
|
||||||
|
FcChar8 *
|
||||||
|
FcAtomicNewFile (FcAtomic *atomic);
|
||||||
|
|
||||||
|
FcChar8 *
|
||||||
|
FcAtomicOrigFile (FcAtomic *atomic);
|
||||||
|
|
||||||
|
FcBool
|
||||||
|
FcAtomicReplaceOrig (FcAtomic *atomic);
|
||||||
|
|
||||||
|
void
|
||||||
|
FcAtomicDeleteNew (FcAtomic *atomic);
|
||||||
|
|
||||||
|
void
|
||||||
|
FcAtomicUnlock (FcAtomic *atomic);
|
||||||
|
|
||||||
|
void
|
||||||
|
FcAtomicDestroy (FcAtomic *atomic);
|
||||||
|
|
||||||
/* fcmatch.c */
|
/* fcmatch.c */
|
||||||
FcPattern *
|
FcPattern *
|
||||||
FcFontSetMatch (FcConfig *config,
|
FcFontSetMatch (FcConfig *config,
|
||||||
|
|
|
@ -28,13 +28,13 @@ DEFINES=-DFC_FALLBACK_FONTS='"$(FALLBACK_FONTS)"'
|
||||||
EXPATLIB=-lexpat
|
EXPATLIB=-lexpat
|
||||||
REQUIREDLIBS=$(LDPRELIBS) $(FREETYPE2LIB) $(EXPATLIB)
|
REQUIREDLIBS=$(LDPRELIBS) $(FREETYPE2LIB) $(EXPATLIB)
|
||||||
|
|
||||||
SRCS=fcblanks.c fccache.c fccfg.c fccharset.c fcdbg.c fcdefault.c fcdir.c \
|
SRCS=fcatomic.c fcblanks.c fccache.c fccfg.c fccharset.c fcdbg.c \
|
||||||
fcfreetype.c fcfs.c fcinit.c fclist.c fcmatch.c fcmatrix.c fcname.c \
|
fcdefault.c fcdir.c fcfreetype.c fcfs.c fcinit.c fclist.c fcmatch.c \
|
||||||
fcpat.c fcstr.c fcxml.c
|
fcmatrix.c fcname.c fcpat.c fcstr.c fcxml.c
|
||||||
|
|
||||||
OBJS=fcblanks.o fccache.o fccfg.o fccharset.o fcdbg.o fcdefault.o fcdir.o \
|
OBJS=fcatomic.o fcblanks.o fccache.o fccfg.o fccharset.o fcdbg.o \
|
||||||
fcfreetype.o fcfs.o fcinit.o fclist.o fcmatch.o fcmatrix.o fcname.o \
|
fcdefault.o fcdir.o fcfreetype.o fcfs.o fcinit.o fclist.o fcmatch.o \
|
||||||
fcpat.o fcstr.o fcxml.o
|
fcmatrix.o fcname.o fcpat.o fcstr.o fcxml.o
|
||||||
|
|
||||||
#include <Library.tmpl>
|
#include <Library.tmpl>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $XFree86: xc/lib/fontconfig/src/fccache.c,v 1.3 2002/02/19 07:50:43 keithp Exp $
|
* $XFree86: xc/lib/fontconfig/src/fccache.c,v 1.4 2002/03/01 01:00:54 keithp Exp $
|
||||||
*
|
*
|
||||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||||
*
|
*
|
||||||
|
@ -416,28 +416,20 @@ FcBool
|
||||||
FcFileCacheSave (FcFileCache *cache,
|
FcFileCacheSave (FcFileCache *cache,
|
||||||
const FcChar8 *cache_file)
|
const FcChar8 *cache_file)
|
||||||
{
|
{
|
||||||
FcChar8 *lck;
|
|
||||||
FcChar8 *tmp;
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int h;
|
int h;
|
||||||
FcFileCacheEnt *c;
|
FcFileCacheEnt *c;
|
||||||
|
FcAtomic *atomic;
|
||||||
|
|
||||||
if (!cache->updated && cache->referenced == cache->entries)
|
if (!cache->updated && cache->referenced == cache->entries)
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
|
|
||||||
lck = malloc (strlen ((char *) cache_file)*2 + 4);
|
atomic = FcAtomicCreate (cache_file);
|
||||||
if (!lck)
|
if (!atomic)
|
||||||
goto bail0;
|
goto bail0;
|
||||||
tmp = lck + strlen ((char *) cache_file) + 2;
|
if (!FcAtomicLock (atomic))
|
||||||
strcpy ((char *) lck, (char *) cache_file);
|
|
||||||
strcat ((char *) lck, "L");
|
|
||||||
strcpy ((char *) tmp, (char *) cache_file);
|
|
||||||
strcat ((char *) tmp, "T");
|
|
||||||
if (link ((char *) lck, (char *) cache_file) < 0 && errno != ENOENT)
|
|
||||||
goto bail1;
|
goto bail1;
|
||||||
if (access ((char *) tmp, F_OK) == 0)
|
f = fopen ((char *) FcAtomicNewFile(atomic), "w");
|
||||||
goto bail2;
|
|
||||||
f = fopen ((char *) tmp, "w");
|
|
||||||
if (!f)
|
if (!f)
|
||||||
goto bail2;
|
goto bail2;
|
||||||
|
|
||||||
|
@ -469,21 +461,23 @@ FcFileCacheSave (FcFileCache *cache,
|
||||||
if (fclose (f) == EOF)
|
if (fclose (f) == EOF)
|
||||||
goto bail3;
|
goto bail3;
|
||||||
|
|
||||||
if (rename ((char *) tmp, (char *) cache_file) < 0)
|
if (!FcAtomicReplaceOrig (atomic))
|
||||||
goto bail3;
|
goto bail3;
|
||||||
|
|
||||||
unlink ((char *) lck);
|
FcAtomicUnlock (atomic);
|
||||||
|
FcAtomicDestroy (atomic);
|
||||||
|
|
||||||
cache->updated = FcFalse;
|
cache->updated = FcFalse;
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
|
|
||||||
bail4:
|
bail4:
|
||||||
fclose (f);
|
fclose (f);
|
||||||
bail3:
|
bail3:
|
||||||
unlink ((char *) tmp);
|
FcAtomicDeleteNew (atomic);
|
||||||
bail2:
|
bail2:
|
||||||
unlink ((char *) lck);
|
FcAtomicUnlock (atomic);
|
||||||
bail1:
|
bail1:
|
||||||
free (lck);
|
FcAtomicDestroy (atomic);
|
||||||
bail0:
|
bail0:
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.3 2002/02/18 22:29:28 keithp Exp $
|
* $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.4 2002/02/19 08:33:23 keithp Exp $
|
||||||
*
|
*
|
||||||
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||||
*
|
*
|
||||||
|
@ -200,6 +200,13 @@ struct _FcFileCache {
|
||||||
int referenced;
|
int referenced;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _FcAtomic {
|
||||||
|
FcChar8 *file; /* original file name */
|
||||||
|
FcChar8 *new; /* temp file name -- write data here */
|
||||||
|
FcChar8 *lck; /* lockfile name (used for locking) */
|
||||||
|
FcChar8 *tmp; /* tmpfile name (used for locking) */
|
||||||
|
};
|
||||||
|
|
||||||
struct _FcBlanks {
|
struct _FcBlanks {
|
||||||
int nblank;
|
int nblank;
|
||||||
int sblank;
|
int sblank;
|
||||||
|
|
Loading…
Reference in New Issue