Portage assumes that the HOSTNAME environment variable is present [1], and uses it as part of resetting an xterm window title. This results in nonsense when it is not, as on my systems; it appears as "root@:/your/cwd". This manifests most obviously during the end of depclean (immediately before returning to the shell) and, based upon reading the source code callers, would manifest during any emerge operation. I suggest reading /etc/hostname or /proc/sys/kernel/hostname or something instead. Alternatively, have Portage set the HOSTNAME environment variable in its own process when it is started, based on the contents of one of those, if it is missing. [1] https://gitweb.gentoo.org/proj/portage.git/tree/lib/portage/output.py#n340
Created attachment 923183 [details] When HOSTNAME is missing from the environment
Created attachment 923184 [details] When HOSTNAME is manually added to /etc/env.d/
gethostname(2) is another possibility, if there is a Python binding for that.