Re: XForms: XForms/fork()/events

Steve Lamont (spl@szechuan.ucsd.edu)
Wed, 2 Jul 97 13:10:52 PDT

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> This works fine when I don't use the fork. But I can't use this form and
> the main form (and the other forms) at the same time. When I use fork to
> create a new process which should handle the "send signals" form the program
> dies with an "Xlib: unexpected async reply (sequence 0x879)!" (the number
> changes).

One possibility is that when the child process dies or closes down, it
is closing down the X connection to the server, which then causes Xlib
in the parent to get massively confused since it gets a message from
the server that really should be destined for the child (or, to be
completely correct, never sent at all).

What you need to do is to shut down the X connection on the child
process so that when it goes away it doesn't try to communicate with
the server. Do this by getting the connection number (the file
descriptor under Unix) and issuing a close. Here's a little bit of
test code I whomped up that does this:

#include <stdio.h>
#include <signal.h>
#include "forms.h"
#include "try.h"

int pid;

void spawn_cb(FL_OBJECT *ob, long data)
{

if ( !( pid = fork() ) ) {

/*
* If we find ourselves here, we're the child process...
*/

int connection_fd = ConnectionNumber( fl_get_display() );

close( connection_fd ); /* Close down gracefully */

while ( 1 ) /* This is where we'd do the child process work */
sleep( 1 ); /* In our test, we just buzz */

}

}

void zap_cb(FL_OBJECT *ob, long data)
{

kill( pid, SIGINT ); /* You may want to replace this with */
/* some other signal */

}

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/