New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix reading /etc/machine-id in kernel-install #25388
Conversation
The kernel-install script has code to read the contents of /etc/machine-id into the MACHINE_ID variable. Depending on the variable content kernel-install either logs the value or creates a new machine id via 'systemd-id128 new'. In that logic there is one issue. If the file /etc/machine-id exists but is empty, the script tries to call read on an empty file which return with an exit code != 0. As the script code also uses 'set -e', kernel-install will exit at this point which is unexpected. The condition of an empty /etc/machine-id file exists for example when building OS images, which should initialize the system id on first boot but not staticly inside of the image. afaik an empty /etc/machine-id is also a common approach to make systemd indicate that it should create a new system id. Because of this, the commit makes sure the reading of /etc/machine-id does not fail in any case such that the handling of the MACHINE_ID variable takes place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Per review comment use test -s to make sure the subsequent reading of /etc/machine-id is only done if the file exists and has size > 0
btw, to be fully correct we should add code that handles the case where /etc/machine-id contains the string "uninitialized", too. As per man page machine-id(5). |
yes good point. I opened #25407 with a first suggestion how to handle it. Thanks |
* Fix reading /etc/machine-id in kernel-install The kernel-install script has code to read the contents of /etc/machine-id into the MACHINE_ID variable. Depending on the variable content kernel-install either logs the value or creates a new machine id via 'systemd-id128 new'. In that logic there is one issue. If the file /etc/machine-id exists but is empty, the script tries to call read on an empty file which return with an exit code != 0. As the script code also uses 'set -e', kernel-install will exit at this point which is unexpected. The condition of an empty /etc/machine-id file exists for example when building OS images, which should initialize the system id on first boot but not staticly inside of the image. afaik an empty /etc/machine-id is also a common approach to make systemd indicate that it should create a new system id. Because of this, the commit makes sure the reading of /etc/machine-id does not fail in any case such that the handling of the MACHINE_ID variable takes place. (cherry picked from commit 883e7cb)
* Fix reading /etc/machine-id in kernel-install The kernel-install script has code to read the contents of /etc/machine-id into the MACHINE_ID variable. Depending on the variable content kernel-install either logs the value or creates a new machine id via 'systemd-id128 new'. In that logic there is one issue. If the file /etc/machine-id exists but is empty, the script tries to call read on an empty file which return with an exit code != 0. As the script code also uses 'set -e', kernel-install will exit at this point which is unexpected. The condition of an empty /etc/machine-id file exists for example when building OS images, which should initialize the system id on first boot but not staticly inside of the image. afaik an empty /etc/machine-id is also a common approach to make systemd indicate that it should create a new system id. Because of this, the commit makes sure the reading of /etc/machine-id does not fail in any case such that the handling of the MACHINE_ID variable takes place.
The kernel-install script has code to read the contents of /etc/machine-id into the MACHINE_ID variable. Depending on the variable content kernel-install either logs the value or creates a new machine id via 'systemd-id128 new'. In that logic there is one issue. If the file /etc/machine-id exists but is empty, the script tries to call read on an empty file which return with an exit code != 0. As the script code also uses 'set -e', kernel-install will exit at this point which is unexpected. The condition of an empty /etc/machine-id file exists for example when building OS images, which should initialize the system id on first boot but not staticly inside of the image. afaik an empty /etc/machine-id is also a common approach to make systemd indicate that it should create a new system id. Because of this, the commit makes sure the reading of /etc/machine-id does not fail in any case such that the handling of the MACHINE_ID variable takes place. (cherry picked from commit 883e7cb) (cherry picked from commit d34ea41) Backported for https://bugzilla.redhat.com/show_bug.cgi?id=2148464.
The kernel-install script has code to read the contents of
/etc/machine-id
into theMACHINE_ID
variable. Depending on the variable content kernel-install either logs the value or creates a new machine id viasystemd-id128 new
. In that logic there is one issue. If the file/etc/machine-id
exists but is empty, the script tries to call read on an empty file which return with an exit code != 0. As the script code also usesset -e
, kernel-install will exit at this point which is unexpected.The condition of an empty /etc/machine-id file exists for example when building OS images, which should initialize the system id on first boot but not staticly inside of the image. afaik an empty
/etc/machine-id
is also a common approach to make systemd indicate that it should create a new system id. Because of this, the commit makes sure the reading of/etc/machine-id
does not fail in any case such that the handling of the MACHINE_ID variable takes place.