[comp.windows.x] Help Please: How do I find out if X-windows is running?

frank@odetics.com (Frank Merrow) (05/11/91)

Hi,

I am working on my first Xview program.  By chance I tried it last
night via modem expecting it to give me "no server available" or
some such thing.  Instead it gave me a segmentation fault (Sun 386i).
This morning at work I also tried to run it from another X11 system
and have it display on my system using -display=mars:0 and again
I got a segmentation fault.  I have included my startup code below
(which works WHEN running on my station under OpenLook)
All it ever prints in the other two cases is "Hi There".  Any Ideas?

Frank
frank@odetics.com or uunet!odetics!frank

P.S. From the xview book it is not clear what xv_init() returns on
error (something about a Server).  At any rate the NULL check was
a wild idea on my part.  But the bottom line seems to be that once
I call xv_init() I will abort if the server is not available.  Is
there something I can/should be calling first to test for it?

main (argc,argv)
   int  argc;
   char *argv[];

{
int event_mask;

/* I will start by initializing XView and creating my Base Frame.	*/

printf("Hi There\n");
if (xv_init (XV_INIT_ARGC_PTR_ARGV,&argc,argv,NULL) == NULL)
   {
   printf("xv_init() Error - Are you sure you are running X11?\n");
   exit (1);
   }

printf("Hi Again\n");

. . . 

guy@auspex.auspex.com (Guy Harris) (05/13/91)

>I am working on my first Xview program.  By chance I tried it last
>night via modem expecting it to give me "no server available" or
>some such thing.  Instead it gave me a segmentation fault (Sun 386i).

That's a bug in XView; the code that tries to print the "no server
available" message is broken, and assumes that the DISPLAY environment
variable is set, and therefore that the pointer returned by
'getenv("DISPLAY")' can safely be dereferenced.  Needless to say, that
is *not* necessarily true.

I posted a fix for it to "comp.windows.open-look" a while ago; a
workaround might be to try doing an "XOpenDisplay()" call yourself (you
might not want to just check whether DISPLAY is set, because a lot of
programs will just try to open ":0" if it's not, rather than assuming X
isn't up) and see if it succeeds.