hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/tools/hv/hv_kvp_daemon.c
....@@ -76,7 +76,7 @@
7676 DNS
7777 };
7878
79
-static int in_hand_shake = 1;
79
+static int in_hand_shake;
8080
8181 static char *os_name = "";
8282 static char *os_major = "";
....@@ -437,7 +437,7 @@
437437
438438 /*
439439 * Parse the /etc/os-release file if present:
440
- * http://www.freedesktop.org/software/systemd/man/os-release.html
440
+ * https://www.freedesktop.org/software/systemd/man/os-release.html
441441 */
442442 file = fopen("/etc/os-release", "r");
443443 if (file != NULL) {
....@@ -700,7 +700,7 @@
700700
701701
702702 /*
703
- * Gather the DNS state.
703
+ * Gather the DNS state.
704704 * Since there is no standard way to get this information
705705 * across various distributions of interest; we just invoke
706706 * an external script that needs to be ported across distros
....@@ -1051,7 +1051,7 @@
10511051 char *start;
10521052
10531053 /*
1054
- * in_buf has sequence of characters that are seperated by
1054
+ * in_buf has sequence of characters that are separated by
10551055 * the character ';'. The last sequence does not have the
10561056 * terminating ";" character.
10571057 */
....@@ -1360,7 +1360,7 @@
13601360
13611361 int main(int argc, char *argv[])
13621362 {
1363
- int kvp_fd, len;
1363
+ int kvp_fd = -1, len;
13641364 int error;
13651365 struct pollfd pfd;
13661366 char *p;
....@@ -1400,14 +1400,6 @@
14001400 openlog("KVP", 0, LOG_USER);
14011401 syslog(LOG_INFO, "KVP starting; pid is:%d", getpid());
14021402
1403
- kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC);
1404
-
1405
- if (kvp_fd < 0) {
1406
- syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s",
1407
- errno, strerror(errno));
1408
- exit(EXIT_FAILURE);
1409
- }
1410
-
14111403 /*
14121404 * Retrieve OS release information.
14131405 */
....@@ -1420,6 +1412,18 @@
14201412
14211413 if (kvp_file_init()) {
14221414 syslog(LOG_ERR, "Failed to initialize the pools");
1415
+ exit(EXIT_FAILURE);
1416
+ }
1417
+
1418
+reopen_kvp_fd:
1419
+ if (kvp_fd != -1)
1420
+ close(kvp_fd);
1421
+ in_hand_shake = 1;
1422
+ kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC);
1423
+
1424
+ if (kvp_fd < 0) {
1425
+ syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s",
1426
+ errno, strerror(errno));
14231427 exit(EXIT_FAILURE);
14241428 }
14251429
....@@ -1456,9 +1460,7 @@
14561460 if (len != sizeof(struct hv_kvp_msg)) {
14571461 syslog(LOG_ERR, "read failed; error:%d %s",
14581462 errno, strerror(errno));
1459
-
1460
- close(kvp_fd);
1461
- return EXIT_FAILURE;
1463
+ goto reopen_kvp_fd;
14621464 }
14631465
14641466 /*
....@@ -1492,7 +1494,7 @@
14921494 case KVP_OP_GET_IP_INFO:
14931495 kvp_ip_val = &hv_msg->body.kvp_ip_val;
14941496
1495
- error = kvp_mac_to_ip(kvp_ip_val);
1497
+ error = kvp_mac_to_ip(kvp_ip_val);
14961498
14971499 if (error)
14981500 hv_msg->error = error;
....@@ -1617,13 +1619,17 @@
16171619 break;
16181620 }
16191621
1620
- /* Send the value back to the kernel. */
1622
+ /*
1623
+ * Send the value back to the kernel. Note: the write() may
1624
+ * return an error due to hibernation; we can ignore the error
1625
+ * by resetting the dev file, i.e. closing and re-opening it.
1626
+ */
16211627 kvp_done:
16221628 len = write(kvp_fd, hv_msg, sizeof(struct hv_kvp_msg));
16231629 if (len != sizeof(struct hv_kvp_msg)) {
16241630 syslog(LOG_ERR, "write failed; error: %d %s", errno,
16251631 strerror(errno));
1626
- exit(EXIT_FAILURE);
1632
+ goto reopen_kvp_fd;
16271633 }
16281634 }
16291635