At Sat, 10 May 2014 22:36:44 -0400, Dave Reisner wrote: > On Sat, May 10, 2014 at 10:22:07PM -0400, Luke Shumaker wrote: > > +#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 | ...
That doesn't work, but this does: cpp -include limits.h <<<HOST_NAME_MAX | ... I'd never had occasion to use that flag before, so thank you! > > +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. Is it any more likely to cause clashes than the existing machine name munging? 64 characters is a lot, and I figure that the end is the part that is most likely to change. What about passing '-q' to systemd-nspawn and not directing its stderr to /dev/null? That way the user gets a reasonably friendly "Failed to register machine: Machine '$machine_name' already exits", as well as a message for any other errors that may occur. IIRC, the reason stderr was directed to /dev/null was that at the time it was written, systemd-nspawn didn't have a '-q' flag. Happy hacking, ~ Luke Shumaker