[comp.windows.x] X V10 XOpenDisplay - should it assume hostname:0??

jmsellens@watdragon.waterloo.EDU ("John M. Sellens") (09/28/87)

Currently, it seems that the X V10.4 XOpenDisplay requires
either an argument or an environment variable, and if both of
of them are missing, or if a display number is not given,
then XOpenDisplay will fail.  My question is: isn't it
reasonable for it to assume the current host and display 0
if either or both are missing?

John Sellens -- Logic Programming and Artificial Intelligence Group

{decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdragon!jmsellens
jmsellens@dragon.waterloo.{edu,CDN} jsellens@watmta.BITNET
jmsellens%dragon@waterloo.csnet

jg@jumbo.dec.com (Jim Gettys) (09/28/87)

Not really; there are people who run more than server from a single
machine.  This was true for VS100's, and is true today for some
VAXstation II/GPX machines (dual headed) and for various terminals or
IBM PC's running X by running multiple servers on the same host.

It is more than slightly irritating if other people's mistakes pop
up windows on your display.

Another common scenario is when someone else is logged in to your
workstation remotely, and forgets to set the DISPLAY variable.  Do
you really want his program to pop up on your screen?  It seemed best
to return an error rather than blindly continue.
				Jim Gettys

raveling@VAXA.ISI.EDU (Paul Raveling) (09/28/87)

John Sellens suggested:

	Currently, it seems that the X V10.4 XOpenDisplay requires
	either an argument or an environment variable, and if both of
	of them are missing, or if a display number is not given,
	then XOpenDisplay will fail.  My question is: isn't it
	reasonable for it to assume the current host and display 0
	if either or both are missing?
	
    In my opinion this is eminently reasonable.  I'd rather have Xlib
    take a reasonable default than to have to code the defaulting into
    each client we write.

Jim Gettys answered:

	Not really; there are people who run more than server from a single
	machine.  This was true for VS100's, and is true today for some
	VAXstation II/GPX machines (dual headed) ...
	
	It is more than slightly irritating if other people's mistakes pop
	up windows on your display. ... It seemed best to return an error
	rather than blindly continue.

    We haven't, to my knowledge, had that sort of threat yet in using
    X in our corner of ISI.  In our environment the benefits of this
    defaulting would outweigh the risks.

    BTW, I'm using a two-headed Bobcat; others on our project have
    private single-headed Bobcats at this time.


---------------------
Paul Raveling
Raveling@vaxa.isi.edu

jkh@violet.berkeley.edu (Jordan K. Hubbard) (09/28/87)

In article <8709280101.AA26155@watdragon.uucp> jmsellens@watdragon.waterloo.EDU ("John M. Sellens") writes:
>Currently, it seems that the X V10.4 XOpenDisplay requires
>either an argument or an environment variable, and if both of
>of them are missing, or if a display number is not given,
>then XOpenDisplay will fail.  My question is: isn't it
>reasonable for it to assume the current host and display 0
>if either or both are missing?

That would be cool, if the C language would guarantee you NULLs for
unspecified arguments. I don't believe that this is assured under all
architectures. Variable arguments invariably lose, unless you use VARARGS.

						Jordan

jmsellens@watdragon.waterloo.edu (John M. Sellens) (10/06/87)

I (John Sellens) originally asked:
>	Currently, it seems that the X V10.4 XOpenDisplay requires
>	either an argument or an environment variable, and if both of
>	of them are missing, or if a display number is not given,
>	then XOpenDisplay will fail.  My question is: isn't it
>	reasonable for it to assume the current host and display 0
>	if either or both are missing?
>	

Jim Gettys answered:
>	Not really; there are people who run more than server from a single
>	machine.  This was true for VS100's, and is true today for some
>	VAXstation II/GPX machines (dual headed) ...
>	
>	It is more than slightly irritating if other people's mistakes pop
>	up windows on your display. ... It seemed best to return an error
>	rather than blindly continue.

and Paul Raveling added:
>    In my opinion this is eminently reasonable.  I'd rather have Xlib
>    take a reasonable default than to have to code the defaulting into
>    each client we write.
>
>    We haven't, to my knowledge, had that sort of threat yet in using
>    X in our corner of ISI.  In our environment the benefits of this
>    defaulting would outweigh the risks.
>
>    BTW, I'm using a two-headed Bobcat; others on our project have
>    private single-headed Bobcats at this time.


So - I figured what the heck, and added it to our copy of Xlib anyway.
It seems to work, so I thought that I would throw it out into the net
in case anyone else was interested.  Just a couple of trivial changes
to Xlib/XDisplayName.c, the revised version of which is included here
in all it's splendor - the changes are marked with #ifdef waterloo.

John

John Sellens -- Logic Programming and Artificial Intelligence Group

{decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdragon!jmsellens
jmsellens@dragon.waterloo.{edu,CDN} jsellens@watmta.BITNET
jmsellens%dragon@waterloo.csnet



/* $Header: XDisplayName.c,v 10.1 86/11/19 18:17:19 jg Rel $ */

/* XDisplayName.c */
/* 
 * Returns the name of the display XOpenDisplay would use.  This is better
 * than just printing the "display" variable in a program because that
 * could be NULL and/or there could be an environment variable set.
 * This makes it easier for programmers to provide meaningful error
 * messages. 
 *
 * 
 * For example, this is used in XOpenDisplay() as
 *	strncpy( displaybuf, XDisplayName( display ), sizeof(displaybuf) );
 *      if ( *displaybuf == '\0' ) return( NULL );
 *  This check is actually unnecessary because the next thing is an index()
 *  call looking for a ':' which will fail and we'll return(NULL).
 */
/* Written at Waterloo - JMSellens */

#include <stdio.h>
#ifdef waterloo
#include <sys/param.h>	/* for MAXHOSTNAMELEN */
#endif

char *getenv();


char *
XDisplayName( display )
char *display;
{
#ifdef waterloo
    /* has to be static since we return it */
    static char hname[MAXHOSTNAMELEN+5];	/* xtra space for :0 */
#endif
    char *d;
    if ( display != (char *)NULL && *display != '\0' )
	return( display );
    if ( (d = getenv( "DISPLAY" )) != (char *)NULL )
	return( d );
#ifdef waterloo
    /* This causes XOpenDisplay to assume the current host for display if
       no other guess is available - Jim Gettys said it would be a
       bad thing and lead to more people popping windows on your
       terminal by accident - JMS Oct 5/87 */
    if ( gethostname(hname,sizeof(hname))==0 ) {
	(void) strcat( hname, ":0" );
	return( hname );
    }
#endif
    return( "" );
}