init: clean up exec command
Add wait time log for exec service execution time
Fix memory leak when exec service failed to start
Test: on marlin
Bug: 34518530
Change-Id: I01736bd9b1429414f3dc91dd5d02d88a681f0985
diff --git a/init/init.cpp b/init/init.cpp
index c8c18d2..43f601f 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -82,7 +82,7 @@
const char *ENV[32];
-bool waiting_for_exec = false;
+static std::unique_ptr<Timer> waiting_for_exec(nullptr);
static int epoll_fd = -1;
@@ -131,7 +131,24 @@
return -1;
}
-bool wait_property(const char *name, const char *value)
+bool start_waiting_for_exec()
+{
+ if (waiting_for_exec) {
+ return false;
+ }
+ waiting_for_exec.reset(new Timer());
+ return true;
+}
+
+void stop_waiting_for_exec()
+{
+ if (waiting_for_exec) {
+ LOG(INFO) << "Wait for exec took " << *waiting_for_exec;
+ waiting_for_exec.reset();
+ }
+}
+
+bool start_waiting_for_property(const char *name, const char *value)
{
if (waiting_for_prop) {
return false;
@@ -142,7 +159,8 @@
wait_prop_value = value;
waiting_for_prop.reset(new Timer());
} else {
- LOG(INFO) << "wait_property(\"" << name << "\", \"" << value << "\"): already set";
+ LOG(INFO) << "start_waiting_for_property(\""
+ << name << "\", \"" << value << "\"): already set";
}
return true;
}