Skip Menu |

This queue is for tickets about the File-Slurp CPAN distribution.

Report information
The Basics
Id: 28977
Status: resolved
Priority: 0/
Queue: File-Slurp

People
Owner: Nobody in particular
Requestors: acd [...] weirdness.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 9999.12
Fixed in: 9999.19



Subject: read_file and write_fail can fail due to EINTR
I encountered a bug (or misfeature) when using File::Slurp's read_file within an app that receives signals. read_file uses sysread which is vulnerable to being interrupted when a signal is received. Since sysread is the raw OS read call, Perl doesn't automatically restart the read as it does for the read function. I've attached a patch which resolves the issue for me on my system. Also, as a caveat, I noticed that you've been working towards supporting earlier versions of Perl in File::Slurp and I've not been able to test it on anything other than the 5.8 train. The same issue likely exists with write_file as well, though I did not experience it. I included a fix for it in my patch as well.
Subject: file-slurp-eintr.patch
diff -ru File-Slurp-9999.12/lib/File/Slurp.pm File-Slurp-9999.12.acd/lib/File/Slurp.pm --- File-Slurp-9999.12/lib/File/Slurp.pm 2006-02-17 01:13:51.000000000 -0500 +++ File-Slurp-9999.12.acd/lib/File/Slurp.pm 2007-08-24 11:29:15.696387979 -0400 @@ -6,6 +6,7 @@ use POSIX qw( :fcntl_h ) ; use Fcntl qw( :DEFAULT ) ; use Symbol ; +use Errno ; my $is_win32 = $^O =~ /win32/i ; @@ -174,6 +175,10 @@ next ; } +# since we're using sysread Perl won't automatically restart the call when +# interrupted by a signal. + next if $!{EINTR}; + # handle the read error @_ = ( \%args, "read_file '$file_name' - sysread: $!"); @@ -330,6 +335,10 @@ my $write_cnt = syswrite( $write_fh, ${$buf_ref}, $size_left, $offset ) ; +# since we're using sysread Perl won't automatically restart the call when +# interrupted by a signal. + next if $!{EINTR}; + unless ( defined $write_cnt ) { # the write failed
On Fri Aug 24 11:33:08 2007, acd wrote: Show quoted text
> I encountered a bug (or misfeature) when using File::Slurp's read_file > within an app that receives signals. read_file uses sysread which is > vulnerable to being interrupted when a signal is received. Since > sysread is the raw OS read call, Perl doesn't automatically restart the > read as it does for the read function. I've attached a patch which > resolves the issue for me on my system. Also, as a caveat, I noticed > that you've been working towards supporting earlier versions of Perl in > File::Slurp and I've not been able to test it on anything other than > the 5.8 train. > > The same issue likely exists with write_file as well, though I did not > experience it. I included a fix for it in my patch as well.
can you create a test for this? i can see the issue and it will only happen if you use signals (which are not a great thing in general to use). it will be hard to prove it works without a proper test. i may patch this coming version as it can't hurt.
Subject: Re: [rt.cpan.org #28977] read_file and write_fail can fail due to EINTR
Date: Mon, 23 May 2011 10:37:55 -0400
To: bug-File-Slurp [...] rt.cpan.org
From: Andrew Danforth <acd [...] weirdness.net>
Let me see if I can whip up a test. I discovered this with an application that is long lived and spawns children, so it needs SIGCHLD to know when to reap them. The SIGCHLDs are sometimes delivered while in the middle of a sysread. On Mon, May 23, 2011 at 1:50 AM, Uri Guttman via RT < bug-File-Slurp@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=28977 > > > On Fri Aug 24 11:33:08 2007, acd wrote:
> > I encountered a bug (or misfeature) when using File::Slurp's read_file > > within an app that receives signals. read_file uses sysread which is > > vulnerable to being interrupted when a signal is received. Since > > sysread is the raw OS read call, Perl doesn't automatically restart the > > read as it does for the read function. I've attached a patch which > > resolves the issue for me on my system. Also, as a caveat, I noticed > > that you've been working towards supporting earlier versions of Perl in > > File::Slurp and I've not been able to test it on anything other than > > the 5.8 train. > > > > The same issue likely exists with write_file as well, though I did not > > experience it. I included a fix for it in my patch as well.
> > can you create a test for this? i can see the issue and it will only > happen if you use signals (which are not a great thing in general to > use). it will be hard to prove it works without a proper test. i may > patch this coming version as it can't hurt. > > >
Subject: Re: [rt.cpan.org #28977] read_file and write_fail can fail due to EINTR
Date: Mon, 23 May 2011 14:13:38 -0400
To: bug-File-Slurp [...] rt.cpan.org
From: Andrew Danforth <acd [...] weirdness.net>
Test case attached. Seems to work.

Message body is not shown because sender requested not to inline it.

couple of comments. this patch is against .12 which is fairly old now as i have been crazy doing releases. current is .18 on cpan and this patch will get into .19. also the indents/formatting seem to be lost which isn't big but it makes it harder to see how to apply the patch (which i do by hand edit anyhow). i am patching this now and testing the test.
a beta tarball with the patch and t/signal.t test is at: http://sysarch.com/File-Slurp-9999.19.tar.gz see if it fixes your interrupt issue and report back to me. if it works, i will release it. thanx, uri
Subject: Re: [rt.cpan.org #28977] read_file and write_fail can fail due to EINTR
Date: Tue, 24 May 2011 20:36:02 -0400
To: bug-File-Slurp [...] rt.cpan.org
From: Andrew Danforth <acd [...] weirdness.net>
Looks good to me. Thanks for addressing this!
Subject: Re: [rt.cpan.org #28977] read_file and write_fail can fail due to EINTR
Date: Tue, 24 May 2011 20:40:25 -0400
To: bug-File-Slurp [...] rt.cpan.org
From: Andrew Danforth <acd [...] weirdness.net>
I wanted to quickly add one more thing. My testcase might not work properly on Windows; I'm not sure how Perl on Windows handles signals and fork. If it won't work, you may want to do something similar to inode.t to exclude the test.
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #28977] read_file and write_fail can fail due to EINTR
Date: Sat, 04 Jun 2011 02:54:39 -0400
To: bug-File-Slurp [...] rt.cpan.org
From: "Uri Guttman" <uri [...] StemSystems.com>
i have put the beta of File::Slurp .19 at: http://sysarch.com/File-Slurp-9999.19.tar.gz let me know how it tests/works on your system. you are acked in the Changes file too! thanx, uri -- Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------