in reply to Re: inetd spawned perl problem
in thread inetd spawned perl problem

Hi, Thank you very much for your message. I'm using perl 5.005_03 on HP-UX 10.20 and 5.8.0 on Tru64 v5. I think that i've not explained the exact problem.
The connection sequence would be as shown:

At this point, I close the client that calls the telnet. If I start remsh w/o the -n option, then the spawned child remsh process becomes defunct (most probably b'cos the parent remsh process does not do a wait()). If I start remsh with the -n option, then there does not appear to be any signals processed (additionally remsh inherently ignores TERM, INT and QUIT).
So, at this point, I have my perl script still running along with the remsh processes. The script will exit along with the remsh processes only when there is some data returned from remsh and SIGPIPE is received.
Is there any other way I can check for the closure of the socket from my perl script (given the fact that I dont have a file handle on the socket) ? Also, any other way I can check for the closure of STDOUT ? I cant write arbitrary data out to STDOUT as the script writes to another set of processes that parse the data and expect the data to be in a certain format and those processes cannot be modified easily.
Thanks again!

Replies are listed 'Best First'.
Re: Re: Re: inetd spawned perl problem
by Thelonius (Priest) on May 09, 2003 at 18:10 UTC
    Here is my interpretation of what you describe:

    A client process "C" connects to port 9876.
    Inetd accepts the connection, forks, then execs() your perl program "P".
    Your perl program starts a remsh process "S" which connects to a remote host and process "R".

    The process P is running this code:

    open(RCMD, "remsh $h -l $u $script |") || die $!; while (<RCMD>) { print $_; }

    I think what you are asking is how your Perl program P can detect if the client C exits (or otherwises closes the socket connection). Right now it may wait a long time on <RCMD> and not give an error until the "print $_".

    If this is a correct understanding, then what I suggested above should work. The STDIN and STDOUT of your Perl process P are both connected to the socket connection that "C" connected to and inetd accepted. A call to select() or can_read() should detect when that socket connection is closed.

      Thank you very much for your pointers. The problem was solved by following your suggestions. The new code looks like:
      while (! eof(RCMD)) { my @fds = $sel->can_read(5); #print NSY "FDS = @fds\n"; if ($#fds == 0) { my $in = <RCMD>; print $in; } else { my @fds = $wsel->can_read(0); #print NSY "FDS = @fds\n"; if ($#fds != 0) { #print NSY "Closing as stdout closed\n"; exit(0); } } }