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 <matthew.barnes@cloud.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
This commit is contained in:
Matthew Barnes authored and Jan Beulich committed 2024-08-02 08:43:57 +02:00
1 parent 85191cf321
commit e92a453c8d
1 file changed
+20 -2
+20 -2
View File
@@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include <xenctrl.h> #include <xenctrl.h>
@@ -24,7 +25,23 @@ int main(int argc, char **argv)
status.port = port; status.port = port;
rc = xc_evtchn_status(xch, &status); rc = xc_evtchn_status(xch, &status);
if ( rc < 0 ) 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 ) if ( status.status == EVTCHNSTAT_closed )
continue; continue;
@@ -58,7 +75,8 @@ int main(int argc, char **argv)
printf("\n"); printf("\n");
} }
out:
xc_interface_close(xch); xc_interface_close(xch);
return 0; return rc;
} }
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.