diff --git a/hyper-v.changes b/hyper-v.changes index 26ec415..8fbce23 100644 --- a/hyper-v.changes +++ b/hyper-v.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Feb 20 16:16:16 UTC 2020 - ohering@suse.de + +- Revert previous non-upstream change for async name resolution + Just use gethostname via hyper-v.kvp.gethostname.patch (bsc#1100758) + ------------------------------------------------------------------- Fri Nov 29 16:41:25 UTC 2019 - ohering@suse.de diff --git a/hyper-v.kvp.gethostname.patch b/hyper-v.kvp.gethostname.patch new file mode 100644 index 0000000..3b757ff --- /dev/null +++ b/hyper-v.kvp.gethostname.patch @@ -0,0 +1,23 @@ +--- a/hyper-v.tools.hv.hv_kvp_daemon.c ++++ b/hyper-v.tools.hv.hv_kvp_daemon.c +@@ -1335,6 +1335,7 @@ kvp_get_domain_name(char *buffer, int le + struct addrinfo hints, *info ; + int error = 0; + ++ return; + gethostname(buffer, length); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */ +@@ -1572,6 +1573,12 @@ int main(int argc, char *argv[]) + + switch (hv_msg->body.kvp_enum_data.index) { + case FullyQualifiedDomainName: ++ /* ++ * The API is undocumented. ++ * The Host can not possibly care about DNS within the guest network ++ * The time it takes to get the hostname is much shorter than a DNS lookup. ++ */ ++ gethostname(full_domain_name, sizeof(full_domain_name)); + strcpy(key_value, full_domain_name); + strcpy(key_name, "FullyQualifiedDomainName"); + break; diff --git a/hyper-v.spec b/hyper-v.spec index 7b65855..d8ee039 100644 --- a/hyper-v.spec +++ b/hyper-v.spec @@ -61,7 +61,7 @@ Source20: hyper-v.tools.hv.hv_get_dhcp_info.sh Source21: hyper-v.tools.hv.hv_get_dns_info.sh Source22: hyper-v.tools.hv.hv_set_ifconfig.sh -BuildRoot: %{_tmppath}/%{name}-%{version}-build +Patch0: hyper-v.kvp.gethostname.patch %description This package contains the Microsoft Hyper-V tools. @@ -70,9 +70,11 @@ This package contains the Microsoft Hyper-V tools. %setup -Tc cp -avL %{S:5} kvptest.ps1.txt cp -vL %{S:9} %{hv_kvp_daemon}.h -cp -vL %{S:10} %{hv_kvp_daemon}.c +cp -vL %{S:10} . cp -vL %{S:12} %{hv_vss_daemon}.c -cp -vL %{S:14} %{hv_fcopy_daemon}.c +cp -vL %{S:14} %{hv_fcopy_daemon}.c +%patch0 -p1 +mv `basename %{S:10}` %{hv_kvp_daemon}.c %build sed -i~ '/#include /d' %{hv_kvp_daemon}.c @@ -237,7 +239,6 @@ ln -sfvbn ../../etc/init.d/%{hv_fcopy_daemon} $RPM_BUILD_ROOT${bindir}/rc%{hv_fc %endif %files -%defattr (-,root,root) %doc kvptest.ps1.txt %if %{use_systemd} %{_unitdir} diff --git a/hyper-v.tools.hv.hv_kvp_daemon.c b/hyper-v.tools.hv.hv_kvp_daemon.c index 01ebbab..7986e62 100644 --- a/hyper-v.tools.hv.hv_kvp_daemon.c +++ b/hyper-v.tools.hv.hv_kvp_daemon.c @@ -41,7 +41,6 @@ #include #include #include -#include /* * KVP protocol: The user mode component first registers with the @@ -86,7 +85,7 @@ static char *processor_arch; static char *os_build; static char *os_version; static char *lic_version = "Unknown version"; -static char *full_domain_name; +static char full_domain_name[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; static struct utsname uts_buf; /* @@ -1329,76 +1328,27 @@ setval_error: return error; } -/* - * Async retrival of Fully Qualified Domain Name because getaddrinfo takes an - * unpredictable amount of time to finish. - */ -static void *kvp_getaddrinfo(void *p) + +static void +kvp_get_domain_name(char *buffer, int length) { - char *tmp, **str_ptr = (char **)p; - char hostname[HOST_NAME_MAX + 1]; - struct addrinfo *info, hints = { - .ai_family = AF_INET, /* Get only ipv4 addrinfo. */ - .ai_socktype = SOCK_STREAM, - .ai_flags = AI_CANONNAME, - }; - int ret; - int prev_ret = 0, cnt = 5; + struct addrinfo hints, *info ; + int error = 0; - do { - if (gethostname(hostname, sizeof(hostname) - 1) < 0) - goto out; + gethostname(buffer, length); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */ + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_CANONNAME; - ret = getaddrinfo(hostname, NULL, &hints, &info); - switch (ret) { - case 0: - break; - case EAI_BADFLAGS: - case EAI_MEMORY: - case EAI_OVERFLOW: - case EAI_SOCKTYPE: - case EAI_SYSTEM: - /* Permanent failure */ - syslog(LOG_ERR, "getaddrinfo failed: %d %s", - ret, gai_strerror(ret)); - goto out; - default: - /* runtime debug */ - if (cnt) { - if (prev_ret != ret) { - prev_ret = ret; - syslog(LOG_ERR, "getaddrinfo warning: %d %s", ret, gai_strerror(ret)); - cnt--; - } - } - /* Temporary failure, aim for success. */ - sleep(5); - } - } while (ret); - - ret = asprintf(&tmp, "%s", info->ai_canonname); - freeaddrinfo(info); - if (ret <= 0) - goto out; - - if (ret > HV_KVP_EXCHANGE_MAX_VALUE_SIZE) - tmp[HV_KVP_EXCHANGE_MAX_VALUE_SIZE - 1] = '\0'; - *str_ptr = tmp; - -out: - pthread_exit(NULL); -} - -static void kvp_obtain_domain_name(char **str_ptr) -{ - pthread_t t; - - if (pthread_create(&t, NULL, kvp_getaddrinfo, str_ptr)) { - syslog(LOG_ERR, "pthread_create failed; error: %d %s", - errno, strerror(errno)); + error = getaddrinfo(buffer, NULL, &hints, &info); + if (error != 0) { + snprintf(buffer, length, "getaddrinfo failed: 0x%x %s", + error, gai_strerror(error)); return; } - pthread_detach(t); + snprintf(buffer, length, "%s", info->ai_canonname); + freeaddrinfo(info); } void print_usage(char *argv[]) @@ -1463,7 +1413,11 @@ int main(int argc, char *argv[]) * Retrieve OS release information. */ kvp_get_os_info(); - kvp_obtain_domain_name(&full_domain_name); + /* + * 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"); @@ -1618,7 +1572,7 @@ int main(int argc, char *argv[]) switch (hv_msg->body.kvp_enum_data.index) { case FullyQualifiedDomainName: - strcpy(key_value, full_domain_name ? : ""); + strcpy(key_value, full_domain_name); strcpy(key_name, "FullyQualifiedDomainName"); break; case IntegrationServicesVersion: