BUILD: server: fix build regression on old compilers (<= gcc-4.4)

Willy reported that since 3ac79b504 ("MEDIUM: server:
make server_set_inetaddr() updater serializable"), haproxy fails to
compile on some older compilers such as gcc-4.4 with this kind of error:

  src/server.c: In function 'snr_resolution_cb':
  src/server.c:4471: error: unknown field 'dns_resolver' specified in initializer
  compilation terminated due to -Wfatal-errors.
  make: *** [Makefile:1006: src/server.o] Error 1

This is due to referencing a member inside anonymous union from a compound
literal assignment. Apparently such use of anonymous union wasn't properly
supported back then on older compilers. To fix the issue, we give "u" name
to the parent union use this name to explicitly refer to the union where
relevant in the code (only a few changes fortunately).

The fix itself was verified to restore build compatibility with gcc 4.4
(and even 4.2).

As 3ac79b504 is used as a prerequisite for 64c9c8ef3 ("BUG/MINOR:
server/dns: use server_set_inetaddr() to unset srv addr from DNS"), please
consider backporting this patch too if 64c9c8ef3 happens to be backported
in 2.9.
This commit is contained in:
Aurelien DARRAGON 2024-03-25 13:38:36 +01:00 committed by Willy Tarreau
parent 56c4b29ff1
commit 3de1acfb23
2 changed files with 3 additions and 3 deletions

View File

@ -630,7 +630,7 @@ struct server_inetaddr_updater {
struct {
unsigned int ns_id; // nameserver id responsible for the update
} dns_resolver; // SERVER_INETADDR_UPDATER_DNS_RESOLVER specific infos
}; // per updater's additional ctx
} u; // per updater's additional ctx
};
#define SERVER_INETADDR_UPDATER_NONE \
(struct server_inetaddr_updater){ .by = SERVER_INETADDR_UPDATER_BY_NONE, \
@ -656,7 +656,7 @@ struct server_inetaddr_updater {
(struct server_inetaddr_updater){ \
.by = SERVER_INETADDR_UPDATER_BY_DNS_RESOLVER, \
.dns = 1, \
.dns_resolver.ns_id = _ns_id, \
.u.dns_resolver.ns_id = _ns_id, \
}
/* data provided to EVENT_HDL_SUB_SERVER_INETADDR handlers through

View File

@ -3824,7 +3824,7 @@ static void _srv_append_inetaddr_updater_info(struct buffer *out,
* query
*/
BUG_ON(!r);
ns = find_nameserver_by_resolvers_and_id(r, updater.dns_resolver.ns_id);
ns = find_nameserver_by_resolvers_and_id(r, updater.u.dns_resolver.ns_id);
BUG_ON(!ns);
chunk_appendf(out, " by '%s/%s'", r->id, ns->id);
}