XForms: Infinite loop in fl_signal_caught() under IRIX 6.x

Steve Lamont (spl@szechuan.ucsd.edu)
Tue, 1 Dec 98 11:34:00 PST

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

I spent a hour or so chasing a problem in an application which uses
fl_add_signal_callback() to catch a SIGCHLD signal generated when a
fork()/exec() subprocess completes (to do the wait() and clean up the
zombie).

Under IRIX 6.2 (at least -- haven't tested it elsewhere), the default
action of the XForms signal handler is to call fl_signal_caught()
which calls signal() to re-enable the signal. Unfortunately, since
the signal is still pending (the handler has not exited), this causes
IRIX to call the signal handler again, which calls fl_signal_caught(),
which... and so forth until you blow out the top of the stack and core
dump.

The workaround is to use fl_app_signal_direct( True ) and catch the
signal yourself:

pid_t *kid = ( pid_t *) malloc( sizeof( pid_t ) );

switch ( *kid = fork() ) {

default: {

fl_app_signal_direct( True );
signal( SIGCHLD, catch );
fl_add_signal_callback( SIGCHLD, child_cleanup, ( void *) kid );
break;

}
case 0: {

execl( ... whatever ... );
die( "Ooooooh, bad news! I couldn't execl %s!!!!", buffer );
break;

}

[...]

void catch( int sig )

{

fl_signal_caught( sig );

}

void child_cleanup( int signal, void *data )

{

if ( signal == SIGCHLD ) {

pid_t kid_pid = *( ( pid_t *) data );
pid_t wait_pid;
int status;

while ( ( kid_pid != ( wait_pid =
waitpid( kid_pid, &status, WNOHANG ) )
) &&
( errno == EINTR ) )
;
free( data );

}

}

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/