Currently, if absolute path of the chroot directory is more than 65 bytes (HOST_NAME_MAX+1) long, arch-nspawn will fail (mysteriously too, since stderr is directed to /dev/null). This patch makes it so that if $machine_name is more than 64 (HOST_NAME_MAX) bytes long, it is stripped to use just the last 64 bytes. I left in a comment that would have it find HOST_NAME_MAX dynamically, but have it just hard-coded as '64'; the script already isn't portable away from systemd/Linux, and it likely won't change on Linux anytime soon. --- arch-nspawn.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch-nspawn.in b/arch-nspawn.in index 15db2e9..df3a08f 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -96,6 +96,12 @@ eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") machine_name="${working_dir//[![:alnum:]_-]/-}" machine_name="${machine_name#-}" +#HOST_NAME_MAX="$(printf '%s\n' '#include <limits.h>' 'HOST_NAME_MAX'|cpp -|sed -n '$p')" +HOST_NAME_MAX=64 +if [[ ${#machine_name} -gt "$HOST_NAME_MAX" ]]; then + machine_name="${machine_name:(-${HOST_NAME_MAX})}" + machine_name="${machine_name#-}" +fi exec ${CARCH:+setarch "$CARCH"} systemd-nspawn 2>/dev/null \ -D "$working_dir" \ -- 1.9.2