On errno

Tim Kientzle kientzle at freebsd.org
Mon Mar 30 15:35:26 PDT 2009


Marcel Moolenar suggests adding new values of errno to
further distinguish error conditions, leading to the
following comments:

Daniel Eischen wrote:
> On Mon, 30 Mar 2009, Tim Kientzle wrote:
>> Poul-Henning Kamp wrote:
>>> Long time ago, I proposed a scheme where a process can register
>>> a userland error-text buffer with the kernel.
>>
>> This is the right direction:  Basically, add a new variable
>> that augments errno instead of extending the possible values of
>> errno.
> 
> Just add the other error values in the upper half of the
> word, and have __errno() return with the upper half
> masked out.  VxWorks doesn't something similar with
> their errno,...

I thought of that, but it won't work.  Old binaries exist
and you don't want to version every single system call.

Poul-Henning Kamp wrote:
> The probelm with an integer is that you cannot give details
> like:
> 	"partition 3 overlaps bootcode"
> without precreating the N^2 possible messages of that kind.

The standard solution if you need variable parameters,
of course, is to pass the parameters back:
    int code: EPARTITIONOVERLAPSBOOTCODE
    char *default_text: "partition %1d overlaps bootcode"
    arg1: 3

This provides everything necessary for libc to
generate an appropriate translated text. The
"default_text" return is a common tweak, mostly to
to make the code at the error source easier to read,
though it also helps the consumer to provide something
even when the translation catalogs are missing or damaged.

Note that the code at the error source is essentially
the same either way:
   generate_error(EPARTITIONOVERLAPSBOOTCODE,
      "partition %1d overlaps bootcode", partno);
but the varargs values get passed back to userland
to be formatted instead of being formatted in the
kernel.

Tim


More information about the freebsd-arch mailing list