Remove multithreading while calling enter_mpipl

libpdbg which implements the enter_mpipl is not thread-safe
so removing multithreading and creating processes.

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I5ca1ff2f203203b387486d9ed410eb4517443474
diff --git a/procedures/p9/enter_mpreboot.cpp b/procedures/common/enter_mpreboot.cpp
similarity index 68%
rename from procedures/p9/enter_mpreboot.cpp
rename to procedures/common/enter_mpreboot.cpp
index c8ead0c..3c6e2e0 100644
--- a/procedures/p9/enter_mpreboot.cpp
+++ b/procedures/common/enter_mpreboot.cpp
@@ -15,14 +15,15 @@
  */
 
 #include <libpdbg.h>
+#include <sys/wait.h>
+#include <unistd.h>
 
 #include <phosphor-logging/log.hpp>
-#include <thread>
 #include <vector>
 
 namespace openpower
 {
-namespace p9
+namespace misc
 {
 
 /**
@@ -50,7 +51,8 @@
 {
     using namespace phosphor::logging;
     struct pdbg_target* target;
-    std::vector<std::thread> threads;
+    std::vector<pid_t> pidList;
+    bool failed = false;
     pdbg_targets_init(NULL);
 
     log<level::INFO>("Starting memory preserving reboot");
@@ -60,17 +62,43 @@
         {
             continue;
         }
-        std::thread t(sbeEnterMpReboot, target);
-        threads.push_back(std::move(t));
+
+        pid_t pid = fork();
+
+        if (pid < 0)
+        {
+            log<level::ERR>("Fork failed while starting mp reboot");
+            failed = true;
+        }
+        else if (pid == 0)
+        {
+            sbeEnterMpReboot(target);
+            std::exit(EXIT_SUCCESS);
+        }
+        else
+        {
+            pidList.push_back(std::move(pid));
+        }
     }
 
-    for (auto& t : threads)
+    for (auto& p : pidList)
     {
-        t.join();
+        int status = 0;
+        waitpid(p, &status, 0);
+        if (WEXITSTATUS(status))
+        {
+            log<level::ERR>("Memory preserving reboot failed");
+            failed = true;
+        }
+    }
+
+    if (failed)
+    {
+        std::exit(EXIT_FAILURE);
     }
 }
 
 REGISTER_PROCEDURE("enterMpReboot", enterMpReboot);
 
-} // namespace p9
+} // namespace misc
 } // namespace openpower