From: Matthew Barnes Date: Thu, 8 Aug 2024 11:57:28 +0000 (+0200) Subject: tools/lsevtchn: Use errno macro to handle hypercall error cases X-Git-Tag: RELEASE-4.17.5~4 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2cb91df736374f3a09cbff1d61fe8e7d6dbc636c;p=xen.git tools/lsevtchn: Use errno macro to handle hypercall error cases Currently, lsevtchn aborts its event channel enumeration when it hits an event channel that is owned by Xen. lsevtchn does not distinguish between different hypercall errors, which results in lsevtchn missing potential relevant event channels with higher port numbers. Use the errno macro to distinguish between hypercall errors, and continue event channel enumeration if the hypercall error is not critical to enumeration. Signed-off-by: Matthew Barnes Reviewed-by: Anthony PERARD master commit: e92a453c8db8bba62d6be3006079e2b9990c3978 master date: 2024-08-02 08:43:57 +0200 --- diff --git a/tools/xcutils/lsevtchn.c b/tools/xcutils/lsevtchn.c index d1710613dd..30c8d847b8 100644 --- a/tools/xcutils/lsevtchn.c +++ b/tools/xcutils/lsevtchn.c @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -24,7 +25,23 @@ int main(int argc, char **argv) status.port = port; rc = xc_evtchn_status(xch, &status); if ( rc < 0 ) - break; + { + switch ( errno ) + { + case EACCES: /* Xen-owned evtchn */ + continue; + + case EINVAL: /* Port enumeration has ended */ + rc = 0; + break; + + default: + perror("xc_evtchn_status"); + rc = 1; + break; + } + goto out; + } if ( status.status == EVTCHNSTAT_closed ) continue; @@ -58,7 +75,8 @@ int main(int argc, char **argv) printf("\n"); } + out: xc_interface_close(xch); - return 0; + return rc; }