How about this instead?
It actually changes the behaviour slightly. Currently a /etc/hostname
which contains the single character '\n' would return
inspect_get_hostname = "" (which seems wrong). This is the default
/etc/hostname for virt-builder images.
I think this is because in the current code, read_small_file actually
returns “Some [""; ""]”, so it takes the branch where it matches
“| Some (hostname :: _)” which returns empty string.
Anyway, after this patch it returns "unknown" which is documented as
"the hostname could not be determined", which I think is more correct
behaviour. I tested it also on files with blank lines and comments
and so on, and it seems to do what is necessary, although it could do
with a proper regression test.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html