Merge "init: clean up exec command" am: 564aeca94e am: b1a519a2bd

am: acc81455a1

Change-Id: Id9548bea7f8a77cbf8b20c8007a561fa06049d95
This commit is contained in:
Wei Wang 2017-02-03 20:57:35 +00:00 committed by android-build-merger
commit d8d64be608
4 changed files with 34 additions and 9 deletions

View file

@ -265,10 +265,14 @@ static int do_exec(const std::vector<std::string>& args) {
if (!svc) { if (!svc) {
return -1; return -1;
} }
if (!svc->Start()) { if (!start_waiting_for_exec()) {
return -1;
}
if (!svc->Start()) {
stop_waiting_for_exec();
ServiceManager::GetInstance().RemoveService(*svc);
return -1; return -1;
} }
waiting_for_exec = true;
return 0; return 0;
} }
@ -1018,7 +1022,7 @@ static int do_wait_for_prop(const std::vector<std::string>& args) {
<< "\") failed: value too long"; << "\") failed: value too long";
return -1; return -1;
} }
if (!wait_property(name, value)) { if (!start_waiting_for_property(name, value)) {
LOG(ERROR) << "do_wait_for_prop(\"" << name << "\", \"" << value LOG(ERROR) << "do_wait_for_prop(\"" << name << "\", \"" << value
<< "\") failed: init already in waiting"; << "\") failed: init already in waiting";
return -1; return -1;

View file

@ -82,7 +82,7 @@ static time_t process_needs_restart_at;
const char *ENV[32]; const char *ENV[32];
bool waiting_for_exec = false; static std::unique_ptr<Timer> waiting_for_exec(nullptr);
static int epoll_fd = -1; static int epoll_fd = -1;
@ -131,7 +131,24 @@ int add_environment(const char *key, const char *val)
return -1; 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) { if (waiting_for_prop) {
return false; return false;
@ -142,7 +159,8 @@ bool wait_property(const char *name, const char *value)
wait_prop_value = value; wait_prop_value = value;
waiting_for_prop.reset(new Timer()); waiting_for_prop.reset(new Timer());
} else { } else {
LOG(INFO) << "wait_property(\"" << name << "\", \"" << value << "\"): already set"; LOG(INFO) << "start_waiting_for_property(\""
<< name << "\", \"" << value << "\"): already set";
} }
return true; return true;
} }

View file

@ -23,7 +23,6 @@ class Action;
class Service; class Service;
extern const char *ENV[32]; extern const char *ENV[32];
extern bool waiting_for_exec;
extern std::string default_console; extern std::string default_console;
extern struct selabel_handle *sehandle; extern struct selabel_handle *sehandle;
extern struct selabel_handle *sehandle_prop; 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); 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 */ #endif /* _INIT_INIT_H */

View file

@ -997,7 +997,7 @@ bool ServiceManager::ReapOneProcess() {
} }
if (svc->Reap()) { if (svc->Reap()) {
waiting_for_exec = false; stop_waiting_for_exec();
RemoveService(*svc); RemoveService(*svc);
} }