1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-14 07:23:23 +00:00

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

@ -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);