[PATCH 2/2] common: blspec: Both environment and config file machine-id must match

Cory Tusar Cory.Tusar at zii.aero
Fri Jun 14 13:35:11 PDT 2019

The original logic for determining whether or not to consider a blspec
entry as "matching" would return a false positive for cases in which a
machine-id was specified in a particular blspec configuration file, but
no such value was present in the environment.

This commit modifies that logic such that a machine-id is considered to
be "matching" ONLY if the values are identical in both the environment
and configuration file, OR if there is no machine-id specified in either
the environment or the configuration file.

Instances where a machine-id is specified in only one location will no
longer be considered a match, nor will instances where the UUID values
themselves differ.

Tested on a number of ZII platforms where we use a machine-id value to
differentiate between active and inactive OS partitions.

Signed-off-by: Cory Tusar <cory.tusar at zii.aero>
 common/blspec.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/common/blspec.c b/common/blspec.c
index 41f2a4c53..59859c9b3 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -430,16 +430,14 @@ out:
 static bool entry_is_match_machine_id(struct blspec_entry *entry)
-	int ret = true;
 	const char *env_machineid = getenv_nonempty("global.boot.machine_id");
+	const char *machineid = blspec_entry_var_get(entry, "machine-id");
+	bool ret = !!env_machineid == !!machineid;
-	if (env_machineid) {
-		const char *machineid = blspec_entry_var_get(entry, "machine-id");
-		if (!machineid || strcmp(machineid, env_machineid)) {
-			pr_debug("ignoring entry with missmatched machine-id " \
-				"\"%s\" != \"%s\"\n", env_machineid, machineid);
-			ret = false;
-		}
+	if (env_machineid && machineid && strcmp(env_machineid, machineid)) {
+		pr_info("ignoring entry with mismatched machine-id " \
+			"\"%s\" != \"%s\"\n", env_machineid, machineid);
+		ret = false;
 	return ret;

More information about the barebox mailing list