aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hv/hv_kvp_daemon.c
diff options
context:
space:
mode:
authorOlaf Hering <olaf@aepfle.de>2013-08-07 13:14:37 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 15:03:31 -0400
commit58125210ab3b202917c04fca014317944d464ea0 (patch)
tree11f8eafbb3326197b82f6192db97bf523fbc6d4e /tools/hv/hv_kvp_daemon.c
parentd6675667540a19427099cfd7eb80fcd4320a951d (diff)
Tools: hv: cache FQDN in kvp_daemon to avoid timeouts
kvp_daemon does some operations which take an unpredicable amount of time. In addition the kernel driver gives the kvp_daemon a 5 second timeout to respond to message from the host. If an operation such as getaddrinfo takes a long time and the timeout triggers then netlink errors occour. As a result of such errors the daemon just terminates and the service becomes unavailable. Idendifying and fixing these shortcomings in the kernel-userland communication protocol will be done in separate patches. This change fixes just one obvious timeout bug. Update kvp_get_domain_name to not return a value, better diagnostic for the consumer of the hostname string, remove trailing newline in error case, use snprintf to not overrun output buffer, get hostname only once and return the cached result. Signed-off-by: Olaf Hering <olaf@aepfle.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/hv/hv_kvp_daemon.c')
-rw-r--r--tools/hv/hv_kvp_daemon.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 8fd9ec66121c..21bd7d4574fc 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -89,6 +89,7 @@ static char *processor_arch;
89static char *os_build; 89static char *os_build;
90static char *os_version; 90static char *os_version;
91static char *lic_version = "Unknown version"; 91static char *lic_version = "Unknown version";
92static char full_domain_name[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
92static struct utsname uts_buf; 93static struct utsname uts_buf;
93 94
94/* 95/*
@@ -1367,7 +1368,7 @@ setval_error:
1367} 1368}
1368 1369
1369 1370
1370static int 1371static void
1371kvp_get_domain_name(char *buffer, int length) 1372kvp_get_domain_name(char *buffer, int length)
1372{ 1373{
1373 struct addrinfo hints, *info ; 1374 struct addrinfo hints, *info ;
@@ -1381,12 +1382,12 @@ kvp_get_domain_name(char *buffer, int length)
1381 1382
1382 error = getaddrinfo(buffer, NULL, &hints, &info); 1383 error = getaddrinfo(buffer, NULL, &hints, &info);
1383 if (error != 0) { 1384 if (error != 0) {
1384 strcpy(buffer, "getaddrinfo failed\n"); 1385 snprintf(buffer, length, "getaddrinfo failed: 0x%x %s",
1385 return error; 1386 error, gai_strerror(error));
1387 return;
1386 } 1388 }
1387 strcpy(buffer, info->ai_canonname); 1389 snprintf(buffer, length, "%s", info->ai_canonname);
1388 freeaddrinfo(info); 1390 freeaddrinfo(info);
1389 return error;
1390} 1391}
1391 1392
1392static int 1393static int
@@ -1453,6 +1454,11 @@ int main(void)
1453 * Retrieve OS release information. 1454 * Retrieve OS release information.
1454 */ 1455 */
1455 kvp_get_os_info(); 1456 kvp_get_os_info();
1457 /*
1458 * Cache Fully Qualified Domain Name because getaddrinfo takes an
1459 * unpredictable amount of time to finish.
1460 */
1461 kvp_get_domain_name(full_domain_name, sizeof(full_domain_name));
1456 1462
1457 if (kvp_file_init()) { 1463 if (kvp_file_init()) {
1458 syslog(LOG_ERR, "Failed to initialize the pools"); 1464 syslog(LOG_ERR, "Failed to initialize the pools");
@@ -1671,8 +1677,7 @@ int main(void)
1671 1677
1672 switch (hv_msg->body.kvp_enum_data.index) { 1678 switch (hv_msg->body.kvp_enum_data.index) {
1673 case FullyQualifiedDomainName: 1679 case FullyQualifiedDomainName:
1674 kvp_get_domain_name(key_value, 1680 strcpy(key_value, full_domain_name);
1675 HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1676 strcpy(key_name, "FullyQualifiedDomainName"); 1681 strcpy(key_name, "FullyQualifiedDomainName");
1677 break; 1682 break;
1678 case IntegrationServicesVersion: 1683 case IntegrationServicesVersion: