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

Denis Kenzior <[email protected]> Mon, 4 Aug 2025 09:37:54 -0500
Newsgroups dev.linux.lists.connman
Message-ID <[email protected]>
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.

>   };
>   
>   #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?

>   		}
>   	}
>   

Regards,
-Denis