Re: Re: ZeroFill(.../pg_xlog/xlogtemp.20148) failed: No such file or directory

Chris Jones <chris@mt.sri.com>

From: Chris Jones <chris@mt.sri.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Oliver Elphick <olly@lfix.co.uk>, pgsql-general@postgresql.org
Date: 2001-05-23T17:39:15Z
Lists: pgsql-general
On Wed, May 23, 2001 at 12:50:46PM -0400, Tom Lane wrote:

> 	errno = 0;
> 	if (write(...) != expectedbytecount)
> 	{
> 		int	save_errno = errno;
> 
> 		unlink(tmp);
> 
> 		errno = save_errno ? save_errno : ENOSPC;
> 
> 		elog(...);
> 	}
> 
> Comments?  Is it reasonable to guess that the problem must be ENOSPC
> if write doesn't write all the bytes but also doesn't set errno?

No, it could be any number of other things.  The first that comes to
mind is EINTR.  How about something closer to:

totalwritten = 0;
while(totalwritten < expectedbytecount) {
    lastwritten = write(...);
    if(lastwritten == -1) {
        /* errno is guaranteed to be set */
        if(errno == EINTR) {
            continue;
        }
        unlink(tmp);
        elog(...);
        break;
    } else if(lastwritten == 0) {
        /* errno should be 0.  Considering this an error is probably a
           BAD idea. */
        unlink(tmp);
        elog(...);
        break;
    } else {
        /* we got a partial write count.  No problem; try again. */
        totalwritten += lastwritten;
    }    
}

Chris

-- 
chris@mt.sri.com -----------------------------------------------------
Chris Jones                                    SRI International, Inc.
                                                           www.sri.com