From bba3109fe2a746b59424369f839c8380fb9b35a7 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 18 May 2023 10:53:22 +0200 Subject: [PATCH] switchroot: Make read_proc_cmdline_ostree() take a key argument This changes it into read_proc_cmdline_key(), as this will later be used to read additional keys. --- src/switchroot/ostree-mount-util.h | 7 ++++--- src/switchroot/ostree-prepare-root.c | 2 +- src/switchroot/ostree-system-generator.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/switchroot/ostree-mount-util.h b/src/switchroot/ostree-mount-util.h index 9d79f0cb..e3b0037a 100644 --- a/src/switchroot/ostree-mount-util.h +++ b/src/switchroot/ostree-mount-util.h @@ -73,11 +73,12 @@ out: } static inline char * -read_proc_cmdline_ostree (void) +read_proc_cmdline_key (const char *key) { char *cmdline = NULL; const char *iter; char *ret = NULL; + size_t key_len = strlen (key); cmdline = read_proc_cmdline (); if (!cmdline) @@ -90,9 +91,9 @@ read_proc_cmdline_ostree (void) const char *next_nonspc = next; while (next_nonspc && *next_nonspc == ' ') next_nonspc += 1; - if (strncmp (iter, "ostree=", strlen ("ostree=")) == 0) + if (strncmp (iter, key, key_len) == 0 && iter[key_len] == '=') { - const char *start = iter + strlen ("ostree="); + const char *start = iter + key_len + 1; if (next) ret = strndup (start, next - start); else diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index f24a5681..7f148959 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -135,7 +135,7 @@ resolve_deploy_path (const char *root_mountpoint) struct stat stbuf; char *ostree_target, *deploy_path; - ostree_target = read_proc_cmdline_ostree (); + ostree_target = read_proc_cmdline_key ("ostree"); if (!ostree_target) errx (EXIT_FAILURE, "No OSTree target; expected ostree=/ostree/boot.N/..."); diff --git a/src/switchroot/ostree-system-generator.c b/src/switchroot/ostree-system-generator.c index 33e3d783..c045c541 100644 --- a/src/switchroot/ostree-system-generator.c +++ b/src/switchroot/ostree-system-generator.c @@ -63,7 +63,7 @@ main (int argc, char *argv[]) * exit so that we don't error, but at the same time work where switchroot * is PID 1 (and so hasn't created /run/ostree-booted). */ - char *ostree_cmdline = read_proc_cmdline_ostree (); + char *ostree_cmdline = read_proc_cmdline_key ("ostree"); if (!ostree_cmdline) exit (EXIT_SUCCESS); -- 2.30.2