OpenNebula / addon-context-linux

Linux VM Contextualization
Apache License 2.0
56 stars 73 forks source link

B OpenNebula/one#6174: Consider /etc/hosts being empty #297

Closed dann1 closed 1 year ago

dann1 commented 1 year ago

populating /etc/hosts fails on DockerHub images because the file exists, but it is empty. So this condition triggers

elif [ -f /etc/hosts ]; then
        # In FreeBSD, sed doesn't interpret \n. We put a real newline.
        eval "${SED_I} -e \"1s/^/${entry}\"$'\\\\\n/' /etc/hosts"

and nothing happens. Now it is -s which will check both that the file exists and is not empty. When empty, next condition (else) will be checked and the entry will be forcibly written.

Some linting as well

Closes OpenNebula/one#6174

No doc PR required since it is a context problem. When the release is made it will be added to the context changelog