XForms: XForms/fork()/events

Peter Tobias (tobias@et-inf.fho-emden.de)
Wed, 2 Jul 1997 18:16:10 +0200

To subscribers of the xforms list from Peter Tobias <tobias@et-inf.fho-emden.de> :

Hello,

I have a small problem with xforms 0.86. My main program uses a simple
fl_do_forms loop to check for some buttons. Pressing the button "cap" in
the main window calls a callback function (cb_capdata). This callback
function deactivates the main form and creates a new form. If the user
presses the "go" button the program starts an external program and creates
a new process by using fork (without exec).
This new process should simply show a form where the user can send signals
(SIGINT or SIGUSR1) to the external program. If the user uses the button
to send the SIGINT signal to the external program the form should be closed
and and its process should end. This new process/form should not block
the other forms.

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).

How can I tell the new process to work without conflicting with the main
program? In an X11 only program it would probably be possible to open a
new connection to the X display but this probably won't work for xforms
(you can't use something like fl_initialize twice).

According to the xforms manual the fl_X*Event* functions might help but
how should this be done?

Here are the most important parts of the main program and the callback
function:

int main(int argc, char *argv[])
{
...
fl_show_form(pform, FL_PLACE_CENTER, FL_FULLBORDER, FORMTITLE);
while (TRUE) {
action = fl_do_forms();
if (action == bt_cap) {
...
break;
} else if (action == bt_quit) {
...
break;
}
i = fl_get_browser(prot_browser);
if (i == 0) {
...
}
}
return(0);
}
===========================================================================

void cb_capdata(FL_OBJECT *ob, long data)
{
...
fl_deactivate_form(pform);
fl_show_form(cap, FL_PLACE_HOTSPOT, FL_FULLBORDER, "Title");

while(TRUE) {
action = fl_do_forms();
if (action == bt_cap_go) {
...
/* get values from form */
...
/* execute program */
...
if ( (pid = fork()) < 0) /* fork twice so parent process is init */
perror("fork error");
else if (pid == 0) { /* first child */
if ( (pid = fork()) < 0)
perror("fork error");
else if (pid > 0)
exit(0); /* end of process 1 */

/**********************************************************/
/* This is the second process that causes the problems .. */
fl_show_form(cap_stop, FL_PLACE_HOTSPOT, FL_FULLBORDER, "T2");
while (TRUE) {
action_i = fl_check_forms();
waitpid(pid, NULL, WNOHANG);
if (action_i == bt_capstop) {
break;
} else if (action_i == bt_capstats) {
/* send SIGUSR1 to child process */
kill(pid, 10);
}
if (kill(pid, 0) != 0) { /* process still there? */
break;
}
}
kill(pid, SIGINT);
fl_hide_form(cap_stop)
exit(0);
/**********************************************************/
}

/* parent process */
if (waitpid(pid, NULL, 0) != pid)
perror("waitpid error");
break;

}
...
}
fl_hide_form(cap);
fl_activate_form(pform);
}

Thanks in advance,

Peter

-- 
Peter Tobias <tobias@et-inf.fho-emden.de> <tobias@debian.org> <tobias@linux.de>
PGP ID EFAA400D, fingerprint = 06 89 EB 2E 01 7C B4 02  04 62 89 6C 2F DD F1 3C 
_________________________________________________
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/