[arch-projects] [devtools] [PATCH 5/9] arch-nspawn: Avoid errors where $working_dir is longer than HOST_NAME_MAX.

Dave Reisner d at falconindy.com
Sat May 10 22:36:44 EDT 2014


On Sat, May 10, 2014 at 10:22:07PM -0400, Luke Shumaker wrote:
> 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')"

No need to write the include as if this were a source file, just tell
cpp about it directly:

  cpp -I limits.h <<<HOST_NAME_MAX | ...

> +HOST_NAME_MAX=64
> +if [[ ${#machine_name} -gt "$HOST_NAME_MAX" ]]; then
> +	machine_name="${machine_name:(-${HOST_NAME_MAX})}"
> +	machine_name="${machine_name#-}"

I think this is worth warning about, since it might result in name
clashes.

> +fi
>  
>  exec ${CARCH:+setarch "$CARCH"} systemd-nspawn 2>/dev/null \
>  	-D "$working_dir" \
> -- 
> 1.9.2
> 


More information about the arch-projects mailing list