Procan: try to find out VSOCK CID only when running as root

This commit is contained in:
Gerhard Rieger 2023-01-26 10:06:01 +01:00
parent c3719e7603
commit 2a04219dee
2 changed files with 7 additions and 0 deletions

View file

@ -54,6 +54,8 @@ Corrections:
restrictive mode. Furthermore Silla Rizzoli experienced that Minicom
ignores lock files with mode 600, so it is set to 644 now.
Procan tries to find out VSOCK CID only when running as root
Features:
VSOCK, VSOCK-L support options pf, socktype, prototype (currently
useless)

View file

@ -112,11 +112,16 @@ static int iffan(FILE *outfile) {
static int vsockan(FILE *outfile) {
unsigned int cid;
int vsock;
if (Getuid() != 0) {
return 1;
}
if ((vsock = Open("/dev/vsock", O_RDONLY, 0)) < 0 ) {
Warn1("open(\"/dev/vsock\", ...): %s", strerror(errno));
return -1;
} else if (Ioctl(vsock, IOCTL_VM_SOCKETS_GET_LOCAL_CID, &cid) < 0) {
Warn2("ioctl(%d, IOCTL_VM_SOCKETS_GET_LOCAL_CID, ...): %s",
vsock, strerror(errno));
return -1;
} else {
Notice1("VSOCK CID=%u", cid);
fprintf(outfile, "\nVSOCK_CID = %u\n", cid);