[PATCH:libXfont 1/2] Set close-on-exec for font file I/O.

Alan Coopersmith alan.coopersmith at oracle.com
Wed Feb 25 15:10:44 PST 2015


On 02/25/15 12:45 PM, Thomas Klausner wrote:
> From: Christos Zoulas <christos at NetBSD.org>
>
> Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
> ---
>   src/fontfile/fileio.c |  5 ++++-
>   src/fontfile/filewr.c | 12 +++++++-----
>   2 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/src/fontfile/fileio.c b/src/fontfile/fileio.c
> index 80af511..d44cecd 100644
> --- a/src/fontfile/fileio.c
> +++ b/src/fontfile/fileio.c
> @@ -36,6 +36,9 @@ in this Software without prior written authorization from The Open Group.
>   #ifndef O_BINARY
>   #define O_BINARY O_RDONLY
>   #endif
> +#ifndef O_CLOEXEC
> +#define O_CLOEXEC 0
> +#endif
>
>   FontFilePtr
>   FontFileOpen (const char *name)
> @@ -44,7 +47,7 @@ FontFileOpen (const char *name)
>       int		len;
>       BufFilePtr	raw, cooked;
>
> -    fd = open (name, O_BINARY);
> +    fd = open (name, O_BINARY|O_CLOEXEC);
>       if (fd < 0)
>   	return 0;
>       raw = BufFileOpenRead (fd);
> diff --git a/src/fontfile/filewr.c b/src/fontfile/filewr.c
> index bcc7b1e..859a0be 100644
> --- a/src/fontfile/filewr.c
> +++ b/src/fontfile/filewr.c
> @@ -33,17 +33,19 @@ in this Software without prior written authorization from The Open Group.
>   #endif
>   #include <X11/fonts/fntfilio.h>
>   #include <X11/Xos.h>
> +#ifndef O_BINARY
> +#define O_BINARY	0
> +#endif
> +#ifndef O_CLOEXEC
> +#define O_CLOEXEC	0
> +#endif
>
>   FontFilePtr
>   FontFileOpenWrite (const char *name)
>   {
>       int	fd;
>
> -#if defined(WIN32) || defined(__CYGWIN__)
> -    fd = open (name, O_CREAT|O_TRUNC|O_RDWR|O_BINARY, 0666);
> -#else
> -    fd = creat (name, 0666);
> -#endif
> +    fd = open (name, O_CREAT|O_TRUNC|O_RDWR|O_BINARY|O_CLOEXEC, 0666);
>       if (fd < 0)
>   	return 0;
>       return (FontFilePtr) BufFileOpenWrite (fd);
>

Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

-- 
	-Alan Coopersmith-              alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc


More information about the xorg-devel mailing list