[comp.windows.x] R3 bug/misfeature: DISPLAY setting in xinit

spaf@PURDUE.EDU (Gene Spafford) (10/31/88)

VERSION:
    R3

CLIENT MACHINE and OPERATING SYSTEM:
    Sun 3/60 w 68881 running SunOS 3.4

DISPLAY:
    FC (Sony 17")

AREA:
    xinit

SYNOPSIS:
    xinit overrides the user environment for the value of the variable
    DISPLAY and sets its own value.  This is antisocial in cases where
    the user has set DISPLAY on purpose.

DESCRIPTION:
    xinit always sets the display to host:0 with this kind of
    configuration.  However, with a cgfour display, there are "two"
    screens available, with the color screen being 0.1 and the b/w
    being 0.0.  By overriding the user setting of DISPLAY (e.g., from
    host:0.1 to host:0), the b/w screen becomes the default and all
    clients realize on the b/w screen.

    This also results in bizarre behavior in some other programs...for
    instance, attempts to execute  "awm -b -display host:0.1" in the
    xinit startup file results in it dumping core.  Some other clients
    behave the same way.

    Trying "xinit -- Xsun :0.1" results in the xinit program never
    establishing a connection with the Xsun server.

REPEAT BY:
    Try it.

SAMPLE FIX:
*** xinit.c.orig	Sun Oct 30 14:05:46 1988
--- xinit.c	Sun Oct 30 14:12:49 1988
***************
*** 560,566 ****
  set_environment ()
  {
      int nenvvars;
!     char **newPtr, **oldPtr;
      static char displaybuf[256];
  
      /* count number of environment variables */
--- 560,566 ----
  set_environment ()
  {
      int nenvvars;
!     char **newPtr, **oldPtr, *ocp;
      static char displaybuf[256];
  
      /* count number of environment variables */
***************
*** 574,585 ****
  		 program, nenvvars + 2);
  	exit (1);
      }
  
      /* put DISPLAY=displayname as first element */
      strcpy (displaybuf, "DISPLAY=");
      strcpy (displaybuf + 8, displayname);
-     newPtr = newenviron;
      *newPtr++ = displaybuf;
  
      /* copy pointers to other variables */
      for (oldPtr = environ; *oldPtr; oldPtr++) {
--- 574,591 ----
  		 program, nenvvars + 2);
  	exit (1);
      }
+     newPtr = newenviron;
  
      /* put DISPLAY=displayname as first element */
+     ocp = getenv("DISPLAY");
+     if (ocp != NULL)
+ 	*newPtr++ = ocp;
+     else
+     {
  	strcpy (displaybuf, "DISPLAY=");
  	strcpy (displaybuf + 8, displayname);
  	*newPtr++ = displaybuf;
+     }
  
      /* copy pointers to other variables */
      for (oldPtr = environ; *oldPtr; oldPtr++) {

spaf@PURDUE.EDU (Gene Spafford) (11/01/88)

Arggh!  This is what I get for saving intermediate versions!

The patch I mailed for xinit was not the correct one.  What follows
is:


*** xinit.c.orig	Sun Oct 30 14:05:46 1988
--- xinit.c	Mon Oct 31 11:22:27 1988
***************
*** 560,566 ****
  set_environment ()
  {
      int nenvvars;
!     char **newPtr, **oldPtr;
      static char displaybuf[256];
  
      /* count number of environment variables */
--- 560,566 ----
  set_environment ()
  {
      int nenvvars;
!     char **newPtr, **oldPtr, *ocp;
      static char displaybuf[256];
  
      /* count number of environment variables */
***************
*** 574,584 ****
  		 program, nenvvars + 2);
  	exit (1);
      }
  
      /* put DISPLAY=displayname as first element */
      strcpy (displaybuf, "DISPLAY=");
!     strcpy (displaybuf + 8, displayname);
!     newPtr = newenviron;
      *newPtr++ = displaybuf;
  
      /* copy pointers to other variables */
--- 574,585 ----
  		 program, nenvvars + 2);
  	exit (1);
      }
+     newPtr = newenviron;
  
      /* put DISPLAY=displayname as first element */
      strcpy (displaybuf, "DISPLAY=");
!     ocp = getenv("DISPLAY");
!     strcat (displaybuf, (ocp != NULL) ? ocp : displayname);
      *newPtr++ = displaybuf;
  
      /* copy pointers to other variables */