Re: [PATCH 16/45] gresolv: Add generic error for GResolv struct with getter

Jussi Laakkonen <[email protected]> Fri, 8 Aug 2025 15:34:09 +0300
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
Hi Denis,

On 8/4/25 17:37, Denis Kenzior wrote:
> Hi Jussi,
> 
> On 7/11/25 9:27 AM, Jussi Laakkonen wrote:
>> Add a error for the struct to be used with hostname lookup. The function
>> should return either 0 in case of error or the source id, this fixes the
>> wrong returns when error happens and makes it possible to retrieve the
>> error afterwards.
>> ---
>>   gweb/gresolv.c | 15 +++++++++++++--
>>   gweb/gresolv.h |  2 ++
>>   2 files changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/gweb/gresolv.c b/gweb/gresolv.c
>> index 8101d718..1f1db474 100644
>> --- a/gweb/gresolv.c
>> +++ b/gweb/gresolv.c
>> @@ -116,6 +116,7 @@ struct _GResolv {
>>       GResolvDebugFunc debug_func;
>>       gpointer debug_data;
>> +    int err;
> 
> These errors are really local to g_resolv_lookup_hostname, so not sure 
> this warrants a member.
> 

Personally I think that the error should be in some way retrievable by 
the caller. Previously the error and the source id's were mixed which is 
never a good option.

>>   };
>>   #define debug(resolv, format, arg...)                \
>> @@ -1060,7 +1061,8 @@ guint g_resolv_lookup_hostname(GResolv *resolv, 
>> const char *hostname,
>>       if (resolv->result_family != AF_INET6) {
>>           if (add_query(lookup, hostname, ns_t_a)) {
>>               g_free(lookup);
>> -            return -EIO;
>> +            resolv->err = -EIO;
>> +            return 0;
> 
> Since this is a glib library, have you considered returning 0 and 
> setting GError in/out parameter instead?

Yeah, sure, I can change it to GError. Just tried to keep things really 
simple here.

> 
>>           }
>>       }
> 
> Regards,
> -Denis


BR,
  Jussi