switchroot: Make read_proc_cmdline_ostree() take a key argument
authorAlexander Larsson <alexl@redhat.com>
Thu, 18 May 2023 08:53:22 +0000 (10:53 +0200)
committerAlexander Larsson <alexl@redhat.com>
Wed, 31 May 2023 08:57:37 +0000 (10:57 +0200)
This changes it into read_proc_cmdline_key(), as this will later be
used to read additional keys.

src/switchroot/ostree-mount-util.h
src/switchroot/ostree-prepare-root.c
src/switchroot/ostree-system-generator.c

index 9d79f0cb9f4e12e5a428a639b203dd7ddae82d0d..e3b0037a0f37a5f479ce8c0c17944ebe9cc14398 100644 (file)
@@ -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
index f24a568101ad9eab9335c547a917f9c9860ed219..7f1489593e120b7933b6b6808ac97425d146d625 100644 (file)
@@ -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/...");
 
index 33e3d78303712e593ce97ca7a6028851ad4e946b..c045c541a2b12f78e58d61481ed9cd71629cd226 100644 (file)
@@ -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);