gethostbyname_r sets errno to EINVAL?

gethostbyname_r sets errno to EINVAL?

Post by chen.. » Sun, 08 Jan 2006 08:22:22



On some Sun machines on our network which uses NFS, gethostbyname_r is
setting errno to EINVAL (22). No non-solaris machine shows this
behaviour, also all machines which do are Solaris 8 (however not all
Solaris 8 machines show this behaviour). So I'm baffled. Does anyone
have any idea what may be going on? The man pages dont mention a thing.
Thank you.
Khan
 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Casper H.S. Di » Sun, 08 Jan 2006 18:40:54



>On some Sun machines on our network which uses NFS, gethostbyname_r is
>setting errno to EINVAL (22). No non-solaris machine shows this
>behaviour, also all machines which do are Solaris 8 (however not all
>Solaris 8 machines show this behaviour). So I'm baffled. Does anyone
>have any idea what may be going on? The man pages dont mention a thing.

What makes you think you can check "errno" after a failed
gethostbyname_r() call and get a meaningful response?

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Joerg Schilli » Sun, 08 Jan 2006 20:36:47




>On some Sun machines on our network which uses NFS, gethostbyname_r is
>setting errno to EINVAL (22). No non-solaris machine shows this
>behaviour, also all machines which do are Solaris 8 (however not all
>Solaris 8 machines show this behaviour). So I'm baffled. Does anyone
>have any idea what may be going on? The man pages dont mention a thing.

A program that checks errno after gethostbyname_r is broken.
Call "man gethostbyname_r" to find how to get error information in your case.

It could even be that errno was set to EINVAL long before you did
call gethostbyname_r

--



URL:  http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily

 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Richard L. Hamilt » Mon, 09 Jan 2006 02:42:11






>>On some Sun machines on our network which uses NFS, gethostbyname_r is
>>setting errno to EINVAL (22). No non-solaris machine shows this
>>behaviour, also all machines which do are Solaris 8 (however not all
>>Solaris 8 machines show this behaviour). So I'm baffled. Does anyone
>>have any idea what may be going on? The man pages dont mention a thing.

> A program that checks errno after gethostbyname_r is broken.

I'd like to agree, except on Solaris 9 at least the man page says

     The      reentrant       functions        gethostbyname_r(),
     gethostbyaddr_r(),  and  gethostent_r() will return NULL and
     set errno to ERANGE if the length of the buffer supplied  by
     caller  is  not  large  enough  to  store  the  result.  See
     Intro(2) for the proper usage and interpretation of errno in
     multithreaded applications.

