Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations)
Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations)
- Subject: Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations)
- From: "Nathaniel Gray" <email@hidden>
- Date: Sun, 18 Nov 2007 15:37:06 -0800
On Nov 18, 2007 3:01 PM, Andrew J. Hesford <email@hidden> wrote:
> On Nov 18, 2007, at 4:31 PM, Nathaniel Gray wrote:
>
> > I'm pretty happy with the new way, but I *would* like a bulletproof
> > way of knowing if $DISPLAY is connected to a running X server. I've
> > got some code (mostly working around the lack of accessibility info in
> > X) that tries to connect to DISPLAY as a way of checking for a running
> > X server, since that seemed like the best way of detecting that.
> > Since that's no longer appropriate I need a replacement, and I really
> > hope you aren't going to say "ps -a -U $USER | grep X11" or some such.
> > ;^)
>
>
> Yes, grepping for X11 is an ugly solution. But you can't deny that it
> works! Don't forget "grep -v grep" to avoid false hits when grep
> matches itself.
I'm not convinced it works. If the user has started a different
server that's not connected to DISPLAY in the current environment it
breaks. If DISPLAY is connected to a remote machine by SSH forwarding
it breaks. These are somewhat unlikely scenarios for the software I'm
writing, but I'm aiming for correct code, not kinda-correct code.
> Looking at the manpage, I don't see the facility for this, but I think
> a nice way to do this (for general processes) would be to query
> launchctl. Something along the lines of `launchctl status org.x.X11`.
> The program could then print one of "running", "available" or
> "disabled", depending on the job's status. It could also set a return
> value based on the status. For example, 0 for "running" or
> "available", 128 for "disabled". This allows you to do a bunch of tests:
>
> if ! launchctl status org.x.X11 > /dev/null; then DONT_START_X_STUFF;
> fi
> if ! launchctl status org.x.X11 | grep running > /dev/null; then
> X_NOT_RUNNING; fi
>
> and so on. With these return codes, you have a quick check to
> determine if you CAN do something with X. If you want to distinguish
> between a running or available-to-run server, you have to take the
> extra step with grep.
>
> Of course, this isn't just limited to X11.
Right, this is a much better idea. I would like it even better if I
could ask about the service connected to a specific socket.
Cheers,
-n8
--
>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden