diff options
| author | Tom Cherry <tomcherry@google.com> | 2017-08-01 17:04:44 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2017-08-01 17:04:44 +0000 |
| commit | 25422816d4acad3c4e4d7cae5eb44c1525ed896d (patch) | |
| tree | c1ffd77c3140292e7575a8fdeea82f8651f37649 /init/init.cpp | |
| parent | 1cb98847d58decba5fc021d69a1df70bfb0913eb (diff) | |
| parent | eb3fa921916f2505d85fe42b780a890f7358f482 (diff) | |
| download | system_core-25422816d4acad3c4e4d7cae5eb44c1525ed896d.tar.gz system_core-25422816d4acad3c4e4d7cae5eb44c1525ed896d.tar.bz2 system_core-25422816d4acad3c4e4d7cae5eb44c1525ed896d.zip | |
Merge "init: fix process restarting"
am: eb3fa92191
Change-Id: Ic03cf607631c49c1d37584f7641d9300a79f5457
Diffstat (limited to 'init/init.cpp')
| -rw-r--r-- | init/init.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/init/init.cpp b/init/init.cpp index c51217e9b..58410982e 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -53,6 +53,7 @@ #include <fstream> #include <memory> +#include <optional> #include <vector> #include "bootchart.h" @@ -84,7 +85,6 @@ static int property_triggers_enabled = 0; static char qemu[32]; std::string default_console = "/dev/console"; -static time_t process_needs_restart_at; const char *ENV[32]; @@ -219,12 +219,21 @@ void property_changed(const std::string& name, const std::string& value) { } } -static void restart_processes() -{ - process_needs_restart_at = 0; - ServiceManager::GetInstance().ForEachServiceWithFlags(SVC_RESTARTING, [](Service* s) { - s->RestartIfNeeded(&process_needs_restart_at); +static std::optional<boot_clock::time_point> RestartProcesses() { + std::optional<boot_clock::time_point> next_process_restart_time; + ServiceManager::GetInstance().ForEachService([&next_process_restart_time](Service* s) { + if (!(s->flags() & SVC_RESTARTING)) return; + + auto restart_time = s->time_started() + 5s; + if (boot_clock::now() > restart_time) { + s->Start(); + } else { + if (!next_process_restart_time || restart_time < *next_process_restart_time) { + next_process_restart_time = restart_time; + } + } }); + return next_process_restart_time; } void handle_control_message(const std::string& msg, const std::string& name) { @@ -1206,12 +1215,16 @@ int main(int argc, char** argv) { am.ExecuteOneCommand(); } if (!(waiting_for_prop || sm.IsWaitingForExec())) { - if (!shutting_down) restart_processes(); - - // If there's a process that needs restarting, wake up in time for that. - if (process_needs_restart_at != 0) { - epoll_timeout_ms = (process_needs_restart_at - time(nullptr)) * 1000; - if (epoll_timeout_ms < 0) epoll_timeout_ms = 0; + if (!shutting_down) { + auto next_process_restart_time = RestartProcesses(); + + // If there's a process that needs restarting, wake up in time for that. + if (next_process_restart_time) { + epoll_timeout_ms = std::chrono::ceil<std::chrono::milliseconds>( + *next_process_restart_time - boot_clock::now()) + .count(); + if (epoll_timeout_ms < 0) epoll_timeout_ms = 0; + } } // If there's more work to do, wake up again immediately. |
