ostree-prepare-root: enabler for simpler kernel arg
authorGatis Paeglis <gatis.paeglis@qt.io>
Fri, 12 Aug 2016 06:50:29 +0000 (08:50 +0200)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 10 Jan 2018 13:52:58 +0000 (13:52 +0000)
With the current approach, when ostree-prepare-root is used
on the kernel command line as init=, it always assumes that
the next value in the argument list is a path to the sysroot.
The code for falling back to a default path (if none is provided),
would only work if init= is the last arg in the argument list.
We can not rely on that and have to explicitly provide the
path to the sysroot. Which defeats the purpose of a default
path selection code.

To keep command line neater assume that sysroot is on / when
using ostree-prepare-root as init. This probably is what most
people want anyways. Also _ostree_kernel_args* API assumes
that args are space separated list. Which is problematic for:
"init=${ostree}/usr/lib/ostree/ostree-prepare-root /" as it
gets split in two.

Closes: #1401
Approved by: cgwalters

src/switchroot/ostree-prepare-root.c

index 9b8c33818ee42e07188c6419992f40eb34864529..43e15fcc3d7315d1468de225aada2a633845165c 100644 (file)
@@ -102,10 +102,16 @@ main(int argc, char *argv[])
   struct stat stbuf;
   int we_mounted_proc = 0;
 
-  if (argc < 2)
-    root_arg = "/";
+  if (getpid() == 1)
+    {
+      root_arg = "/";
+    }
   else
-    root_arg = argv[1];
+    {
+      if (argc < 2)
+        err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT");
+      root_arg = argv[1];
+    }
 
   if (stat ("/proc/cmdline", &stbuf) < 0)
     {