@@ -52,13 +52,13 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver,
SocketAddress ***addrs,
Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
struct addrinfo ai, *res, *e;
InetSocketAddress *iaddr = &addr->u.inet;
char port[33];
char uaddr[INET6_ADDRSTRLEN + 1];
char uport[33];
int rc;
- Error *err = NULL;
size_t i;
*naddrs = 0;
@@ -69,11 +69,10 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver,
if (iaddr->has_numeric && iaddr->numeric) {
ai.ai_flags |= AI_NUMERICHOST | AI_NUMERICSERV;
}
- ai.ai_family = inet_ai_family_from_address(iaddr, &err);
+ ai.ai_family = inet_ai_family_from_address(iaddr, errp);
ai.ai_socktype = SOCK_STREAM;
- if (err) {
- error_propagate(errp, err);
+ if (*errp) {
return -1;
}
@@ -65,11 +65,11 @@ int qio_net_listener_open_sync(QIONetListener *listener,
int num,
Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
QIODNSResolver *resolver = qio_dns_resolver_get_instance();
SocketAddress **resaddrs;
size_t nresaddrs;
size_t i;
- Error *err = NULL;
bool success = false;
if (qio_dns_resolver_lookup_sync(resolver,
@@ -84,7 +84,7 @@ int qio_net_listener_open_sync(QIONetListener *listener,
QIOChannelSocket *sioc = qio_channel_socket_new();
if (qio_channel_socket_listen_sync(sioc, resaddrs[i], num,
- err ? NULL : &err) == 0) {
+ *errp ? NULL : errp) == 0) {
success = true;
qio_net_listener_add(listener, sioc);
@@ -96,10 +96,9 @@ int qio_net_listener_open_sync(QIONetListener *listener,
g_free(resaddrs);
if (success) {
- error_free(err);
+ error_free_errp(errp);
return 0;
} else {
- error_propagate(errp, err);
return -1;
}
}
If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases. If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit (together with its neighbors) was generated by for f in $(git grep -l errp \*.[ch]); do \ spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \ done; then fix a bit of compilation problems: coccinelle for some reason leaves several f() { ... goto out; ... out: } patterns, with "out:" at function end. then ./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)" (auto-msg was a file with this commit message) Still, for backporting it may be more comfortable to use only the first command and then do one huge commit. Reported-by: Kevin Wolf <kwolf@redhat.com> Reported-by: Greg Kurz <groug@kaod.org> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> --- io/dns-resolver.c | 7 +++---- io/net-listener.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-)