tlibdraw: use proper pipe for default font data - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 4ae529dbfe8573ae105d0d66f7f453c4f850fa1f
 (DIR) parent 4c54893156cf2489081fe63eb37a0e4d3ede1e05
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Tue, 14 Jan 2020 13:18:29 -0500
       
       libdraw: use proper pipe for default font data
       
       May fix a deadlock / missing font on OpenBSD.
       
       Fixes #308.
       
       Diffstat:
         M src/libdraw/getsubfont.c            |      22 ++++++++++++++++------
       
       1 file changed, 16 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/src/libdraw/getsubfont.c b/src/libdraw/getsubfont.c
       t@@ -53,15 +53,25 @@ _getsubfont(Display *d, char *name)
        static int
        defaultpipe(void)
        {
       -        int p[2];
       +        int p[2], pid;
        
       -        // assuming defontdata (<5k) fits in pipe buffer.
       -        // especially reasonable since p9pipe is actually
       -        // a socket pair.
       +        // Used to assume that defontdata (<5k) fit in the
       +        // pipe buffer, especially since p9pipe is actually
       +        // a socket pair. But OpenBSD in particular saw hangs,
       +        // so feed the pipe it the "right" way with a subprocess.
                if(pipe(p) < 0)
                        return -1;
       -        write(p[1], defontdata, sizeof defontdata);
       -        close(p[1]);
       +        if((pid = fork()) < 0) {
       +                close(p[0]);
       +                close(p[1]);
       +                return -1;
       +        }
       +        if(pid == 0) {
       +                close(p[0]);
       +                write(p[1], defontdata, sizeof defontdata);
       +                close(p[1]);
       +                _exit(0);
       +        }
                return p[0];
        }