Skip to content

Commit 76653f2

Browse files
author
Requiem
committed
fix: made VM::HYPERV_HOSTNAME cross-platform
1 parent 8dff22a commit 76653f2

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/vmaware.hpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,7 +4240,7 @@ struct VM {
42404240
}
42414241
u16 cycleThreshold = 1200;
42424242
if (util::hyper_x() == HYPERV_ARTIFACT_VM) {
4243-
cycleThreshold = 15000; // if we're running under Hyper-V, attempt to detect nested virtualization only
4243+
cycleThreshold = 8000; // if we're running under Hyper-V, attempt to detect nested virtualization only
42444244
}
42454245

42464246
#if (WINDOWS)
@@ -5624,14 +5624,28 @@ struct VM {
56245624
* @implements VM::HYPERV_HOSTNAME
56255625
*/
56265626
[[nodiscard]] static bool hyperv_hostname() {
5627+
std::string hostname;
5628+
5629+
#if (WINDOWS)
56275630
char buf[MAX_COMPUTERNAME_LENGTH + 1];
56285631
DWORD len = sizeof(buf);
56295632

5630-
if (!GetComputerNameA(buf, &len)) {
5633+
if (GetComputerNameA(buf, &len)) {
5634+
hostname.assign(buf, len);
5635+
}
5636+
else {
56315637
return false;
56325638
}
5639+
#elif (LINUX)
5640+
char buf[HOST_NAME_MAX];
56335641

5634-
std::string hostname(buf, len);
5642+
if (gethostname(buf, sizeof(buf)) == 0) {
5643+
hostname = buf;
5644+
}
5645+
else {
5646+
return false;
5647+
}
5648+
#endif
56355649

56365650
const char* prefix = "runnervm";
56375651
const std::size_t prefix_len = std::strlen(prefix);

0 commit comments

Comments
 (0)