-
Notifications
You must be signed in to change notification settings - Fork 558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-pi doesn't sanely handle write errors #328
Comments
From morty@sled.gsfc.nasa.govperl 5.00502 and 5.00503 (probably earlier as well) don't check for write morty@frakir:/spare/morty 12:16:11 1513$ df -k . IMHO, better behavior would be for perl to put the file back the way it was I haven't tried the latest development version; my apologies if this is a Perl Info
|
From @smpeters
steve@kirk pi_test $ perl -pi- -e'exit' test It seems to have been fixed somewhere prior to Perl 5.8.5. Steve Peters |
@smpeters - Status changed from 'open' to 'resolved' |
From morty@sled.gsfc.nasa.govOn Fri, Nov 12, 2004 at 03:46:36AM -0000, Steve Peters via RT wrote:
That didn't duplicate the steps that led to the original problem. The I just tried it under 5.8.5, and it still happens. Example: root@red-sonja:/mnt 05:30:13 1061# dd if=/dev/zero of=bar bs=1024 - Morty |
From morty@frakir.orgPlease reopen. Thanks! A complete demo script is attached. |
From morty@sled.gsfc.nasa.govIt occurs to me that I never included a demo of how to create an #!/bin/sh # script to demo problem of perl not detecting write errors with -pi IMG=/root/floppy.img cd / && echo Done. Status is: $? && df -k . && ls -l bar* # clean up regardless of status |
@smpeters - Status changed from 'resolved' to 'open' |
From @chipdudeA first step in handling write errors would be dying if either print or As for restoring the partially read file back to its original name on Finally, adding death to the behavior of existing code that has its own perl -pi~ 's/foo/bar/' *.c But if you write this you should _not_ get automatic death: #!/usr/bin/perl Comments? |
From @chipdude{{ I filed this comment in RT and asked it to copy p5p, but over an hour A first step in handling write errors in -pi would be dying if either print As for restoring the partially read file back to its original name on Finally, adding death to the behavior of existing code that has its own perl -pi~ 's/foo/bar/' *.c But if you write this you should _not_ get automatic death: #!/usr/bin/perl Comments? |
From Mordechai.T.Abzug@nasa.govOn Mon, Nov 17, 2008 at 10:38:05AM -0800, Chip Salzenberg via RT wrote:
Agreed. At the very least, I should get a non-zero exit status.
In my use case, I was looking to use Perl to in-place edit system And what about the case where one has an error when using -i without a
Agreed. The main problem here is that the -p implicit loop doesn't But what if the programmer's code does throw die while processing <> - Morty |
From ben@morrow.me.ukQuoth Mordechai.T.Abzug@nasa.gov (Morty Abzug):
perl -pi~ -e'... END { $? and rename "$ARGV~", $ARGV }'
But that's not easy, since the original file has been unlinked and Unix Ben |
From tchrist@perl.com<<<====================================================>>> ¶ SUMMARY: Yes, Chip, it's a bug, one I've kvetched ¶ METAPHOR: There is nothing new under the sun. [Eccl 1:9] ¶ IN LATIN: Sicut erat in principio, et nunc, et semper. <<<====================================================>>> On Mon, 17 Nov 2008 10:38:07 PST, Chip Salzenberg wrote:
Indeed; see §xv below.
Agreed: vehemently, vociferously, and vituperatively. See §xiii below.
How nice of you to ask! I'm only too glad to provide a few Chip, this bug is one I've long lamented, and the problem more When a filehandle is *implicitly* closed (or even flushed) by This makes for incorrect programs--and silently lost data!! If the programmer cannot check, than Perl *must*; and doesn't. If you look at pp_fork(), you'll see that it does, voidally, PERL_FLUSHALL_FOR_CHILD I presume you recall why we must do that, and may even The fflush NULL case is here in Perl_PerlIO_flush: /* But again, people are voiding (erroneously disregarding) it. if (fp) { Meanwhile in Perl_do_openn(), called by pp_open(), you find That case is this: const PerlIO_funcs *tab = PerlIOBase(f)->tab; if (tab && tab->Flush) I get lost in the longjump() in S_my_exit_jump, but you can /* Need to flush since END blocks can produce output */ which leads you to the following evil code: if (open_max > 0) { Notice again, we've neglecting reporting a flush failure. If reading through the code isn't enough (to make your head spin), I complain about this every 5 or 10 years. The last time was only http://www.gossamer-threads.com/lists/perl/porters/230671?search_string=even%20my%20cat%20is%20smarter%20than;#230671 in which I prove that even my cat is smarter than perl. :-) Pardon me, while I repeat myself: » Which brings me to my final complaint of the day. That code is » Watch: » % df -h . » To this day, Perl's implicit closing of files doesn't warn you » I've never convinced anybody this is important. Since *every* » END { close(STDOUT) || die "can't close stdout: $!" } See §vi below. » But that sort of thing should happen on all implicitly closed » Watch again, starting from before the bogus, ill-reported » % df -h . » This is all incorrect behavior on Perl's part. Even cat knows better! » % echo foo | cat >> it; echo $? » +-------------------------------------------------------+ » What's that about, eh? » But I've been saying this for years, just like everything else. » BTW, this proves my point about checking for print's status » % perl -e 'open(my » And you can't get the danged thing to detect its folly: » % perl -WE 'open(my » I firmly believe that this needs to be a part of *EVERY* Perl » END { close(STDOUT) || die "can't close stdout: $!" } » And I believe this *much* more than some here believe <ARGV> And then in a grandchild followup, where I wrote: »> I am glad you mentioned this, because I also think it's a [...] »> Yup, and also for STDERR (if closing STDERR fails you can » Possibly. Probably. Maybe. »>> Furthermore, I also believe all *IMPLICIT* closes that fail »> This also makes perfect sense. » Easy for you to say. Others have said otherwise in the past, »> Does anyone really object to this? » They clearly did, or it would have been done. But maybe this »> In principle it is a backwards incompatible change (code that » A bug is a bug, and this is. Always has been. Rafaël then kindly spoke up, saying: »>> To this day, Perl's implicit closing of files doesn't warn »>> I've never convinced anybody this is important. »> It absolutely is. I had no idea, and as far as I'm » I concur. A patch would help, but I know that PerlIO is not Indeed; see §xvi below. » A proper bug report would help, too, because currently this one I was glad to see that I'd finally convinced SOMEONE this to be But I know I didn't submit a patch; alas for §ix below! I did, however, look into the problem, as you see from the C code And as I believe I have shown, it's not just one place that I believe that all voided flushes are wrong. I also believe that the code in Perl_do_openn() that reads if (result == EOF && fd > PL_maxsysfd) { is a Microsoftening of the true etiology behind the underlying Where now the errno and strerror thereof? "Can't close file" My five rules for "proper" (=good) error messages are: $0: They name the program generating the message. It's hard to call one of those more important than another, but --tom -- --Larry Wall in README § ii You tell it that it's indicative by appending $!. That's --Larry Wall in <199709081801.LAA20629@wall.org> § iii And you can still put in all that cruft if you want to. --Larry Wall § iv Be consistent. --Larry Wall in the perl man page § v The problem with being consistent is that there are lots of ways --Larry Wall in-ID <20050516005559.GC26184@wall.org>, § vi The computer should be doing the hard work. --Larry Wall in <199709012312.QAA08121@wall.org> § vii I think I'll side with the pissheads on this one. --Larry Wall § viii It seems like a sane thing to me, § ix This has been planned for some time. I guess we'll just have --Larry Wall in <199709302338.QAA17037@wall.org> § x Er, Tom, I hate to be the one to point this out, but your fix --Larry Wall in <199801081824.KAA29602@wall.org> § xi Down that path lies madness. On the other hand, the road to § xii But maybe we could try to set some slushiness milestones on --Larry Wall in <20050314165932.GA12577@wall.org> § xiii I have no opinion on its suitability for any particular task. --Larry Wall in <20050309170804.GA22973@wall.org> § xiv I recommend not remaking my mistakes. --Larry Wall in <20040317192052.GA10645@wall.org> § xv I suppose one could claim that an undocumented feature --Larry Wall in <199710290036.QAA01818@wall.org> § xvi It's not designed to make people happy who want to confuse --Larry Wall in <20050419155213.GC19507@wall.org> § xvii If you write something wrong enough, I'll be glad to make up --Larry Wall in <199702221943.LAA20388@wall.org> §xviii ...sometimes collections of stupid utterances can be --Larry Wall in <20050303163144.GA5235@wall.org> § xix : If I don't document something, it's usually either for Yeah, I keep saying that. The trouble with being quoted a lot is that it makes --Larry Wall § xx : 1. What is the possibility of this being added In the near future, the probability is close to zero. --Larry Wall § xxi Well, you know, Hubbard had a bunch of people sworn --Larry Wall in <199804141540.IAA05247@wall.org> |
From @chipdudeAside: the referenced message includes a romaniacally-numbered list of Larry On Tue, Nov 18, 2008 at 04:23:41PM -0700, Tom Christiansen wrote:
Yay. Action item #1: die on output failure in a -i loop. You go on at length (usefully - I have much context to swap back in) about § xxii There's often more than one correct thing. -- |
From @chipdudeOn Tue, Nov 18, 2008 at 01:11:27PM +0000, Ben Morrow wrote:
That's a clever idiom that will work in many cases. Kinda ugly, but oh perl -pi~ -e'... END { $? and $ARGV and rename "$ARGV~", $ARGV }' I wonder whether we could make this a standard but optional feature of ${^INPLACE_SAFE}++; # nop in old Perls, forces rename on error in new Perls
Indeed. |
From ben@morrow.me.ukQuoth chip@pobox.com (Chip Salzenberg):
Better of course would be to process from $ARGV to "$ARGV$^I", and then Ben |
From @chipdudeOn Thu, Nov 27, 2008 at 02:29:56AM +0000, Ben Morrow wrote:
I like, as long as the ${^INPLACE_SAFE} variable is still there for scripts that want Summarizing the plan: * -ix means to set $^I="x" Comments? |
From @chipdudeOn Wed, Nov 26, 2008 at 05:09:22PM -0800, Chip Salzenberg wrote:
And here's the patch for this part of the larger issue of not ignoring flush close ARGVOUT or die "-p destination: $!"; Testing was fun. It seems that Linux's ext2 filesystem is clever about This patch builds on the previously posted patch for unified saving and Share & Enjoy! Inline Patchdiff --git a/doio.c b/doio.c
index c945216..78c6e49 100644
--- a/doio.c
+++ b/doio.c
@@ -904,7 +904,14 @@ Perl_nextargv(pTHX_ register GV *gv)
if (io && (IoFLAGS(io) & IOf_ARGV))
IoFLAGS(io) |= IOf_START;
if (PL_inplace) {
- (void)do_close(PL_argvoutgv,FALSE);
+ IO *outio;
+ if (PL_argvoutgv && isGV_with_GP(PL_argvoutgv) && (outio = GvIO(PL_argvoutgv))) {
+ dSAVE_ERRNO;
+ SETERRNO(0, 0);
+ if (!io_close(outio, FALSE))
+ Perl_die(aTHX_ "-p destination: %s", errno ? Strerror(errno) : "previous error");
+ RESTORE_ERRNO;
+ }
if (io && (IoFLAGS(io) & IOf_ARGV)
&& PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0)
{
-- Chip Salzenberg twitter:chipsalz |
From @hvdsChip Salzenberg <chip@pobox.com> wrote: New commandline flags are rare and expensive, but I can just about see the As defined here, when x is empty, -j is the same as -i. Should it do Hugo |
From @chipdudeOn Thu, Nov 27, 2008 at 08:20:02AM +0000, hv@crypt.org wrote:
I hate to do it, but we do want safety convenient, do we not? We could be -i.bak - unsafe .bak Simpler in a way, more complex in another way.
Yes, this is a Good Idea. |
From @chipdudeOn Wed, Nov 26, 2008 at 11:32:31PM -0800, Chip Salzenberg wrote:
... but it also fails lib/warnings.t. I think this is more patch bug than |
From @TuxOn Thu, 27 Nov 2008 03:28:50 -0800, Chip Salzenberg <chip@pobox.com>
-- |
From @chipdudeOn Thu, Nov 27, 2008 at 03:30:07AM -0800, Chip Salzenberg wrote:
But not any more! Here's a new cut. It only reports flush failures caused Inline Patchdiff --git a/doio.c b/doio.c
index c945216..ce57ae1 100644
--- a/doio.c
+++ b/doio.c
@@ -904,7 +904,14 @@ Perl_nextargv(pTHX_ register GV *gv)
if (io && (IoFLAGS(io) & IOf_ARGV))
IoFLAGS(io) |= IOf_START;
if (PL_inplace) {
- (void)do_close(PL_argvoutgv,FALSE);
+ IO *outio;
+ if (PL_argvoutgv && isGV_with_GP(PL_argvoutgv) && (outio = GvIO(PL_argvoutgv))) {
+ dSAVE_ERRNO;
+ SETERRNO(0, 0);
+ if (!io_close(outio, FALSE) && errno) /* only report _new_ failure to flush */
+ Perl_die(aTHX_ "-p destination: %s", Strerror(errno));
+ RESTORE_ERRNO;
+ }
if (io && (IoFLAGS(io) & IOf_ARGV)
&& PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0)
{
-- Chip Salzenberg twitter:chipsalz |
From @chipdudeOn Thu, Nov 27, 2008 at 12:52:08PM +0100, H.Merijn Brand wrote:
Yup, it all fits. Code that wants to use safe renaming when possible and work elsewhere will BEGIN { or #!/usr/bin/perl -pi~ which doesn't quite match the simplicity of the alternatively proposed ${^INPLACE_SAFE}++ but I can certainly live with it. Objections? |
From ben@morrow.me.ukQuoth chip@pobox.com (Chip Salzenberg):
I was thinking more along the lines of -ix -i -jx -j -ix -jy -ix -j Setting $^J from the program should work as expected. Any -j option $^J = "#"; I think using Ben |
From @sciuriusChip Salzenberg <chip@pobox.com> writes:
Not really, but I'd suggest a different approach. Some time ago I tried to duplicate the <> functionality to make it So my alternative approach would be to first sort this out, making it = What didn't work? IIRC there were issues with not being able to -- Johan |
From @chipdudeOn Sat, Nov 29, 2008 at 11:14:26PM +0100, Johan Vromans wrote:
That's a clever thought. Adding -Meditsafe (just to pick a nice pragma) to eval "use editsafe"; # error OK And you just know that Ingy will find a clever use for overloaded <>.
So if we had tied eof() processing and READLINE was responsive to context, |
From @sciuriusChip Salzenberg <chip@pobox.com> writes:
That's a small price to pay for gaining an enormous amount of
Maybe a pseudo-core entry: CORE::GLOBAL::eof_argv ? As for the READLINE and <>: I'm not sure if it is a READLINE problem. -- Johan |
From @chipdudeOn Mon, Dec 01, 2008 at 11:37:49PM +0100, Johan Vromans wrote:
I perceive there are two basic approaches that can be taken. One of them provides hooks in and/or out to user-level code to handle the The other of them would be less hacky but perhaps not efficient enough for Is this a good summary? Hard to know which of them is worth doing. |
From @sciurius[Quoting Chip Salzenberg, on December 1 2008, 15:16, in "Re: [perl #1154] -pi"]
And modulo the eof() facility. This is the approach I tried in Iterator::Diamond. -- Johan |
From @sciurius[Quoting Chip Salzenberg, on December 1 2008, 15:16, in "Re: [perl #1154] -pi"]
Personally I think the added flexibility and safety will outweigh the Sometimes, often, reliability is more important than speed. -- Johan |
From @chipdudeOn Tue, Dec 02, 2008 at 12:22:38AM +0100, Johan Vromans wrote:
Couldn't the distinction between C<eof> on the one hand, and C<eof()> (which |
From @chipdudeOn Mon, Dec 01, 2008 at 03:33:47PM -0800, Chip Salzenberg wrote:
Hrm. I think I'm all wet here. |
From tchrist@perl.com
Um, Chip, are people *really* claiming that fixing the -i output If so, I'm boggling. If not, I need to read more. --tom |
From tchrist@perl.com
Which is why I advise overriding ->READLINE() on a tied *HANDLE's --tom |
From tchrist@perl.com
I'm wondering about your mood there, Chip. Not your 1. If <past subj> then <conditional>. 2. If <past indic> then <past indic>. If you meant an exhortation, eg1: If only READLINE() were responsive to context, then your exhortation has long been granted. If, however, you meant a simple statement of fact eg2: If READLINE() was responsive to context in 1994, Then I'd have to check *when* it became true. But my The eof problem may be different. Allegedly, per perltie(1), the ->EOF() method can be overridden ---tom |
From tchrist@perl.com
(Thank goodness modulo isn't context-sensitive! %=)
Hm, now that's an idea. Having it be the *lexer* who autoqualified stuff like However, I also remember how it seemed cleaner use Foo; to compile into BEGIN { as opposed to use Foo (); which compiles into BEGIN { Although that's not truly how it works, it looks like that's use Foo; returns the return value of Foo::->import(), while use Foo () --tom |
From @chipdudeOn Mon, Dec 01, 2008 at 10:15:16PM -0700, Tom Christiansen wrote:
Hm ... hasargs. An intriguing suggestion. It is conceivable that, given local @_ = (tied *ARGV); which would leave hasargs false, thus distinguishing itself from C<eof> and Fortunately, a simpler alternative presents itself: Why not just add an eof(ARGV) -> +(tied *ARGV)->EOF; Presto magic(k)o. Now a digression for the human-language fans in the audience:
Indeed. Having once learned functional Spanish, I find that English's lack
This is, in fact, what I meant WRT READLINE. Thank you for the entertaining |
From @chipdudeOn Mon, Dec 01, 2008 at 09:46:32PM -0700, Tom Christiansen wrote:
Heh, no. We're now discussing a further level of safety: The renaming of |
From @chipdudeOn Mon, Dec 01, 2008 at 10:41:35PM -0800, Chip Salzenberg wrote:
And, here's a patch that works and solves the problem. The details turned Starting with Perl 5.12, an additional integer parameter will be passed. It Frankly, my use of magic numbers is a little old-school, but what the heck... Share & Enjoy! Inline Patchdiff --git a/pod/perltie.pod b/pod/perltie.pod
index 162272b..9f26473 100644
--- a/pod/perltie.pod
+++ b/pod/perltie.pod
@@ -952,6 +952,19 @@ This method will be called when the C<getc> function is called.
sub GETC { print "Don't GETC, Get Perl"; return "a"; }
+=item EOF this
+X<EOF>
+
+This method will be called when the C<eof> function is called.
+
+Starting with Perl 5.12, an additional integer parameter will be passed. It
+will be zero if C<eof> is called without parameter; C<1> if C<eof> is given
+a filehandle as a parameter, e.g. C<eof(FH)>; and C<2> in the very special
+case that the tied filehandle is C<ARGV> and C<eof> is called with an empty
+parameter list, e.g. C<eof()>.
+
+ sub EOF { not length $stringbuf }
+
=item CLOSE this
X<CLOSE>
diff --git a/pp_sys.c b/pp_sys.c
index 211633b..b200eb1 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2014,51 +2014,60 @@ PP(pp_eof)
{
dVAR; dSP;
GV *gv;
+ IO *io;
+ MAGIC *mg;
- if (MAXARG == 0) {
- if (PL_op->op_flags & OPf_SPECIAL) { /* eof() */
- IO *io;
- gv = PL_last_in_gv = GvEGV(PL_argvgv);
- io = GvIO(gv);
- if (io && !IoIFP(io)) {
- if ((IoFLAGS(io) & IOf_START) && av_len(GvAVn(gv)) < 0) {
- IoLINES(io) = 0;
- IoFLAGS(io) &= ~IOf_START;
- do_open(gv, "-", 1, FALSE, O_RDONLY, 0, NULL);
- if ( GvSV(gv) ) {
- sv_setpvs(GvSV(gv), "-");
- }
- else {
- GvSV(gv) = newSVpvs("-");
- }
- SvSETMAGIC(GvSV(gv));
- }
- else if (!nextargv(gv))
- RETPUSHYES;
- }
- }
+ if (MAXARG)
+ gv = PL_last_in_gv = MUTABLE_GV(POPs); /* eof(FH) */
+ else if (PL_op->op_flags & OPf_SPECIAL)
+ gv = PL_last_in_gv = GvEGV(PL_argvgv); /* eof() - ARGV magic */
+ else
+ gv = PL_last_in_gv; /* eof */
+
+ if (!gv)
+ RETPUSHNO;
+
+ if ((io = GvIO(gv)) && (mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar))) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj(MUTABLE_SV(io), mg));
+ /*
+ * in Perl 5.12 and later, the additional paramter is a bitmask:
+ * 0 = eof
+ * 1 = eof(FH)
+ * 2 = eof() <- ARGV magic
+ */
+ if (MAXARG)
+ mPUSHi(1); /* 1 = eof(FH) - simple, explicit FH */
+ else if (PL_op->op_flags & OPf_SPECIAL)
+ mPUSHi(2); /* 2 = eof() - ARGV magic */
else
- gv = PL_last_in_gv; /* eof */
+ mPUSHi(0); /* 0 = eof - simple, implicit FH */
+ PUTBACK;
+ ENTER;
+ call_method("EOF", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
}
- else
- gv = PL_last_in_gv = MUTABLE_GV(POPs); /* eof(FH) */
- if (gv) {
- IO * const io = GvIO(gv);
- MAGIC * mg;
- if (io && (mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar))) {
- PUSHMARK(SP);
- XPUSHs(SvTIED_obj(MUTABLE_SV(io), mg));
- PUTBACK;
- ENTER;
- call_method("EOF", G_SCALAR);
- LEAVE;
- SPAGAIN;
- RETURN;
+ if (!MAXARG && (PL_op->op_flags & OPf_SPECIAL)) { /* eof() */
+ if (io && !IoIFP(io)) {
+ if ((IoFLAGS(io) & IOf_START) && av_len(GvAVn(gv)) < 0) {
+ IoLINES(io) = 0;
+ IoFLAGS(io) &= ~IOf_START;
+ do_open(gv, "-", 1, FALSE, O_RDONLY, 0, NULL);
+ if (GvSV(gv))
+ sv_setpvs(GvSV(gv), "-");
+ else
+ GvSV(gv) = newSVpvs("-");
+ SvSETMAGIC(GvSV(gv));
+ }
+ else if (!nextargv(gv))
+ RETPUSHYES;
}
}
- PUSHs(boolSV(!gv || do_eof(gv)));
+ PUSHs(boolSV(do_eof(gv)));
RETURN;
}
diff --git a/t/op/tiehandle.t b/t/op/tiehandle.t
index 735a25c..dbd0846 100755
--- a/t/op/tiehandle.t
+++ b/t/op/tiehandle.t
@@ -10,7 +10,7 @@ my $data = "";
my @data = ();
require './test.pl';
-plan(tests => 50);
+plan(tests => 63);
sub compare {
local $Level = $Level + 1;
@@ -61,6 +61,11 @@ sub READ {
3;
}
+sub EOF {
+ ::compare(EOF => @_);
+ @data ? '' : 1;
+}
+
sub WRITE {
::compare(WRITE => @_);
$data = substr($_[1],$_[3] || 0, $_[2]);
@@ -69,7 +74,6 @@ sub WRITE {
sub CLOSE {
::compare(CLOSE => @_);
-
5;
}
@@ -92,11 +96,18 @@ is($r, 1);
$r = printf $fh @expect[2,3];
is($r, 2);
-$text = (@data = ("the line\n"))[0];
+@data = ("the line\n");
+@expect = (EOF => $ob, 1);
+is(eof($fh), '');
+
+$text = $data[0];
@expect = (READLINE => $ob);
$ln = <$fh>;
is($ln, $text);
+@expect = (EOF => $ob, 0);
+is(eof, 1);
+
@expect = ();
@in = @data = qw(a line at a time);
@line = <$fh>;
@@ -273,3 +284,22 @@ is($r, 1);
sub READLINE { "foobar\n" }
}
+{
+ # make sure the new eof() features work with @ARGV magic
+ local *ARGV;
+ @ARGV = ('haha');
+
+ @expect = (TIEHANDLE => 'Implement');
+ $ob = tie *ARGV, 'Implement';
+ is(ref($ob), 'Implement');
+ is(tied(*ARGV), $ob);
+
+ @data = ("stuff\n");
+ @expect = (EOF => $ob, 1);
+ is(eof(ARGV), '');
+ @expect = (EOF => $ob, 2);
+ is(eof(), '');
+ shift @data;
+ @expect = (EOF => $ob, 0);
+ is(eof, 1);
+}
-- Chip Salzenberg twitter:chipsalz |
From @chipdudeThe below patch is not in blead, at least it seems not to be, according to Inline Patchdiff --git a/doio.c b/doio.c
index c945216..ce57ae1 100644
--- a/doio.c
+++ b/doio.c
@@ -904,7 +904,14 @@ Perl_nextargv(pTHX_ register GV *gv)
if (io && (IoFLAGS(io) & IOf_ARGV))
IoFLAGS(io) |= IOf_START;
if (PL_inplace) {
- (void)do_close(PL_argvoutgv,FALSE);
+ IO *outio;
+ if (PL_argvoutgv && isGV_with_GP(PL_argvoutgv) && (outio = GvIO(PL_argvoutgv))) {
+ dSAVE_ERRNO;
+ SETERRNO(0, 0);
+ if (!io_close(outio, FALSE) && errno) /* only report _new_ failure to flush */
+ Perl_die(aTHX_ "-p destination: %s", Strerror(errno));
+ RESTORE_ERRNO;
+ }
if (io && (IoFLAGS(io) & IOf_ARGV)
&& PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0)
{
-- Chip Salzenberg twitter:chipsalz |
From @rgs2008/12/13 Chip Salzenberg <chip@pobox.com>:
I see that it was applied to bleadperl two days ago by Steve (to
|
@rgs - Status changed from 'open' to 'resolved' |
From Mordechai.T.Abzug@nasa.govWhen I attempted to verify the fix using bleadperl, the bug still Methodology used to install bleadperl: mkdir ~/bleadperl ~/localperl && Methodology used to test: #!/bin/sh # script to demo problem of perl not detecting write errors with -pi IMG=/root/floppy.img echo Perl version: cd / && echo Done. Status is: $? && df -k . && ls -l bar* # clean up regardless of status Output of script above: Perl version: This is perl, v5.11.0 DEVEL35082 built for i686-linux Copyright 1987-2008, Larry Wall Perl may be copied only under the terms of either the Artistic License Complete documentation for Perl, including FAQ lists, should be found 1440+0 records in Writing inode tables: done This filesystem will be automatically checked every 31 mounts or - Morty (remotely) |
Migrated from rt.perl.org#1154 (status was 'resolved')
Searchable as RT1154$
The text was updated successfully, but these errors were encountered: