8327621: Check return value of uname in os::get_host_name

Reviewed-by: dholmes, stuefe
This commit is contained in:
Johan Sjölen 2024-04-10 08:12:47 +00:00
parent bea9acc55a
commit 51ed69a586

View File

@ -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