You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Stas Bekman <st...@stason.org> on 2004/05/17 05:17:41 UTC
rc and errno in apr api
I have noticed that besides apr_status_t many of the apr api functions get
errno set on error, since they perform system calls internally, which set
errno. e.g. apr_file_read.
While writing interfaces for other systems, that talk to libapr, and use errno
for the errors handling, it's not possible to simply set errno to apr_status_t
returned by some apr calls, since in several cases that code/errstr is
specific to apr and there will be no equivalent in the errno posix land. So
there is no 1:1 mapping between apr_status_t and errno. When there is a
mismatch some alternative solution is out to be found.
What I'm after is having APR API specify which apr functions have errno set,
so one can rely on that and not do guessing which can change in the future.
For example it seems that apr_file_read will always have errno set on failure.
But I have no idea about other functions, especially since there are several
platform specific implementations of each.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: rc and errno in apr api
Posted by Ben Laurie <be...@algroup.co.uk>.
Stas Bekman wrote:
> I have noticed that besides apr_status_t many of the apr api functions
> get errno set on error, since they perform system calls internally,
> which set errno. e.g. apr_file_read.
>
> While writing interfaces for other systems, that talk to libapr, and use
> errno for the errors handling, it's not possible to simply set errno to
> apr_status_t returned by some apr calls, since in several cases that
> code/errstr is specific to apr and there will be no equivalent in the
> errno posix land. So there is no 1:1 mapping between apr_status_t and
> errno. When there is a mismatch some alternative solution is out to be
> found.
>
> What I'm after is having APR API specify which apr functions have errno
> set, so one can rely on that and not do guessing which can change in the
> future. For example it seems that apr_file_read will always have errno
> set on failure. But I have no idea about other functions, especially
> since there are several platform specific implementations of each.
This doesn't make sense to me:
a) It would be impossible to fulfill the guarantee sensibly (we'd
potentially have to fudge errno if we changed the implementation).
b) It would almost certainly vary according to platform.
c) The errors we return are apr_status_t - if you can't represent them
as errno, then don't use errno!
If you are really forced to use errno, then just pick some value that's
as close as you can get for apr_status_t you can't represent.
Cheers,
Ben.
--
http://www.apache-ssl.org/ben.html http://www.thebunker.net/
"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff
Re: rc and errno in apr api
Posted by Nick Kew <ni...@webthing.com>.
On Mon, 17 May 2004, Joe Orton wrote:
> Do you mean, such that errno is guaranteed to be equal to the
> apr_status_t returned? I don't think APR does/could/should give that
> guarantee anywhere.
<SCO>All your APR are belong to us</SCO>
They cited errno.h as an instance of their IP that had been - erm -
illegally stolen and used in Linux!
--
Nick Kew
Re: rc and errno in apr api
Posted by Stas Bekman <st...@stason.org>.
Joe Orton wrote:
> On Sun, May 16, 2004 at 08:17:41PM -0700, Stas Bekman wrote:
>
>>What I'm after is having APR API specify which apr functions have errno
>>set, so one can rely on that and not do guessing which can change in the
>>future.
>
>
> Do you mean, such that errno is guaranteed to be equal to the
> apr_status_t returned? I don't think APR does/could/should give that
> guarantee anywhere.
>
> Yes, errno may be changed by any APR function as a side-effect, but not
> in a predictable manner. Even with the Unix apr_file_read() you may get
> an apr_status_t returned which is different from errno if the mutex
> unlock call fails, for example...
OK, I understood - one can't rely on errno to be set and it just so happens
that it gets set for certain calls on certain platforms under certain
circumstances. Thank you.
...
The reason I've asked is this. Perl has its error variable $! tied to errno.
So when you do:
open $fh, "foo" or die "$!"
if open fails (e.g. "file not found", "perms denied"), the error will end up
in $!. $! is a dual variable. In a numerical context it contains errno, in a
string context it contains strerror(errno).
So since I've implemented Perl IO interface using APR (needed for those cases
when an APR function returns apr_file_t which one may want to manipulate in
perl, using the familiar perl API, I need to be able to propogate errors to
the user. If I can't rely on errno being set, I can't give users $! as they
are used to - I can't write idiomatic API and I need to provide an alternative
way to give users the errors.
So when I've used open() in my tests I was getting $! working automatically,
since apr_file_open() happened to use system calls that set errno, w/o apr
doing that. So I hoped that it could be true for all other apr IO calls and
I'll be able to give users a transparent experience. But as you suggest this
is not the case. Oh, well, we will deal with that.
Thanks again!
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: rc and errno in apr api
Posted by Joe Orton <jo...@manyfish.co.uk>.
On Sun, May 16, 2004 at 08:17:41PM -0700, Stas Bekman wrote:
> What I'm after is having APR API specify which apr functions have errno
> set, so one can rely on that and not do guessing which can change in the
> future.
Do you mean, such that errno is guaranteed to be equal to the
apr_status_t returned? I don't think APR does/could/should give that
guarantee anywhere.
Yes, errno may be changed by any APR function as a side-effect, but not
in a predictable manner. Even with the Unix apr_file_read() you may get
an apr_status_t returned which is different from errno if the mutex
unlock call fails, for example...
Regards,
joe
Re: rc and errno in apr api
Posted by rb...@rkbloom.net.
On Sun, 16 May 2004, Cliff Woolley wrote:
> On Sun, 16 May 2004, Stas Bekman wrote:
>
> > What I'm after is having APR API specify which apr functions have errno set,
> > so one can rely on that and not do guessing which can change in the future.
>
> My gut reaction is that if we actually /need/ errno to be set to glean
> useful information about what happened, we did something wrong in choosing
> which apr_status_t's could be returned from that function.
Cliff is correct, but I would go one step further. Any APR api that is
setting errno is doing so by chance. It would be perfectly valid
(although stupid) for us to add errno=0 at the end of every APR function.
Also, for portability reasons, you really can't rely on errno at all.
Windows only uses it sporatically, and for every function in APR
(including apr_file_open) there are some paths that will set errno and
others that won't.
Ryan
Re: rc and errno in apr api
Posted by Cliff Woolley <jw...@virginia.edu>.
On Sun, 16 May 2004, Stas Bekman wrote:
> What I'm after is having APR API specify which apr functions have errno set,
> so one can rely on that and not do guessing which can change in the future.
My gut reaction is that if we actually /need/ errno to be set to glean
useful information about what happened, we did something wrong in choosing
which apr_status_t's could be returned from that function.
--Cliff