forked from pool/hyper-v
- Reopen the devices if read() or write() returns errors (9fc3c01a)
OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=146
This commit is contained in:
@@ -76,7 +76,7 @@ enum {
|
||||
DNS
|
||||
};
|
||||
|
||||
static int in_hand_shake = 1;
|
||||
static int in_hand_shake;
|
||||
|
||||
static char *os_name = "";
|
||||
static char *os_major = "";
|
||||
@@ -1361,7 +1361,7 @@ void print_usage(char *argv[])
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int kvp_fd, len;
|
||||
int kvp_fd = -1, len;
|
||||
int error;
|
||||
struct pollfd pfd;
|
||||
char *p;
|
||||
@@ -1401,14 +1401,6 @@ int main(int argc, char *argv[])
|
||||
openlog("KVP", 0, LOG_USER);
|
||||
syslog(LOG_INFO, "KVP starting; pid is:%d", getpid());
|
||||
|
||||
kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC);
|
||||
|
||||
if (kvp_fd < 0) {
|
||||
syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s",
|
||||
errno, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve OS release information.
|
||||
*/
|
||||
@@ -1424,6 +1416,18 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
reopen_kvp_fd:
|
||||
if (kvp_fd != -1)
|
||||
close(kvp_fd);
|
||||
in_hand_shake = 1;
|
||||
kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC);
|
||||
|
||||
if (kvp_fd < 0) {
|
||||
syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s",
|
||||
errno, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register ourselves with the kernel.
|
||||
*/
|
||||
@@ -1457,9 +1461,7 @@ int main(int argc, char *argv[])
|
||||
if (len != sizeof(struct hv_kvp_msg)) {
|
||||
syslog(LOG_ERR, "read failed; error:%d %s",
|
||||
errno, strerror(errno));
|
||||
|
||||
close(kvp_fd);
|
||||
return EXIT_FAILURE;
|
||||
goto reopen_kvp_fd;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1618,13 +1620,17 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
/* Send the value back to the kernel. */
|
||||
/*
|
||||
* Send the value back to the kernel. Note: the write() may
|
||||
* return an error due to hibernation; we can ignore the error
|
||||
* by resetting the dev file, i.e. closing and re-opening it.
|
||||
*/
|
||||
kvp_done:
|
||||
len = write(kvp_fd, hv_msg, sizeof(struct hv_kvp_msg));
|
||||
if (len != sizeof(struct hv_kvp_msg)) {
|
||||
syslog(LOG_ERR, "write failed; error: %d %s", errno,
|
||||
strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
goto reopen_kvp_fd;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user