From: Marc M. <mwm...@ro...> - 2002-12-04 22:27:59
|
I've written a little forking program as an experiment. I've commented the code changes made. Not much other than a couple of new variables and the forking code. Here is a snippet of what the new function looks like. Everything below 'end new code' stays the same. However, with the broken $data=`$exec` command seems to go off into it's own little world, but at least the overall slashd process seems to be running smoothly. Before I think it was never returning and holding things up. Now it's never returning and not messing things up. I'll have to do more reading to make sure the spawned process is successfully ended. This kind of fix isn't my ideal solution. I really think it's either a Perl or system thing, but I could be wrong. I can kill the slashd processes that go off into their own little world and the parent slashd process continues humming along. The real issue here is why does the backtick call $data=`$exec` never return? sub prog2file { my($command, $arguments, $f, $verbosity, $handle_err) = @_; return 0 unless -e $command and -r _ and -x _; $verbosity ||= 0; $handle_err ||= 0; my $success = 0; my $err_str = ""; my $exec = "$command $arguments"; my($data, $err); my($pid, @output); #added by Marc # Two ways of handling data from child programs yet we maintain # backwards compatibility. if (! $handle_err) { # commented out by marc $data = `$exec`; # begin new code die "cannot fork: $!" unless defined ($pid = open(SAFE_KID, "|-")); if ($pid == 0) { $data = `$exec` or die "can't exec prog2file call: $!"; } else { @output = <SAFE_KID>; close SAFE_KID; # $? contains status } # end new code |