Start user-specified init (init=) 16/315516/4 sandbox/lstelmach/proc-cmdline-init
authorŁukasz Stelmach <l.stelmach@samsung.com>
Fri, 22 Nov 2024 17:55:12 +0000 (18:55 +0100)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Wed, 8 Jan 2025 21:36:04 +0000 (22:36 +0100)
Change-Id: Ib12140305ffbfeb800173fb534483940170943e6
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
scripts/init.sh

index b748e949aee2b22f5f42d4422d47f48fd397a25b..2ba5865d6ad3af791bd93ae0b563e6a178d07087 100755 (executable)
@@ -478,7 +478,9 @@ function pivot_root()
 function change_root()
 {
     ADDON=
-    INIT_BINARY=/sbin/init
+    INIT_BINARY=$([[ $(</proc/cmdline) =~ (^|[[:space:]])init=([^[:space:]]*) ]]; echo ${BASH_REMATCH[2]})
+    INIT_BINARY=${INIT_BINARY:-/sbin/init}
+
     if [ "$BOOT_MODE" == "fota" ]; then
         ADDON="--unit=online-update.target"
         INIT_BINARY=/usr/lib/systemd/systemd
@@ -488,12 +490,12 @@ function change_root()
     then
         if [ "$IN_INITRD" = "1" ]
         then
-            exec chroot . "$INIT_BINARY" "$ADDON" $@
+            exec chroot . "$INIT_BINARY" $ADDON $@
         elif [ "$IN_INITRAMFS" = "1" ]
         then
-            exec switch_root $ROOTFS_MNT "$INIT_BINARY" "$ADDON" $@
+            exec switch_root $ROOTFS_MNT "$INIT_BINARY" $ADDON $@
         else
-            exec /usr/lib/systemd/systemd "$ADDON" $@
+            exec /usr/lib/systemd/systemd $ADDON $@
         fi
     fi
 }