diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-01-10 22:16:23 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-01-10 22:16:23 +0100 |
commit | 23b189c2bcf2de03902ef0f18e23cf030c6d072a (patch) | |
tree | b26019eca5379ee17c1c8d7f5110a56741b3149b /sys/src/libdraw/init.c | |
parent | 5f54eaddba800ec81c65ab17fa17ddd91cc66470 (diff) |
libdraw: gengetwindow() resize race
instead of trying to make rio not change the window image too fast
and give the client some time to attach it (which turns out to be
impossible), we acknowledge that there is a race and just retry
the window reattach as long as the winname keeps changing in
gengetwindow().
Diffstat (limited to 'sys/src/libdraw/init.c')
-rw-r--r-- | sys/src/libdraw/init.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/sys/src/libdraw/init.c b/sys/src/libdraw/init.c index c0ed2edbf..f7370e3b4 100644 --- a/sys/src/libdraw/init.c +++ b/sys/src/libdraw/init.c @@ -129,10 +129,12 @@ int gengetwindow(Display *d, char *winname, Image **winp, Screen **scrp, int ref) { int n, fd; - char buf[64+1]; + char buf[64+1], obuf[64+1]; Image *image; Rectangle r; + obuf[0] = 0; +retry: fd = open(winname, OREAD); if(fd<0 || (n=read(fd, buf, sizeof buf-1))<=0){ if((image=d->image) == nil){ @@ -147,12 +149,22 @@ gengetwindow(Display *d, char *winname, Image **winp, Screen **scrp, int ref) buf[n] = '\0'; if(*winp != nil){ _freeimage1(*winp); + *winp = nil; freeimage((*scrp)->image); freescreen(*scrp); *scrp = nil; } image = namedimage(d, buf); if(image == 0){ + /* + * theres a race where the winname can change after + * we read it, so keep trying as long as the name + * keeps changing. + */ + if(strcmp(buf, obuf) != 0){ + strcpy(obuf, buf); + goto retry; + } fprint(2, "namedimage %s failed: %r\n", buf); *winp = nil; d->screenimage = nil; |