Use struct sockpeercred when available

OpenBSD uses 'struct sockpeercred' instead of 'struct ucred'. Add a
configure check that detects its presence and use if in the code that
could be compiled on OpenBSD.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
This commit is contained in:
Jasper Lievisse Adriaanse 2016-01-08 00:31:17 +03:00 committed by Roman Bogorodskiy
parent 1b60f1b401
commit 91b423beb7
2 changed files with 10 additions and 0 deletions

View File

@ -393,6 +393,12 @@ AC_CHECK_TYPE([struct ifreq],
#include <net/if.h>
]])
AC_CHECK_TYPE([struct sockpeercred],
[AC_DEFINE([HAVE_STRUCT_SOCKPEERCRED], [1],
[Defined if struct sockpeercred is available])],
[], [[#include <sys/socket.h>
]])
AC_CHECK_DECLS([ETH_FLAG_TXVLAN, ETH_FLAG_NTUPLE, ETH_FLAG_RXHASH, ETH_FLAG_LRO,
ETHTOOL_GGSO, ETHTOOL_GGRO, ETHTOOL_GFLAGS, ETHTOOL_GFEATURES],
[], [], [[#include <linux/ethtool.h>

View File

@ -1259,7 +1259,11 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
pid_t *pid,
unsigned long long *timestamp)
{
# if defined(HAVE_STRUCT_SOCKPEERCRED)
struct sockpeercred cr;
# else
struct ucred cr;
# endif
socklen_t cr_len = sizeof(cr);
int ret = -1;