diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-02-03 20:45:58 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-02-03 20:45:59 +0000 |
commit | 564aeca94e18cd708f93619551e05b3d59d4abe2 (patch) | |
tree | 69e5717d8a8a4ad3ece04191bce25fed43492c58 | |
parent | 01b25ab14912712024d5342064c7b70de85e2db8 (diff) | |
parent | 2d0fdaaafc5d2925b8ef7708a950f6b599892b54 (diff) | |
download | system_core-564aeca94e18cd708f93619551e05b3d59d4abe2.tar.gz system_core-564aeca94e18cd708f93619551e05b3d59d4abe2.tar.bz2 system_core-564aeca94e18cd708f93619551e05b3d59d4abe2.zip |
Merge "init: clean up exec command"
-rw-r--r-- | init/builtins.cpp | 8 | ||||
-rw-r--r-- | init/init.cpp | 24 | ||||
-rw-r--r-- | init/init.h | 7 | ||||
-rw-r--r-- | init/service.cpp | 2 |
4 files changed, 33 insertions, 8 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index 965a81fbe..2388edcf7 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -265,10 +265,14 @@ static int do_exec(const std::vector<std::string>& args) { if (!svc) { return -1; } + if (!start_waiting_for_exec()) { + return -1; + } if (!svc->Start()) { + stop_waiting_for_exec(); + ServiceManager::GetInstance().RemoveService(*svc); return -1; } - waiting_for_exec = true; return 0; } @@ -1018,7 +1022,7 @@ static int do_wait_for_prop(const std::vector<std::string>& args) { << "\") failed: value too long"; return -1; } - if (!wait_property(name, value)) { + if (!start_waiting_for_property(name, value)) { LOG(ERROR) << "do_wait_for_prop(\"" << name << "\", \"" << value << "\") failed: init already in waiting"; return -1; diff --git a/init/init.cpp b/init/init.cpp index c8c18d2f3..43f601f69 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -82,7 +82,7 @@ static time_t process_needs_restart_at; 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 @@ int add_environment(const char *key, const char *val) 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 @@ bool wait_property(const char *name, const char *value) 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; } diff --git a/init/init.h b/init/init.h index 4e4da328b..3768c02b2 100644 --- a/init/init.h +++ b/init/init.h @@ -23,7 +23,6 @@ class Action; class Service; extern const char *ENV[32]; -extern bool waiting_for_exec; extern std::string default_console; extern struct selabel_handle *sehandle; extern struct selabel_handle *sehandle_prop; @@ -36,6 +35,10 @@ void register_epoll_handler(int fd, void (*fn)()); int add_environment(const char* key, const char* val); -bool wait_property(const char *name, const char *value); +bool start_waiting_for_exec(); + +void stop_waiting_for_exec(); + +bool start_waiting_for_property(const char *name, const char *value); #endif /* _INIT_INIT_H */ diff --git a/init/service.cpp b/init/service.cpp index 0f7f62fe9..e186f27a8 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -997,7 +997,7 @@ bool ServiceManager::ReapOneProcess() { } if (svc->Reap()) { - waiting_for_exec = false; + stop_waiting_for_exec(); RemoveService(*svc); } |