Re: .X11-unix and the sticky bit
Re: .X11-unix and the sticky bit
- Subject: Re: .X11-unix and the sticky bit
- From: Ronnie Misra <email@hidden>
- Date: Tue, 13 Apr 2004 14:53:57 -0700
On Apr 13, 2004, at 1:56 PM, Torrey T. Lyons wrote:
At 4:23 PM -0400 4/13/04, matt shultz wrote:
> Is there a reason you have to hardcode display 5? Why not detect
which
socket files are already there and choose a display that you know is
not in use?
We hardcode display 5 so that if a user quits our application and
relaunches we can detect if our X server is running, with specific
options, and we don't have to restart X. This way we check if a X
server
is running on display 5 and if it is we assume it's ours and our
application will be able to run under it.
You don't want to do this even if you were not having other problems.
With fast user switching you could easily have another user using
display 5. (The X server keeps trying different display numbers when
it starts up till it finds and unused one.) The proper thing to do is
to search the process list for your application. If your application
is running, how do you know which display it is running on? I think
the best thing to do is that when your application starts up it should
save the contents of the DISPLAY environment variable to some user
specific known location. For example, ~/.myCoolAppsDisplay. Then if
the current user is running your application already, you just need to
read ~/.myCoolAppsDisplay to find out which display this user's
incarnation of your app is connected to. Much more robust.
You could write a little program to probe displays to find one that
matches the properties you want; if you don't find one, then launch
your own. This probing program would look at the lock files in /tmp
(.X0-lock, .X1-lock, ...). For each of these displays, query for visual
info (XGetVisualInfo). When you find one that is PseudoColor, use that
one. If you don't find one, launch your own.
This scheme also means that your app won't get confused if another
user's session is already running X11 on display 5 - the probing
application won't be able to connect to other users' servers.
You can do this all from a perl script:
#!/usr/bin/perl
use strict;
my $found = -1;
my %running;
foreach my $lock (`ls /tmp/.X*-lock 2>/dev/null`) {
$lock =~ m|([0-9]+)|;
my $disp = $1;
$running{$disp} = 1;
my $info = `xwininfo -root -display :$disp 2>/dev/null`;
if ($info =~ m|PseudoColor|) {
$found = $disp;
last;
}
}
if ($found == -1) {
for (my $i = 0; ; $i++) {
if (!$running{$i}) {
print "launch new server as $i\n";
last;
}
}
} else {
print "found PseudoColor display $found\n";
}
Ronnie
_______________________________________________
x11-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/x11-users
Do not post admin requests to the list. They will be ignored.