Detecting X11.app with launchd, was Re: The meaning(s) of $DISPLAY
Detecting X11.app with launchd, was Re: The meaning(s) of $DISPLAY
- Subject: Detecting X11.app with launchd, was Re: The meaning(s) of $DISPLAY
- From: Ben Byer <email@hidden>
- Date: Mon, 19 Nov 2007 01:06:46 -0800
On Nov 18, 2007, at 10:14 PM, Nathaniel Gray wrote:
On Nov 18, 2007 4:20 PM, Ben Byer <email@hidden> wrote:
On Nov 18, 2007, at 2: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.
Why? :D
Is it really so hard to imagine a situation where you don't want to
launch an X server if it's not already running? Even if we ignore the
X11.app icon bouncing up in the dock it's not like ~/.xinitrc is
guaranteed to be free of side-effects.
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.
In all seriousness, what end goal are you trying to accomplish?
Why do you
need to know if an X server is running, unless you then want to use
it (by
connecting to $DISPLAY)?
Because my program is not primarily an X11 client, it's a multi-mode
program that has an X11 module. The current approach is that when
it's triggered it tries to connect to DISPLAY, and if that doesn't
work the X11 module does nothing. There's still lots of other
interesting work to be done, just not in X.
If you want to know the whole story, check out the website:
http://www.n8gray.org/code/forget-me-not
See, this is why I wanted more info about what you would like to
accomplish. Launchd can answer this question for you, and it can do
so in a way that is robust (i.e. it won't get confused if you have
multiple users logged in to the same machine.)
If you want to test this out on the command line, the command
"launchctl list org.x.X11" will spit out a plist data structure that
describes that LaunchAgent. If it is currently running for the current
user, it will list the pid of the process along with the other
attributes of the launchd plist. So, you just need to use this
functionality in your program; you can even use the programmatic
interface to launchd to get this info. (As far as I know, this should
degrade gracefully back to at least Tiger, if not Panther -- a Tiger
user won't have anything that matches org.x.X11, so the launchd check
will have no effect).
My ObjC is horrendous and I wasn't able to figure out how to properly
test this, but I hope the attached patch will point you in the right
direction.
Attachment:
FMN-X11-launchd.patch
Description: Binary data
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.
;^)
How about this?
# If no display has been specified, deduce local display number
from X11
process.
if [ "$DISPLAY" = "" ]; then
export DISPLAY = `ps auxww | grep $USER | egrep
'(Xauthority|/Applications/Utilities/X11.app/Contents/MacOS/X11 .*:
[0-9]+$)'
| grep -v grep | sed 's/^.*\(:[0-9][0-9]*\)$/\1/'`
fi
I just started to write an indignant reply but then I realized you're
probably kidding. You must be kidding, right? :-)
Oh, please. I'm not unreasonable! Martin correctly guessed the owner
of that code; unfortunately, it fails on Leopard because we moved
X11.app. :/
--
Ben Byer
CoreOS / BSD Technology Group, XDarwin maintainer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden