From 650a053795d53d3f5e3054a03b3341e828f58b2c Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Tue, 22 Aug 2023 13:04:03 +0100 Subject: [PATCH 1/2] prepare-root: On a non-A/B androidboot system, boot system slot a Sometimes android bootloaders boot in a nonab way: https://source.android.com/docs/core/ota/nonab In this case, "androidboot." kargs are present but not "androidboot.slot_suffix" specifically. In this case, rather than getting stuck in a partially booted environment, boot system slot a. --- src/switchroot/ostree-prepare-root.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 931672726f..155189b9c5 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -163,6 +163,24 @@ get_aboot_root_slot (const char *slot_suffix) return NULL; } +static bool +proc_cmdline_has_key_starting_with (const char *cmdline, const char *key) +{ + for (const char *iter = cmdline; iter;) + { + if (g_str_has_prefix (iter, key)) + return true; + + iter = strchr (iter, ' '); + if (iter == NULL) + return false; + + iter += strspn (iter, " "); + } + + return false; +} + static inline char * get_ostree_target (const char *cmdline) { @@ -170,6 +188,12 @@ get_ostree_target (const char *cmdline) if (slot_suffix) return get_aboot_root_slot (slot_suffix); + /* Non-A/B androidboot: + * https://source.android.com/docs/core/ota/nonab + */ + if (proc_cmdline_has_key_starting_with (cmdline, "androidboot.")) + return strdup ("/ostree/root.a"); + return find_proc_cmdline_key (cmdline, "ostree"); } From 6e9e50d87c8869882de920c096125af36218ae06 Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Tue, 22 Aug 2023 13:11:30 +0100 Subject: [PATCH 2/2] prepare-root: Changes made to find_proc_cmdline_key Used strspn based on feedback from similar function. --- src/switchroot/ostree-mount-util.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/switchroot/ostree-mount-util.h b/src/switchroot/ostree-mount-util.h index 1c15fe9004..eb79efdfbf 100644 --- a/src/switchroot/ostree-mount-util.h +++ b/src/switchroot/ostree-mount-util.h @@ -87,29 +87,26 @@ cleanup_free (void *p) static inline char * find_proc_cmdline_key (const char *cmdline, const char *key) { - char *ret = NULL; - size_t key_len = strlen (key); - - const char *iter = cmdline; - while (iter != NULL) + const size_t key_len = strlen (key); + for (const char *iter = cmdline; iter;) { const char *next = strchr (iter, ' '); - const char *next_nonspc = next; - while (next_nonspc && *next_nonspc == ' ') - next_nonspc += 1; if (strncmp (iter, key, key_len) == 0 && iter[key_len] == '=') { const char *start = iter + key_len + 1; if (next) - ret = strndup (start, next - start); - else - ret = strdup (start); - break; + return strndup (start, next - start); + + return strdup (start); } - iter = next_nonspc; + + if (next) + next += strspn (next, " "); + + iter = next; } - return ret; + return NULL; } /* This is an API for other projects to determine whether or not the