get_hostname_identifier to not return empty hostnames

When getting the hostname to construct the legacy uvar path, if the
hostname is empty, we will create a path pointing at a directory. On
BSDs this path can be successfully open'd and we will produce errors
about invalid uvar files.
This commit is contained in:
ridiculousfish 2021-09-17 11:17:15 -07:00
parent 6db631ae88
commit 9a2482557d

View File

@ -981,7 +981,8 @@ bool get_hostname_identifier(wcstring &result) {
if (gethostname(hostname, sizeof(hostname)) == 0) {
result.assign(str2wcstring(hostname));
result.assign(truncate(result, HOSTNAME_LEN));
success = true;
// Don't return an empty hostname, we may attempt to open a directory instead.
success = !result.empty();
}
return success;
}