[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gpsd-dev] [PATCH v3 1/1] gps2udp: reset errno after successful geta

From: Ferry Huberts
Subject: Re: [gpsd-dev] [PATCH v3 1/1] gps2udp: reset errno after successful getaddrinfo call
Date: Fri, 03 Jan 2014 19:43:14 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 03/01/14 18:11, Mike Frysinger wrote:
On Friday 03 January 2014 10:18:42 Ferry Huberts wrote:
On 03/01/14 16:00, Mike Frysinger wrote:
On Friday 03 January 2014 09:29:29 Ferry Huberts wrote:
On 03/01/14 15:18, Mike Frysinger wrote:
On Friday 03 January 2014 08:33:47 Ferry Huberts wrote:
It may return errno==2 ("No such file or directory") when the file
/etc/gai.conf is not present.

The observed effect was that the port number conversion considered
a perfectly valid port number as invalid.

you still haven't really explained why this is the way to go.
functions do not "return errno".  they return real values, and any
code calling those functions need to first check the return value
*before* ever looking at errno.

Which is exactly what happens here: the code bails out if the function
call is not successful.

what code is bailing where ?

please do read the code:

i did read the code

     if ((ret = getaddrinfo(host, service, &hints, &result))) {
        return NL_NOHOST;

returns from the function (with return value NL_NOHOST) when the
getaddrinfo call is not successful (returns a non-zero value).

except you didn't reset the errno in that case.  you reset it when the
function succeeded.

so, once again, what is the actual problem you're trying to fix ?

See my first patch:

The problem is here in gps2udp:
    /* check before going background if we can connect to gpsd */

    /* Open UDP port */
    if (udpchannel > 0) {
        int status = open_udp(udphostport);
        if (status !=0) exit (1);

The connect2gpsd function calls down into the netlib_connectsock function in netlib.c. This function succeeds but leaves behind errno == 2. The the open_udp function goes off and does stuff, like axtract a port number by doing atoi. according to the atoi manpage, it is the same as strtol(nptr, NULL, 10). strtol has in its manpage
  The implementation may also set errno to EINVAL in case no conversion
  was performed (no digits seen, and 0 returned).
After atoi, open_udp checks errno and finds it at 2, left behind by the netlib_connectsock function.

I was asked by Gary Miller to further look into why errno wasn't zero.
I did. I fixed the root cause.

I'm thoroughly confused by what you guys actually want.

The function call may set errno even though it succeeds.

that is not a bug

exactly, which is why we must reset errno, because otherwise other
functions are affected.

no, no they are not

Well, they are. Otherwise I wouldn't have had to fix stuff.

Ferry Huberts

reply via email to

[Prev in Thread] Current Thread [Next in Thread]