You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by rb...@covalent.net on 2000/04/20 20:21:12 UTC
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Bill,
The primary error code on ALL platforms is errno. The Windows native
error codes should be APR_OS_START_SYSERR + native code. I'm not sure if
the docs are correct right now, but that is the decided upon design.
Ryan
On Thu, 20 Apr 2000, Bill Stoddard wrote:
> Brian,
> I think you may be headed for a lot of rework here...
>
> The field of error numbers up to APR_OS_START_ERROR is designated for the "primary error
> value for a platform". On Unix, the primary error values are errno. On Windows, the
> primary error values are GetLastError/WSAGetLastError. This means that we should not be
> blindly using strerror to fetch the strings for this range of error messages. It should be
> made into a macro instead which calls strerror on unix, FormatMessage on Windows, etc. I
> see you are using the APR_OS_START_SYSERROR range for your primary error messages, right?
> Or are these special case errors and the primary is really Unix style errno?
>
> Bill
>
> > bjh 00/04/20 07:27:56
> >
> > Modified: src/lib/apr/misc/unix errorcodes.c
> > Log:
> > Add error messages for OS/2 error codes.
> >
> > Revision Changes Path
> > 1.3 +45 -2 apache-2.0/src/lib/apr/misc/unix/errorcodes.c
> >
> > Index: errorcodes.c
> > ===================================================================
> > RCS file: /home/cvs/apache-2.0/src/lib/apr/misc/unix/errorcodes.c,v
> > retrieving revision 1.2
> > retrieving revision 1.3
> > diff -u -r1.2 -r1.3
> > --- errorcodes.c 2000/04/19 22:50:13 1.2
> > +++ errorcodes.c 2000/04/20 14:27:55 1.3
> > @@ -56,8 +56,9 @@
> >
> > #ifdef WIN32
> > #error "not implemented yet"
> > -#elif OS/2
> > -#error "not implemented yet"
> > +#elif OS2
> > +const char *ap_os_strerror(int err, ap_pool_t *p);
> > +#define SYS_ERR_STRING(code, p) { errstr = ap_os_strerror(code, p); }
> > #elif BEOS
> > #error "not implemented yet"
> > #else
> > @@ -160,3 +161,45 @@
> > return errstr;
> > }
> > }
> > +
> > +
> > +
> > +#ifdef OS2
> > +#define INCL_DOS
> > +#include <os2.h>
> > +#include <ctype.h>
> > +
> > +const char *ap_os_strerror(int err, ap_pool_t *p)
> > +{
> > + char result[200];
> > + unsigned char message[HUGE_STRING_LEN];
> > + ULONG len;
> > + char *pos;
> > + int c;
> > +
> > + if (err >= 10000 && err < 12000) { /* socket error codes */
> > + return strerror(ap_canonical_error(err+APR_OS_START_SYSERR));
> > + }
> > + else if (DosGetMessage(NULL, 0, message, HUGE_STRING_LEN, err, "OSO001.MSG", &len)
> == 0) {
> > + len--;
> > + message[len] = 0;
> > + pos = result;
> > +
> > + if (len >= sizeof(result))
> > + len = sizeof(result-1);
> > +
> > + for (c=0; c<len; c++) {
> > + while (ap_isspace(message[c]) && ap_isspace(message[c+1])) /* skip multiple
> whitespace */
> > + c++;
> > + *(pos++) = ap_isspace(message[c]) ? ' ' : message[c];
> > + }
> > +
> > + *pos = 0;
> > + }
> > + else {
> > + sprintf(result, "OS/2 error %d", err);
> > + }
> > +
> > + return ap_pstrdup(p, result);
> > +}
> > +#endif
> >
> >
> >
>
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by rb...@covalent.net.
> Sorry, but I disagree. The primary error code on windows is getlasterror/wsagetlasterror,
> not errno. I was following the design document and it basically outlines what I think is
There is no way you were following the design doc, because I just checked
and it says:
"All platform return errno values unchanged. Each platform can also have
one system error type, which can be returned after an offset is added.
There are five types of error values in APR, each with it's own offset."
> the correct way to proceed (and what I thought we were doing all along). Since we are
> canonicalizing all the error messages before making decisions on them, I don't see the
> need to impose the "The primary error code on ALL platforms is errno" rule on the other
> platforms. We also gain a couple of things by using the native return codes in the <
> APR_OS_START_ERROR range: Native error numbers can be written to the logs & the APR code
> looks cleaner because we don't have to litter it with return (GetLastError() +
> APR_OS_START_SYSERROR);
Please read my last note. Although the native error code can be written
to the logs, a sensible error string cannot be written to the logs. The
conversion routines to go from native error codes to canonical error codes
are lossy and we therefore cannot do the conversion and still be able to
generate a valid string.
If you want to output the native error code, then all you have to do is
subtract APR_OS_START_SYSERR in log_error_core.
This approach provides the most flexability to APR app programmers, and
this is flexability that is required, IMHO.
Ryan
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> Bill,
>
> The primary error code on ALL platforms is errno. The Windows native
> error codes should be APR_OS_START_SYSERR + native code. I'm not sure if
> the docs are correct right now, but that is the decided upon design.
>
> Ryan
>
Sorry, but I disagree. The primary error code on windows is getlasterror/wsagetlasterror,
not errno. I was following the design document and it basically outlines what I think is
the correct way to proceed (and what I thought we were doing all along). Since we are
canonicalizing all the error messages before making decisions on them, I don't see the
need to impose the "The primary error code on ALL platforms is errno" rule on the other
platforms. We also gain a couple of things by using the native return codes in the <
APR_OS_START_ERROR range: Native error numbers can be written to the logs & the APR code
looks cleaner because we don't have to litter it with return (GetLastError() +
APR_OS_START_SYSERROR);
Bill
Re: error codes again... (was: cvs commit: ... errorcodes.c)
Posted by rb...@covalent.net.
> Get off this restriction about "MUST BE ERRNO". If a platform wants to
> share code, then yes: they must share error patterns. But from an API
> point of view, there is absolutely no reason to mandate errno.
>
> The errors from ap_canonical_err() can actually be in an entirely new
> numeric space. The canonical errors are DISJOINT from the APR functions'
> return values.
>
> This allows the Win32 APR code to simply do GetLastError(). Unix code can
> return errno. OS/2 and BeOS can share the Unix code, which implies they
> share "errno" as their primary returns. These latter two platforms will
> need a range that is disjoint from errno, so they can return platform-
> specific errors, but that has already been solved (by virtue of errno
> having a finite range).
>
This is how the code was originally written. It caused people to scream
that it was wrong.
> I am happy to write up a patch to the APRDesign document. I've avoided
> most of this back and forth over the error handling, but it has generated
> a LOT of traffic. I'm happy to help just to trim back the spammage :-)
That's all great, but you've obviously missed all the messages that yelled
and screamed when this was originally allowed. What you are suggesting is
EXACTLY what was originally coded for the error codes. Both Jeff and
Brian yelled because the error codes weren't sharable across platforms,
even though they were as long as the platforms used the same error value.
Yes, this issue has caused a lot of e-mail, but it has caused a lot of
e-mail because it is a complicated issue.
It is not my requirement that everybody uses errno. I didn't write the
code that way originally, it was requested after the original patch was
posted.
Ryan
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
error codes again... (was: cvs commit: ... errorcodes.c)
Posted by Greg Stein <gs...@lyra.org>.
On Thu, 20 Apr 2000 rbb@covalent.net wrote:
> > You are right, I did miss this. But I'm not sure it this is the best design choice. I'll
> > give it some more thought (or you can enlighten me :-)
>
> We really want to share code, but I'm not sure this is a big issue for
> Windows. Perhaps if we just document the hell out of the fact that
> Windows has it's error codes reversed (native returned un-munged, errno
> returned munged). As long as it is well documented with HUGE neon pink
> arrows and we NEVER want to share Windows code, I have no problem swapping
> error codes on some platforms.
I think you're making it more difficult than it needs to be. You're also
trying to impose a condition that does not need to be imposed.
*) Unix, BeOS, and OS/2 can all define their primary errors to be errno.
*) Windows (and Novell?) can define it to be GetLastError()
NOBODY is going to care what number is returned by APR. It can be
anything, in any kind of range, with any kind of meaning. There are three
things that are done with the return value:
1) compare against APR_SUCCESS
2) pass to ap_strerror()
3) pass to ap_canonical_err()
None of those require any particular meaning to the number. All semantics
attached to the error number are internalized by APR.
Get off this restriction about "MUST BE ERRNO". If a platform wants to
share code, then yes: they must share error patterns. But from an API
point of view, there is absolutely no reason to mandate errno.
The errors from ap_canonical_err() can actually be in an entirely new
numeric space. The canonical errors are DISJOINT from the APR functions'
return values.
This allows the Win32 APR code to simply do GetLastError(). Unix code can
return errno. OS/2 and BeOS can share the Unix code, which implies they
share "errno" as their primary returns. These latter two platforms will
need a range that is disjoint from errno, so they can return platform-
specific errors, but that has already been solved (by virtue of errno
having a finite range).
I am happy to write up a patch to the APRDesign document. I've avoided
most of this back and forth over the error handling, but it has generated
a LOT of traffic. I'm happy to help just to trim back the spammage :-)
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by rb...@covalent.net.
>
> You are right, I did miss this. But I'm not sure it this is the best design choice. I'll
> give it some more thought (or you can enlighten me :-)
We really want to share code, but I'm not sure this is a big issue for
Windows. Perhaps if we just document the hell out of the fact that
Windows has it's error codes reversed (native returned un-munged, errno
returned munged). As long as it is well documented with HUGE neon pink
arrows and we NEVER want to share Windows code, I have no problem swapping
error codes on some platforms.
Ryan
>
> <thinking out loud>
> The Windows APR code mostly reports/uses Win32 style errors. None of the code can be
> shared with anything other than perhaps Novell NetWare (where I suspect all the error
> codes are the same anyway). Posix code can be shared, but Posix uses errno, so that is
> not a problem either.
>
> "and what does this mean?" ........ ???? !! "She's a Witch!" !!
> </thinking...>
>
> Will ruminate more on it...
>
> Bill
>
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> > Ahh, okay, maybe I am making an assumption that you are not. I am assuming that
> > APR_OS_START_ERROR can be set to a sufficiently high number to guarantee it will be
able
> > to contain all system error codes returned by any system APR runs on. I think this is
a
> > reasonable assumption and will apply to most systems (it certainly applies for all
> > practical purposes to Windows). May have to set APR_OS_START_ERROR to 500,000 (20,000
will
> > do for Windows). For systems where this is not the case, they implement
> > ap_strerror/ap_canonicalize error to suit their needs. For Windows, it makes perfect
> > sense to make Win32 errors the 'primary error' code in APR.
>
> No, we still don't agree. You are forgetting the same thing I forgot when
> I coded it originally. (I first coded it just like you suggest). We want
> to share code whenever possible. This means that ALL platforms need to
> use the same primary error values, or code sharing is impossible.
You are right, I did miss this. But I'm not sure it this is the best design choice. I'll
give it some more thought (or you can enlighten me :-)
<thinking out loud>
The Windows APR code mostly reports/uses Win32 style errors. None of the code can be
shared with anything other than perhaps Novell NetWare (where I suspect all the error
codes are the same anyway). Posix code can be shared, but Posix uses errno, so that is
not a problem either.
"and what does this mean?" ........ ???? !! "She's a Witch!" !!
</thinking...>
Will ruminate more on it...
Bill
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by rb...@covalent.net.
> Ahh, okay, maybe I am making an assumption that you are not. I am assuming that
> APR_OS_START_ERROR can be set to a sufficiently high number to guarantee it will be able
> to contain all system error codes returned by any system APR runs on. I think this is a
> reasonable assumption and will apply to most systems (it certainly applies for all
> practical purposes to Windows). May have to set APR_OS_START_ERROR to 500,000 (20,000 will
> do for Windows). For systems where this is not the case, they implement
> ap_strerror/ap_canonicalize error to suit their needs. For Windows, it makes perfect
> sense to make Win32 errors the 'primary error' code in APR.
No, we still don't agree. You are forgetting the same thing I forgot when
I coded it originally. (I first coded it just like you suggest). We want
to share code whenever possible. This means that ALL platforms need to
use the same primary error values, or code sharing is impossible.
Ryan
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> Okay, we had this discussion a few weeks ago. I will re-hash the problems
> with the different approaches that were discussed, and the current
> approach here:
>
> Possible approaches:
>
> 1) Have all platforms return common error codes.
> 2) Have all platforms return unique error codes and provide a routine to
> convert to a common error code.
>
> The problem with the first approach, is that it is a lossy
> conversion.
> Windows and OS/2 have hundreds of error codes, errno
> doesn't. If APR does the conversion every time, then there is no way to
> retrieve a meaningful human readable string in apr_strerror.
>
Totally agree. The first approach is lossy and we made a decision early on to not loose
error status in APR. This was the right choice IMHO.
> The problem with the second approach is that it requires programmers to
> call the conversion routine (ap_canonical_error) in order to get a common
> error code. This wouldn't be necessary if the status codes were the
> useful structure they were originall designed as. But, they aren't, they
> are a single integer.
Yes, I agree this requires ap_canonical_error, which is not very pretty. And there may be
other problems with this as well, but I am not sure if we should attempt a design to
handle these problems. This is the approach we are going with and fix it if we find we
need to. I agree.
>
> We are taking the approach that a USEFUL contextual error string is very
> important. Since we are using errno as the common error code (because it
> is the lowest common denominator), we are limited to around 124 error
> codes (according to me Linux errno.h file). Windows and OS/2 have far
> more error codes than this, so two codes will resolve to the same errno
> value. When we want to generate a human readable string, how do we
> determine which error code was actual generated?
I don't think we are at odds on this point. Just implement ap_strerror() to do the right
thing depending on the range of the error message.
Ahh, okay, maybe I am making an assumption that you are not. I am assuming that
APR_OS_START_ERROR can be set to a sufficiently high number to guarantee it will be able
to contain all system error codes returned by any system APR runs on. I think this is a
reasonable assumption and will apply to most systems (it certainly applies for all
practical purposes to Windows). May have to set APR_OS_START_ERROR to 500,000 (20,000 will
do for Windows). For systems where this is not the case, they implement
ap_strerror/ap_canonicalize error to suit their needs. For Windows, it makes perfect
sense to make Win32 errors the 'primary error' code in APR.
Bill.
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by rb...@covalent.net.
Okay, we had this discussion a few weeks ago. I will re-hash the problems
with the different approaches that were discussed, and the current
approach here:
Possible approaches:
1) Have all platforms return common error codes.
2) Have all platforms return unique error codes and provide a routine to
convert to a common error code.
The problem with the first approach, is that it is a lossy
conversion. Windows and OS/2 have hundreds of error codes, errno
doesn't. If APR does the conversion every time, then there is no way to
retrieve a meaningful human readable string in apr_strerror.
The problem with the second approach is that it requires programmers to
call the conversion routine (ap_canonical_error) in order to get a common
error code. This wouldn't be necessary if the status codes were the
useful structure they were originall designed as. But, they aren't, they
are a single integer.
We are taking the approach that a USEFUL contextual error string is very
important. Since we are using errno as the common error code (because it
is the lowest common denominator), we are limited to around 124 error
codes (according to me Linux errno.h file). Windows and OS/2 have far
more error codes than this, so two codes will resolve to the same errno
value. When we want to generate a human readable string, how do we
determine which error code was actual generated?
Please read the APRDesign doc, because I just checked, it is correct, and
it details how the error code stuff works.
If you have any other suggestions for how to deal with this problem,
please let us know.
Ryan
On Thu, 20 Apr 2000, Rodent of Unusual Size wrote:
> rbb@covalent.net wrote:
> >
> > The primary error code on ALL platforms is errno.
>
> Um, no. That makes a mockery of the whole idea of portability.
> Which is APR's whole purpose for being. You do NOT impose the
> concepts from one environment onto another; you figure out a
> way to make the upper layers not know the difference.
>
> I suspect you mean that the decided-upon design is one that makes
> all platform-specific errors look *like* the errno model.
>
> > The Windows native error codes should be APR_OS_START_SYSERR +
> > native code.
>
> Uh-uh. If you're going to do that, there's no point in reserving
> a block at all -- you're just going to remap ALL platform codes
> into your arbitrary and artificial range.
>
> > I'm not sure if the docs are correct right now
>
> Then they should be verified -- they're what people are
> depending upon in order to progress properly.
> --
> #ken P-)}
>
> Ken Coar <http://Golux.Com/coar/>
> Apache Software Foundation <http://www.apache.org/>
> "Apache Server for Dummies" <http://Apache-Server.Com/>
> "Apache Server Unleashed" <http://ApacheUnleashed.Com/>
>
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: cvs commit: apache-2.0/src/lib/apr/misc/unix errorcodes.c
Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
rbb@covalent.net wrote:
>
> The primary error code on ALL platforms is errno.
Um, no. That makes a mockery of the whole idea of portability.
Which is APR's whole purpose for being. You do NOT impose the
concepts from one environment onto another; you figure out a
way to make the upper layers not know the difference.
I suspect you mean that the decided-upon design is one that makes
all platform-specific errors look *like* the errno model.
> The Windows native error codes should be APR_OS_START_SYSERR +
> native code.
Uh-uh. If you're going to do that, there's no point in reserving
a block at all -- you're just going to remap ALL platform codes
into your arbitrary and artificial range.
> I'm not sure if the docs are correct right now
Then they should be verified -- they're what people are
depending upon in order to progress properly.
--
#ken P-)}
Ken Coar <http://Golux.Com/coar/>
Apache Software Foundation <http://www.apache.org/>
"Apache Server for Dummies" <http://Apache-Server.Com/>
"Apache Server Unleashed" <http://ApacheUnleashed.Com/>