From e59f8085964c6ee7f97d03f273339bf0ef15dbde Mon Sep 17 00:00:00 2001
From: James Bottomley <James.Bottomley@HansenPartnership.com>
Date: Mon, 15 Jan 2024 16:15:18 -0500
Subject: [PATCH] Add option to re-exec init for normal boot

By sending SIGUSR1 to init.

Change-Id: I6d322133c1d42c129dda487191b8ffe2371d6af2
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 recovery.cpp                             | 1 +
 recovery_main.cpp                        | 5 +++++
 recovery_ui/device.cpp                   | 1 +
 recovery_ui/include/recovery_ui/device.h | 1 +
 4 files changed, 8 insertions(+)

diff --git a/recovery.cpp b/recovery.cpp
index a2c5682a..3f2dfc79 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -499,6 +499,7 @@ change_menu:
       case Device::REBOOT_FASTBOOT:
       case Device::REBOOT_RECOVERY:
       case Device::REBOOT_RESCUE:
+      case Device::NORMAL_BOOT:
         return chosen_action;
 
       case Device::REBOOT:
diff --git a/recovery_main.cpp b/recovery_main.cpp
index c105e71b..97f4a845 100644
--- a/recovery_main.cpp
+++ b/recovery_main.cpp
@@ -604,6 +604,11 @@ int main(int argc, char** argv) {
         }
         break;
 
+      case Device::NORMAL_BOOT:
+        ui->Print("Sending signal to init to begin normal boot\n");
+        kill(1, SIGUSR1);
+        break;
+
       case Device::ENTER_RECOVERY:
         LOG(INFO) << "Entering recovery";
         fastboot = false;
diff --git a/recovery_ui/device.cpp b/recovery_ui/device.cpp
index e950ea65..dd72250a 100644
--- a/recovery_ui/device.cpp
+++ b/recovery_ui/device.cpp
@@ -48,6 +48,7 @@ static std::vector<menu_action_t> g_advanced_actions{
   { "Run graphics test", Device::RUN_GRAPHICS_TEST },
   { "Run locale test", Device::RUN_LOCALE_TEST },
   { "Enter rescue", Device::ENTER_RESCUE },
+  { "Exex normal boot", Device::NORMAL_BOOT },
   { "Power off", Device::SHUTDOWN },
 };
 
diff --git a/recovery_ui/include/recovery_ui/device.h b/recovery_ui/include/recovery_ui/device.h
index c2fc38dd..1da13a87 100644
--- a/recovery_ui/include/recovery_ui/device.h
+++ b/recovery_ui/include/recovery_ui/device.h
@@ -69,6 +69,7 @@ class Device {
     REBOOT_RESCUE = 19,
     REBOOT_FROM_FASTBOOT = 20,
     SHUTDOWN_FROM_FASTBOOT = 21,
+    NORMAL_BOOT = 22,
     WIPE_SYSTEM = 100,
     ENABLE_ADB = 101,
     MENU_BASE = 200,
-- 
2.43.0

