SIGPIPE delay on open2 exec failure

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Perl 5.8.5 on Fedora Core 3...

Can anyone tell me why my SIGPIPE handler doesn't run until I hit the enter
key when running this program from a TTY?

1:    #!/usr/bin/perl
3:    use FileHandle;
4:    use IPC::Open2;
6:    sub pipeHandler {
7:        die("I piped");
8:    }
10:    $SIG = \&pipeHandler;
12:    $pid = open2( \*FROMPROC, \*TOPROC, "/path/to/nonexistent/program");
13:    TOPROC->autoflush();
15:    print TOPROC "Garbage in...";
16:    print <FROMPROC>;
18:    while(<STDIN>) {
19:        print TOPROC $_;
20:        print <FROMPROC>;
21:    }

I get the error message:

   open2: exec of /path/to/nonexistent/program failed at foowrap line 12

right away, but the program sits waiting until I hit the enter key, then
dies and prints on STDERR:

   I piped at script_name line 7, <STDIN> line 1.

Why didn't it hit the SIGPIPE handler trying to write to TOPROC on line 15?

I've also tried trapping __DIE__ with the following handler:

a:   sub dieHandler {
b:    die("I died");
c:   }

This handler runs right away, and the message:

   I died at script_name line b.

prints instead of the "open2: exec ... failed ..." message, as one would
expect, but then it still sits there waiting for me to hit enter again, at
which point it prints:
   I died at script_name line b, <STDIN> line 1.

I'm sure I'm just missing the subtleties of IPC, so can anyone clue me in as
to what's happening here?

In case you're wondering, I ultimately want to have the program die right
away if the exec in the open2() program fails.

Re: SIGPIPE delay on open2 exec failure

Quoted text here. Click to load it

For me on 5.8.0 it does SIGPIPE on line 15, so this may be a bug
rather than some expected behavior.


-------------------- http://NewsReader.Com / --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB

Site Timeline