in reply to Re: write to /dev/full does not fail
in thread write to /dev/full does not fail

mmh.. intersting: why Perl does not dies on print? even if autoflush is enabled?
# this not dies perl -e '$|++; open FH, ">", "/dev/full" or die $!; print FH "line\n" + or die $!; ' # while this dies on close perl -e 'open FH, ">", "/dev/full"; print FH "line\n" ;close FH or di +e $! ' No space left on device at -e line 1. # interestingly (?) sysopen die on write, may it knows about /dev/full +? perl -e 'sysopen (FH, "/dev/full", O_WRONLY) ; print FH "line\n" or d +ie $!;close FH ' Bad file descriptor at -e line 1.
I expect Perl die when the print fails, at least when autoflush is on.

why this behaviour?

L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: write to /dev/full does not fail
by choroba (Cardinal) on May 23, 2014 at 07:48 UTC
    Interestingly, if you print a lot, print itself will die:
    perl -wE 'open my $F, ">", "/dev/full" or die "open:$!"; for (1..10000) { print $F "line\n" or die "print:$!"; }; close $F or die "close:$!"; '
    print:No space left on device at -e line 3.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      no, it seems to me it always, only dies on close:
      #this not dies perl -e 'open FH, ">", "/dev/full" or die $!; for (1..100) {print FH " +line\n" or die $!;} ' #this too not dies perl -e '$|++;open FH, ">", "/dev/full" or die $!; for (1..100) {prin +t FH "line\n" or die $!;} ' #only this dies, on close perl -e 'open FH, ">", "/dev/full" or die $!; for (1..100) {print FH +"line\n" or die $!;}; close FH or die $!' No space left on device at -e line 1.
      UPDATE: as suggested by choroba 100 are few (magic number seems to be 820):
      # this still does not die perl -e '$|++;open FH, ">", "/dev/full" or die $!; for (1..819) {print + FH "line\n" or die $!;} ' #but this dies! perl -e '$|++;open FH, ">", "/dev/full" or die $!; for (1..1000) {pri +nt FH "line\n" or die $!;} ' No space left on device at -e line 1.
      820 is to much? Perl becomes bored after 820 errors (not spotted)? is very patient: i'm hurted by second error.. ;=)
      # perl -e 'print "$_\n" for 1..10000' | perl -ne '$num = <STDIN>;print + "$num:";open FH, ">", "/dev/full" or die $!; for (1..$num) {print FH + "line\n" or die $!;};close FH;' .. :816 :818 :820 No space left on device at -e line 1, <STDIN> line 410.
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        "line\n" is 5 bytes.

        820 * 5 = 4100.

        Buffer size for linux is 4096, so the write hits the actual device on your 820th iteration.

Re^3: write to /dev/full does not fail
by kschwab (Vicar) on May 23, 2014 at 16:37 UTC
    select(FH); before you increment $|. As-is, you just set autoflush on STDOUT, with no effect on FH.