On Wed, 2022-07-20 at 12:45 +0100, Richard W.M. Jones wrote:
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.
Works great for me and looks much more elegant that what I came up
with.
Thanks,
Dawid