Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Jul 1999 11:46:33 +1000
From:      Patryk Zadarnowski <patrykz@mycenae.ilion.eu.org>
To:        Garance A Drosihn <drosih@rpi.edu>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Swap overcommit 
Message-ID:  <199907170146.LAA37200@mycenae.ilion.eu.org>
In-Reply-To: Your message of "Fri, 16 Jul 1999 12:04:08 -0400." <v04011700b3b504f281a2@[128.113.24.47]> 

next in thread | previous in thread | raw e-mail | index | archive | help

> At 9:52 PM -0700 7/15/99, Matthew Dillon wrote:
> >:>     ...  How many programmers bother to even *clear* errno before
> >:>     making these calls (since some system calls do not set errno
> >:			    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >:>     if it already non-zero).  Virtually nobody.
> >:      ^^^^^^^^^^^^^^^^^^^^^^^
> >:
> >:Erm... WTF?!?! If so, why the HELL are we doing that?!?
> >
> >    No, wait, I got that wrong I think.
> >
> >    Oh yah, I remember now.  Hmm.  How odd.  I came across a case
> >    where read() could return -1 and not set errno properly if
> >    errno was already set, but a perusal of the kernel code seems
> >    to indicate that this can't happen.  Very weird.
> 
> For what it's worth, I know I've run into situations where errno
> had to be cleared before calling some system routine (but I don't
> think it was read, and I am sure it wasn't on freebsd).

Ahem, I'm not sure what that's got to do with swap overcommit, but
anything to distract this thread is a good thing ;)

The correct thing to do with errno is to clear it before a call IFF
you are going to check its value on return from the call, simply
because the calls NEVER don't clear errno on success, but set/change
it on error.  Every standard I've seen requires this behaviour quite
explicitely, and I'm preaty sure it's documented someone in BSD man
pages too. It's definitely correct if you look at the syscall stub
code in libc.

And yes, almost all the code I've seen does the right thing when
it comes to handling errno, including checking its value on an error
from system call (ususally by calling warn() or err()), so the
``Virtually nobody'' argument above is rather misguided.

If something in libc READS errno without clearing it (other than
err/warr functions that is ;), it's badly broken and should be fixed
in the library, not in the user code. IMHO.

patryk.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907170146.LAA37200>