maintenance: Add waiting for compilation

Wait for iorap.cmd.compiler to terminate, otherwise, the JobScheduler
will now be aware of the full span of time it takes to perform the
complete maintenance.

Bug: 150036585
Test: run maintenance and check the scheduler terminate after
the compilation is done.
Change-Id: Ia1caa72a1081e1181b5842c58c7a74dccc9b0d56
diff --git a/src/maintenance/controller.cc b/src/maintenance/controller.cc
index 6c91ed1..853afcd 100644
--- a/src/maintenance/controller.cc
+++ b/src/maintenance/controller.cc
@@ -32,6 +32,7 @@
 #include <optional>
 #include <vector>
 #include <string>
+#include <sys/wait.h>
 
 namespace iorap::maintenance {
 
@@ -116,6 +117,15 @@
     LOG(FATAL) << "Failed to fork a process for compilation";
   } else if (child > 0) {  // we are the caller of this function
     LOG(DEBUG) << "forked into a process for compilation , pid = " << child;
+
+    int wstatus;
+    waitpid(child, /*out*/&wstatus, /*options*/0);
+    if (!WIFEXITED(wstatus)) {
+      LOG(ERROR) << "Child terminated abnormally, status: " << WEXITSTATUS(wstatus);
+      return false;
+    }
+    LOG(DEBUG) << "Child terminated, status: " << WEXITSTATUS(wstatus);
+
     return true;
   } else {
     // we are the child that was forked.
@@ -255,6 +265,7 @@
                  <<" activity_name: " <<activity_name;
       return false;
     }
+
   }
 
   std::optional<db::PrefetchFileModel> compiled_trace =