[Thread Prev][Thread Next]   >Date Index >Thread Index

Re: [wmx] Manager::spawn()

Lasse Rasinen - Wed Jan 31 01:04:34 2001

Lasse Rasinen <lrasinen@iki.fi> writes:

> There is a bug in the Manager::spawn(), to be specific, lines 939-948 in
> Manager.C. The code seems to update the DISPLAY environment variable for
> child processes, but it assumes the only dot in the string is between
> display and screen numbers.
> 
> This of course fails spectacularly when, say, your reverse DNS happens to
> be down, and your DISPLAY is 123.321.123.123:0.0, bad things happen (like
> rxvt: can't open display 123.0)
> 
> I don't offer a fix because I don't know what's the specific form of that
> variable, ie. is there always the dot between display and screen or not.
> 
> (If there is, then the fix is simply to make for loop find the last dot
> and not the first as it does not)

OK, assuming the X man page is correct, they all are of that shape.

| DISPLAY NAMES
|        From the user's perspective, every X server has a  display
|        name of the form:
| 
|                   hostname:displaynumber.screennumber
| 

Following also the 7th C Commandment, 
"Thou shalt study thy libraries and strive not to reinvent them without
cause, that thy code may be short and readable and thy days pleasant and
productive." <http://www.lysator.liu.se/c/ten-commandments.html>,
I also use strrchr() in the patch..

--- Manager.C.old       Wed Jan 31 01:51:33 2001
+++ Manager.C   Wed Jan 31 01:57:57 2001
@@ -941,9 +941,8 @@
                char *pstring = (char *)malloc(strlen(displayName) + 11 +
                                               numdigits(screen()));
                sprintf(pstring, "DISPLAY=%s", displayName);
-               for(c=pstring; *c && (*c != '.'); c++);
-               *(c++)='.';
-               sprintf(c, "%d", screen());
+               c = strrchr(pstring, '.');
+               sprintf(c + 1, "%d", screen());
                putenv(pstring);
            }
 

-- 
Lasse Rasinen
lrasinen@iki.fi


Next: