migration/rdma: Fix rdma_getaddrinfo() error checking
commit07249822212ec56484ecfb5594d2ec94c84961fa
authorMarkus Armbruster <armbru@redhat.com>
Thu, 28 Sep 2023 13:19:50 +0000 (28 15:19 +0200)
committerJuan Quintela <quintela@redhat.com>
Wed, 11 Oct 2023 09:17:03 +0000 (11 11:17 +0200)
treed0b5cc72a1e870af44eb070dd15080c477a7915b
parent0110c6b86a828c9c2f42fbed4fc0da30ad7bf6eb
migration/rdma: Fix rdma_getaddrinfo() error checking

rdma_getaddrinfo() returns 0 on success.  On error, it returns one of
the EAI_ error codes like getaddrinfo() does, or -1 with errno set.
This is broken by design: POSIX implicitly specifies the EAI_ error
codes to be non-zero, no more.  They could clash with -1.  Nothing we
can do about this design flaw.

Both callers of rdma_getaddrinfo() only recognize negative values as
error.  Works only because systems elect to make the EAI_ error codes
negative.

Best not to rely on that: change the callers to treat any non-zero
value as failure.  Also change them to return -1 instead of the value
received from getaddrinfo() on failure, to avoid positive error
values.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <20230928132019.2544702-25-armbru@redhat.com>
migration/rdma.c