TASdvlper has asked for the wisdom of the Perl Monks concerning the following question:
** Update ** Actually, one thing I left out was I am using $SIG{CHLD} at the top of my code so all children get cleaned up properly. I believe this could be what is causing the bad return code ??? Also, I read the comments about using the regexp in the system call and, while I do understand your statement, once this code is integrated into the rest of my code, there is no way the client can pass in a "bad comment" (like you suggested). Without going into details, the client will only have a set up known "scripts" which will be executed. But thanks for your feedback, it is definately something I will keep in mind.while (($new_sock, $c_addr) = $sock->accept()) { die "Can't fork: $!" unless defined ($pid = fork()); if ( $pid == 0 ) { # Child code $sock->close; my ($client_port, $c_ip) = sockaddr_in($c_addr); my $client_ipnum = inet_ntoa($c_ip); my $client_host = gethostbyaddr($c_ip, AF_INET); print "CHILD CODE [cpid::$$]: Connection from: $client_host [$cl +ient_ipnum ", $new_sock->peerport, "] \n\n"; while (defined($buf = <$new_sock>) ) { if ($buf =~ /^EXECUTE:(.*)/ ) { print $1, "\n"; system("/msg/spgear/tools/bin/perl $1") || die "Could not +run program: $1 -- $!\n"; my $rtn = $?; print $new_sock "RETURN CODE: $rtn", "\n"; } else { print "INVALID SYNTAX\n"; print $new_sock "INVALID SYNTAX\n"; } } exit 0; } else { # Parent code $new_sock->close; print "\nPARENT CODE [ppid::$$ cpid:$pid]\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wrong return code after a system call
by antirice (Priest) on Oct 23, 2003 at 20:47 UTC | |
by PodMaster (Abbot) on Oct 24, 2003 at 07:25 UTC |