( note that it said errno, not *h_errnop; although of course ERANGE
is of the set of values for errno, as contrasted with the values for
h_errno (HOST_NOT_FOUND, NO_RECOVERY, NO_DATA, NETDB_INTERNAL, ... );

Quote:> Call "man gethostbyname_r" to find how to get error information in your case.

> It could even be that errno was set to EINVAL long before you did
> call gethostbyname_r

...because of course errno is set when there's a reason to set it, but
it is not cleared by functions that succeed.  If you're curious whether
errno is being set by something that gethostbyname_r() calls, I suppose
you could set errno=0 immediately before calling it, although any
undocumented values or circumstances of it being set aren't something
you should be relying on anyway; even with the quote above, I don't see
anything about EINVAL.

But to be fair to all concerned, the man page looks to me to be less than
entirely clear, with returns of a pointer, or NULL, or for gethostbyname()
at least perhaps of -1 as well, and h_errno set with an error return
(I think...) but of course not cleared with success, and the one mention
above of errno.  I'm not at all sure that two different people, generally
familiar with translating descriptions into correct code, would arrive
at the same conclusions about when errno or h_errno (or *h_errnop) were
valid and should be checked after calling one of the functions on that
man page, and thus both arrive at a correct and complete error checking
technique.

--

Lasik/PRK theme music:
    "In the Hall of the Mountain King", from "Peer Gynt"

 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Joerg Schilli » Mon, 09 Jan 2006 03:38:05








>>>On some Sun machines on our network which uses NFS, gethostbyname_r is
>>>setting errno to EINVAL (22). No non-solaris machine shows this
>>>behaviour, also all machines which do are Solaris 8 (however not all
>>>Solaris 8 machines show this behaviour). So I'm baffled. Does anyone
>>>have any idea what may be going on? The man pages dont mention a thing.

>> A program that checks errno after gethostbyname_r is broken.

>I'd like to agree, except on Solaris 9 at least the man page says

>     The      reentrant       functions        gethostbyname_r(),
>     gethostbyaddr_r(),  and  gethostent_r() will return NULL and
>     set errno to ERANGE if the length of the buffer supplied  by
>     caller  is  not  large  enough  to  store  the  result.  See
>     Intro(2) for the proper usage and interpretation of errno in
>     multithreaded applications.

>( note that it said errno, not *h_errnop; although of course ERANGE
>is of the set of values for errno, as contrasted with the values for
>h_errno (HOST_NOT_FOUND, NO_RECOVERY, NO_DATA, NETDB_INTERNAL, ... );

OK, maybe this is a design problem caused by the fact that gethostbyaddr()
was designed cleanly but outside the errno world. Then the MT extensions did
not really fit into the previous error model...

--



URL:  http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily

 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Casper H.S. Di » Mon, 09 Jan 2006 20:50:23



>OK, maybe this is a design problem caused by the fact that gethostbyaddr()
>was designed cleanly but outside the errno world. Then the MT extensions did
>not really fit into the previous error model...

There's no way to know when to look at errno after gethostbyname_r()
fails; generally, just look at the value in the &herrno argument you
passed and this will tell you why the hostname lookup failed.

It looks like herrno is set to HOST_NOT_FOUND in those cases.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

gethostbyname_r sets errno to EINVAL?

Post by chen.. » Tue, 10 Jan 2006 00:51:23


Well, you all assumed that (1) gethostbyname_r failed, and/or (2) I
didnt check the value of errno before and after the call.
Neither of these is true.
Regards
Khan
 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Casper H.S. Di » Tue, 10 Jan 2006 18:55:32



>Well, you all assumed that (1) gethostbyname_r failed, and/or (2) I
>didnt check the value of errno before and after the call.
>Neither of these is true.

If it didn't fail, you have no business checking errno.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Joerg Schilli » Tue, 10 Jan 2006 19:06:50




>Well, you all assumed that (1) gethostbyname_r failed, and/or (2) I
>didnt check the value of errno before and after the call.
>Neither of these is true.

POSIX says that library functions that don't fail _should_ not modify
errno but this is not required.......

And BTW: if you do the first printf() on the (redirected to a file)
stdout stream, you will get errno == ENOTTY. Would you call this an
error indication?

--



URL:  http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily

 
 
 

gethostbyname_r sets errno to EINVAL?

Post by chen.. » Tue, 10 Jan 2006 23:47:46


Joerg, I dont get errno = ENOTTY (perhaps this is system-specific) but
I get the point, ie. successful functions can modify errno. Thanks.
Khan
 
 
 

gethostbyname_r sets errno to EINVAL?

Post by Richard L. Hamilt » Wed, 11 Jan 2006 09:15:46




Quote:> Joerg, I dont get errno = ENOTTY (perhaps this is system-specific) but
> I get the point, ie. successful functions can modify errno. Thanks.
> Khan

errno = ENOTTY very often happens because stdio probes for a terminal-like
device (by trying to do a termio[s] ioctl) to decide whether to be
line-buffered or fully buffered.  At the system-call level, this is
something that may succeed or fail.  But at the library routine level,
it's a success either way, just some information obtained about what
the file descriptor references.  Since the stdio code doesn't clear
errno after checking, if the stream didn't reference a tty, errno remains
set to ENOTTY.

So most often whether errno is set to ENOTTY depends on whether the last
stdio first reference to a stream (assuming that's when it tests; I didn't
actually look...) was to a non-tty.

--

Lasik/PRK theme music:
    "In the Hall of the Mountain King", from "Peer Gynt"

 
 
 

1. aio_write or aio_write64 on raw device fail with errno EINVAL?

I want to use aio_write64 on raw device , eg. /dev/rtestlv. the code
likes:

s_aiocb64.aio_whence = SEEK_SET;
s_aiocb64.aio_offset = ul_offset;
s_aiocb64.aio_buf = char_buffer;
s_aiocb64.aio_nbytes = ul_nbytes;

if(aio_write64(fid, &s_aiocb64) < 0)
{
        fprintf(stderr,"aio_write64 errno:%d\n",errno);
        perror("aio_write64");
        return(1);

but the aio_write64 always returns EINVAL: Indicates that the
aio_whence field does not have a valid value or that the resulting
pointer is not valid.

but the same code works well with block device, eg. /dev/testlv and
jfs file.

can anyone tell me how to use aio_write64 with raw device? many
thanks.

2. install problems

3. Q: EINVAL set by read from device driver

4. X-window....

5. startx: errno 111, errno 3

6. Network setup

7. errno 146 & errno 3

8. just a quick question, honest!

9. msgrcv() setting errno badly

10. why would a socket read() set errno to EWOULDBLOCK but still read?

11. popen() sets errno=EAGAIN

12. setting errno

13. read(2) sets errno=ERESTART