From 51ed69a586105b707ae616f9eba898449bf9fba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sj=C3=B6len?= Date: Wed, 10 Apr 2024 08:12:47 +0000 Subject: [PATCH] 8327621: Check return value of uname in os::get_host_name Reviewed-by: dholmes, stuefe --- src/hotspot/os/posix/os_posix.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/hotspot/os/posix/os_posix.cpp b/src/hotspot/os/posix/os_posix.cpp index 40f160623bf..d2de5b30484 100644 --- a/src/hotspot/os/posix/os_posix.cpp +++ b/src/hotspot/os/posix/os_posix.cpp @@ -621,9 +621,14 @@ void os::print_jni_name_suffix_on(outputStream* st, int args_size) { bool os::get_host_name(char* buf, size_t buflen) { struct utsname name; - uname(&name); - jio_snprintf(buf, buflen, "%s", name.nodename); - return true; + int retcode = uname(&name); + if (retcode != -1) { + jio_snprintf(buf, buflen, "%s", name.nodename); + return true; + } + const char* errmsg = os::strerror(errno); + log_warning(os)("Failed to get host name, error message: %s", errmsg); + return false; } #ifndef _LP64