diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/hv/hv_kvp_daemon.c | 29 | ||||
-rw-r--r-- | tools/hv/hv_vss_daemon.c | 8 |
2 files changed, 19 insertions, 18 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index 8fd9ec66121..b8d6d541d85 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c @@ -89,6 +89,7 @@ static char *processor_arch; static char *os_build; static char *os_version; static char *lic_version = "Unknown version"; +static char full_domain_name[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; static struct utsname uts_buf; /* @@ -1367,7 +1368,7 @@ setval_error: } -static int +static void kvp_get_domain_name(char *buffer, int length) { struct addrinfo hints, *info ; @@ -1381,12 +1382,12 @@ kvp_get_domain_name(char *buffer, int length) error = getaddrinfo(buffer, NULL, &hints, &info); if (error != 0) { - strcpy(buffer, "getaddrinfo failed\n"); - return error; + snprintf(buffer, length, "getaddrinfo failed: 0x%x %s", + error, gai_strerror(error)); + return; } - strcpy(buffer, info->ai_canonname); + snprintf(buffer, length, "%s", info->ai_canonname); freeaddrinfo(info); - return error; } static int @@ -1433,7 +1434,6 @@ int main(void) int pool; char *if_name; struct hv_kvp_ipaddr_value *kvp_ip_val; - char *kvp_send_buffer; char *kvp_recv_buffer; size_t kvp_recv_buffer_len; @@ -1442,17 +1442,21 @@ int main(void) openlog("KVP", 0, LOG_USER); syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); - kvp_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_kvp_msg); - kvp_send_buffer = calloc(1, kvp_recv_buffer_len); + kvp_recv_buffer_len = NLMSG_LENGTH(0) + sizeof(struct cn_msg) + sizeof(struct hv_kvp_msg); kvp_recv_buffer = calloc(1, kvp_recv_buffer_len); - if (!(kvp_send_buffer && kvp_recv_buffer)) { - syslog(LOG_ERR, "Failed to allocate netlink buffers"); + if (!kvp_recv_buffer) { + syslog(LOG_ERR, "Failed to allocate netlink buffer"); exit(EXIT_FAILURE); } /* * Retrieve OS release information. */ kvp_get_os_info(); + /* + * Cache Fully Qualified Domain Name because getaddrinfo takes an + * unpredictable amount of time to finish. + */ + kvp_get_domain_name(full_domain_name, sizeof(full_domain_name)); if (kvp_file_init()) { syslog(LOG_ERR, "Failed to initialize the pools"); @@ -1488,7 +1492,7 @@ int main(void) /* * Register ourselves with the kernel. */ - message = (struct cn_msg *)kvp_send_buffer; + message = (struct cn_msg *)kvp_recv_buffer; message->id.idx = CN_KVP_IDX; message->id.val = CN_KVP_VAL; @@ -1671,8 +1675,7 @@ int main(void) switch (hv_msg->body.kvp_enum_data.index) { case FullyQualifiedDomainName: - kvp_get_domain_name(key_value, - HV_KVP_EXCHANGE_MAX_VALUE_SIZE); + strcpy(key_value, full_domain_name); strcpy(key_name, "FullyQualifiedDomainName"); break; case IntegrationServicesVersion: diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c index 8611962c672..8bcb04096eb 100644 --- a/tools/hv/hv_vss_daemon.c +++ b/tools/hv/hv_vss_daemon.c @@ -140,7 +140,6 @@ int main(void) struct cn_msg *incoming_cn_msg; int op; struct hv_vss_msg *vss_msg; - char *vss_send_buffer; char *vss_recv_buffer; size_t vss_recv_buffer_len; @@ -150,10 +149,9 @@ int main(void) openlog("Hyper-V VSS", 0, LOG_USER); syslog(LOG_INFO, "VSS starting; pid is:%d", getpid()); - vss_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_vss_msg); - vss_send_buffer = calloc(1, vss_recv_buffer_len); + vss_recv_buffer_len = NLMSG_LENGTH(0) + sizeof(struct cn_msg) + sizeof(struct hv_vss_msg); vss_recv_buffer = calloc(1, vss_recv_buffer_len); - if (!(vss_send_buffer && vss_recv_buffer)) { + if (!vss_recv_buffer) { syslog(LOG_ERR, "Failed to allocate netlink buffers"); exit(EXIT_FAILURE); } @@ -185,7 +183,7 @@ int main(void) /* * Register ourselves with the kernel. */ - message = (struct cn_msg *)vss_send_buffer; + message = (struct cn_msg *)vss_recv_buffer; message->id.idx = CN_VSS_IDX; message->id.val = CN_VSS_VAL; message->ack = 0; |