# $Id: default_chld.pm,v 1.1 1999/04/02 15:41:19 v2kea318 Exp $
# $Log: default_chld.pm,v $
# Revision 1.1  1999/04/02  15:41:19  v2kea318
# Initial revision
#
#***************************************************************************

=head1 NAME

default_chld - a module to define an environment with the default CHLD handler

=head1 DESCRIPTION

This module will define a syntactic construction, DefaultCHLD, which will 
execute the enclosed code block with the default CHLD signal handler, then 
restore the program defined handler upon completion.

=cut

#***************************************************************************

my $curchldsig = 'DEFAULT';

#***************************************************************************

sub restore_default_chld() {
  # Restore the default CHLD signal handler, storing the current value
  # in $curchldsig.
  $curchldsig = $SIG{CHLD};
  $SIG{CHLD} = 'DEFAULT';
}

#***************************************************************************

sub restore_prog_chld() {
  # Restore the program defined CHLD signal handler.
  $SIG{CHLD} = $curchldsig;
}

#***************************************************************************

sub DefaultCHLD(&) { # a syntactic construction that will execute the 
                     # enclosed code block with the default CHLD signal
                     # handler then restore the program defined handler
                     # upon completion.
  my $code = shift();

  restore_default_chld();
  my $rcd = &$code();
  restore_prog_chld();
  return $rcd if ($rcd);
}

#***************************************************************************

1;
