[Melbourne-pm] Error checks without packages

Tim Hogard thogard at abnormal.com
Wed Jul 27 05:30:02 PDT 2011


I have this bit of code and the disk partition /usr/local/tmp is full:
	#!/usr/bin/perl

	$SIG{PIPE} = sub { die "\nSigPIPE!\n" };

	open(OUT,">/usr/local/tmp/x$$") or print "cant open $? $!\n";
	print "err $?\n";

	print OUT  "foo $$ \n" or print "cant print out $? $!\n";

	print "err $?\n";
	close OUT or print "cant close $? $!\n";
	print "err $?\n";


$ ./close_test 
err 0
err 0
cant close 0 No space left on device
err 0

If I add 
	select(OUT);
	$|=1; # set to unbuffered output
	select(STDOUT);
Even before the open I get:

$ ./close_test    
err 0
cant print out 0 No space left on device
err 0
cant close 0 No space left on device
err 0

That helps, but it would be best to know as soon as I open the file
so I can put the entire output in a different file on a different
partition.  The unix "open" system call reports "no space" only
when the directory entry can't be extended and has nothing to do
with how much space is left on the disk.

I could rewind but I'm opening for append since there is small
chance two processes could write the same file at the same time.

I can't flush without loading the IO package (which I don't want
to).

Does anyone have any other ideas?

-tim
http://web.abnormal.com


More information about the Melbourne-pm mailing list