Error in perlipc documentation?

I am trying to understand something that I see in the perlipc documentation.

If you are writing on a trumpet, you must also capture SIGPIPE. Otherwise, think about what happens when you run the pipe to a command that does not exist: open () will most likely succeed (this only reflects the success of fork ()), but then your output will fail - spectacularly . Perl cannot know if the command worked because your command actually works in a separate process. Perhaps exec () failed. Therefore, although readers of fictitious commands return only the fast end of the file, the scripters of the fake command will cause a signal with which they should prepare. Consider:

open(FH, "|bogus") or die "can't fork: $!"; print FH "bang\n" or die "can't write: $!"; close FH or die "can't close: $!"; 

It will not explode until closing, and it will explode SIGPIPE. To catch it, you can use this:

  $SIG{PIPE} = 'IGNORE'; open(FH, "|bogus") or die "can't fork: $!"; print FH "bang\n" or die "can't write: $!"; close FH or die "can't close: status=$?"; 

If I read it correctly, it says that the first version probably will not die before the final closure.

However, this does not happen in my OS X mailbox (Perl versions 5.8.9 - 5.15.9). It explodes on open using "can not fork: There is no such file or directory", regardless of whether I have the $ SIG {PIPE} line.

What? I do not understand?

+6
source share
2 answers

This was a change during development 5.6, so that system () could detect when it failed to execute the fork / exec child

https://github.com/mirrors/perl/commit/d5a9bfb0fc8643b1208bad4f15e3c88ef46b4160

It is also documented at http://search.cpan.org/dist/perl/pod/perlopentut.pod#Pipe_Opens

which itself points to perlipc, but perlipc seems to be missing this

+3
source

The same output on my Perl, v5.14.2 , Ubuntu 12.04:

 $ perl open(FH, "|bogus") or die "can't fork: $!"; print FH "bang\n" or die "can't write: $!"; close FH or die "can't close: $!"; can't fork: No such file or directory at - line 1. 

And this mistake is odd, since it has nothing to do with forking - they must add some guessing looks to see if it can execute bogus . (In the best case, this will be a condition of the race, but most likely it will provide significantly better error handling in the general case and will only be inconvenient, like the previous behavior, when the race is lost.)

0
source

Source: https://habr.com/ru/post/914938/


All Articles