libdraw: use proper pipe for default font data

May fix a deadlock / missing font on OpenBSD.

Fixes #308.
This commit is contained in:
Russ Cox 2020-01-14 13:18:29 -05:00
parent 4c54893156
commit 4ae529dbfe

View file

@ -53,15 +53,25 @@ _getsubfont(Display *d, char *name)
static int static int
defaultpipe(void) defaultpipe(void)
{ {
int p[2]; int p[2], pid;
// assuming defontdata (<5k) fits in pipe buffer. // Used to assume that defontdata (<5k) fit in the
// especially reasonable since p9pipe is actually // pipe buffer, especially since p9pipe is actually
// a socket pair. // a socket pair. But OpenBSD in particular saw hangs,
// so feed the pipe it the "right" way with a subprocess.
if(pipe(p) < 0) if(pipe(p) < 0)
return -1; return -1;
write(p[1], defontdata, sizeof defontdata); if((pid = fork()) < 0) {
close(p[1]); 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]; return p[0];
} }