foreach $serv ( @serv ) { $command="/bin/ldapsearch -h $serv -b '' -s base 'objectclass=*' |"; DEBUG_msg("Forking child to run $command"); $pid=fork(); if ( ! defined $pid ) { ERROR_exit("Unable to fork process for $serv in $dmn"); } elsif ( $pid == 0 ) { # We are the child - run the LDAP command, find ldapServiceName and # compare the domain with the one we're checking and then exit # with the appropriate status ... open(INP,$command) or ERROR_exit("Unable to run LDAP search $!"); while( $data= ) { chomp($data); (@words)=split(/:/,$data); if ( $words[0] eq "ldapServiceName" ) { # Now have the info - extract domain ... $words[2]=~ s/.*\@//; $words[2]= lc($words[2]); DEBUG_msg(" Found $words[2] for $serv"); if ( $words[2] eq $dmn ) { DEBUG_msg(" matches expected domain - exit OK"); exit 5; } else { DEBUG_msg(" domain mismatch - exit FAIL"); exit 2; } } } close(INP); # Didnt find the data - exit from child with error exit 3; } else { # Still in parent $pid the PID of the child DEBUG_msg(" Child process $pid"); $pid_list{$pid}=$serv.":".$dmn; } } foreach $pid ( keys %pid_list ) { DEBUG_msg("Checking state of $pid"); $res=waitpid($pid,WNOHANG); $rc=$res >> 8; my $tst=$res/256; print STDERR "PID $pid res $res rc $rc test $tst "; #### Debug: PID 20670 Child process 20692 Debug: PID 20670 Child process 20694 Debug: PID 20670 Child process 20697 Debug: PID 20670 Child process 20699 Debug: PID 20670 Child process 20702 Debug: PID 20670 Child process 20705 Debug: PID 20694 matches expected domain - exit OK Debug: PID 20702 matches expected domain - exit OK Debug: PID 20699 matches expected domain - exit OK Debug: PID 20670 Checking state of 20692 PID 20692 res 0 rc 0 test 0 Debug: PID 20670 Checking state of 20702 PID 20702 res 20702 rc 80 test 80 Debug: PID 20670 Checking state of 20697 PID 20697 res 0 rc 0 test 0 Debug: PID 20670 Checking state of 20694 PID 20694 res 20694 rc 80 test 80 Debug: PID 20670 Checking state of 20699 PID 20699 res 20699 rc 80 test 80 Debug: PID 20670 Checking state of 20705 PID 20705 res 0 rc 0 test 0