.. | .. |
---|
76 | 76 | DNS |
---|
77 | 77 | }; |
---|
78 | 78 | |
---|
79 | | -static int in_hand_shake = 1; |
---|
| 79 | +static int in_hand_shake; |
---|
80 | 80 | |
---|
81 | 81 | static char *os_name = ""; |
---|
82 | 82 | static char *os_major = ""; |
---|
.. | .. |
---|
437 | 437 | |
---|
438 | 438 | /* |
---|
439 | 439 | * 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 |
---|
441 | 441 | */ |
---|
442 | 442 | file = fopen("/etc/os-release", "r"); |
---|
443 | 443 | if (file != NULL) { |
---|
.. | .. |
---|
700 | 700 | |
---|
701 | 701 | |
---|
702 | 702 | /* |
---|
703 | | - * Gather the DNS state. |
---|
| 703 | + * Gather the DNS state. |
---|
704 | 704 | * Since there is no standard way to get this information |
---|
705 | 705 | * across various distributions of interest; we just invoke |
---|
706 | 706 | * an external script that needs to be ported across distros |
---|
.. | .. |
---|
1051 | 1051 | char *start; |
---|
1052 | 1052 | |
---|
1053 | 1053 | /* |
---|
1054 | | - * in_buf has sequence of characters that are seperated by |
---|
| 1054 | + * in_buf has sequence of characters that are separated by |
---|
1055 | 1055 | * the character ';'. The last sequence does not have the |
---|
1056 | 1056 | * terminating ";" character. |
---|
1057 | 1057 | */ |
---|
.. | .. |
---|
1360 | 1360 | |
---|
1361 | 1361 | int main(int argc, char *argv[]) |
---|
1362 | 1362 | { |
---|
1363 | | - int kvp_fd, len; |
---|
| 1363 | + int kvp_fd = -1, len; |
---|
1364 | 1364 | int error; |
---|
1365 | 1365 | struct pollfd pfd; |
---|
1366 | 1366 | char *p; |
---|
.. | .. |
---|
1400 | 1400 | openlog("KVP", 0, LOG_USER); |
---|
1401 | 1401 | syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); |
---|
1402 | 1402 | |
---|
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 | | - |
---|
1411 | 1403 | /* |
---|
1412 | 1404 | * Retrieve OS release information. |
---|
1413 | 1405 | */ |
---|
.. | .. |
---|
1420 | 1412 | |
---|
1421 | 1413 | if (kvp_file_init()) { |
---|
1422 | 1414 | 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)); |
---|
1423 | 1427 | exit(EXIT_FAILURE); |
---|
1424 | 1428 | } |
---|
1425 | 1429 | |
---|
.. | .. |
---|
1456 | 1460 | if (len != sizeof(struct hv_kvp_msg)) { |
---|
1457 | 1461 | syslog(LOG_ERR, "read failed; error:%d %s", |
---|
1458 | 1462 | errno, strerror(errno)); |
---|
1459 | | - |
---|
1460 | | - close(kvp_fd); |
---|
1461 | | - return EXIT_FAILURE; |
---|
| 1463 | + goto reopen_kvp_fd; |
---|
1462 | 1464 | } |
---|
1463 | 1465 | |
---|
1464 | 1466 | /* |
---|
.. | .. |
---|
1492 | 1494 | case KVP_OP_GET_IP_INFO: |
---|
1493 | 1495 | kvp_ip_val = &hv_msg->body.kvp_ip_val; |
---|
1494 | 1496 | |
---|
1495 | | - error = kvp_mac_to_ip(kvp_ip_val); |
---|
| 1497 | + error = kvp_mac_to_ip(kvp_ip_val); |
---|
1496 | 1498 | |
---|
1497 | 1499 | if (error) |
---|
1498 | 1500 | hv_msg->error = error; |
---|
.. | .. |
---|
1617 | 1619 | break; |
---|
1618 | 1620 | } |
---|
1619 | 1621 | |
---|
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 | + */ |
---|
1621 | 1627 | kvp_done: |
---|
1622 | 1628 | len = write(kvp_fd, hv_msg, sizeof(struct hv_kvp_msg)); |
---|
1623 | 1629 | if (len != sizeof(struct hv_kvp_msg)) { |
---|
1624 | 1630 | syslog(LOG_ERR, "write failed; error: %d %s", errno, |
---|
1625 | 1631 | strerror(errno)); |
---|
1626 | | - exit(EXIT_FAILURE); |
---|
| 1632 | + goto reopen_kvp_fd; |
---|
1627 | 1633 | } |
---|
1628 | 1634 | } |
---|
1629 | 1635 | |
---|