X startup and authorization

Alan Coopersmith alan.coopersmith at oracle.com
Mon May 24 18:53:39 PDT 2010


tom fogal wrote:
> The first issue is startup: we fork and then exec `xinit' in the child;
> the parent sets the appropriate DISPLAY and renders into it.  The
> issue we have is that the parent does not know when the X server is
> "ready" for rendering.  Our current "solution" is to sleep a bit, which
> obviously isn't great.  How can I tell when a server has initialized?

The xserver notifies its parent - xinit/xdm/etc. - via a signal, at which
point they start clients - presumably you'd put something in the .xinitrc
to in turn signal your parent process that called xinit.

You could of course take xinit out of the middle and exec the X server
from your software so it gets the signal or error return directly - you
can see from the source it's not that complicated.

> The second is authorization.  I'll admit to not understanding this
> thoroughly.  It sounds like I want to create an MIT-MAGIC-COOKIE-1,
> tell the X server about it when I start (how?), and then shove it in a
> file which I point to using the XAUTHORITY environment var.  Does that
> sound like the best approach in terms of portability?  Ideally whatever
> I implement would work with some pretty old X servers (5 years or so).

That should work with X servers going back about 15 years.   To inform the
server of the cookie, you can use the -auth flag to the server - see the
startx script in the xinit sources for example.

> Also on the topic of authorization -- where is the API for this?
> `xhost' and `xauth' must be using Xlib functions to do their magic,
> right?  I'd really like to avoid having to system() or fork/exec to do
> proper authorization.

Xauthority file manipulation is in the libXau library - see "man XauWriteAuth"
xhost manipulation happens via the libX11 API's you can read about
on "man XAddHost".

Of course, the xauth & xinit sources have examples.

-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System




More information about the xorg mailing list