summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-07-24 18:17:16 -0700
committerYabin Cui <yabinc@google.com>2015-07-24 18:17:16 -0700
commitee530065648d7fdf1bb80c76385cc54a6d661dc8 (patch)
tree84f77ac82af9bf8472f6b4507093b5d22290f2b5 /init
parent00ede7d2626f9343d330dc6f5286bba3e99e41d0 (diff)
downloadcore-ee530065648d7fdf1bb80c76385cc54a6d661dc8.tar.gz
core-ee530065648d7fdf1bb80c76385cc54a6d661dc8.tar.bz2
core-ee530065648d7fdf1bb80c76385cc54a6d661dc8.zip
init: expand_props for onrestart commands.
It is only a temporary fix. I hope the code can be moved into a member function of class Command. Bug: 22654233 Change-Id: I38c24fb624e54986a953f44d398b3b80c3795d24
Diffstat (limited to 'init')
-rw-r--r--init/init.cpp24
-rw-r--r--init/init.h1
-rw-r--r--init/signal_handler.cpp9
3 files changed, 25 insertions, 9 deletions
diff --git a/init/init.cpp b/init/init.cpp
index 42eebe129..c66c487da 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -585,6 +585,19 @@ std::string build_triggers_string(struct action *cur_action) {
return result;
}
+bool expand_command_arguments(int nargs, char** args, std::vector<std::string>* expanded_args) {
+ std::vector<std::string>& strs = *expanded_args;
+ strs.resize(nargs);
+ strs[0] = args[0];
+ for (int i = 1; i < nargs; ++i) {
+ if (expand_props(args[i], &strs[i]) == -1) {
+ ERROR("%s: cannot expand '%s'\n", args[0], args[i]);
+ return false;
+ }
+ }
+ return true;
+}
+
void execute_one_command() {
Timer t;
@@ -606,14 +619,9 @@ void execute_one_command() {
return;
}
int result = 0;
- std::vector<std::string> arg_strs(cur_command->nargs);
- arg_strs[0] = cur_command->args[0];
- for (int i = 1; i < cur_command->nargs; ++i) {
- if (expand_props(cur_command->args[i], &arg_strs[i]) == -1) {
- ERROR("%s: cannot expand '%s'\n", cur_command->args[0], cur_command->args[i]);
- result = -EINVAL;
- break;
- }
+ std::vector<std::string> arg_strs;
+ if (!expand_command_arguments(cur_command->nargs, cur_command->args, &arg_strs)) {
+ result = -EINVAL;
}
if (result == 0) {
std::vector<char*> args;
diff --git a/init/init.h b/init/init.h
index d81273322..d2b2dfb30 100644
--- a/init/init.h
+++ b/init/init.h
@@ -161,5 +161,6 @@ int selinux_reload_policy(void);
void zap_stdio(void);
void register_epoll_handler(int fd, void (*fn)());
+bool expand_command_arguments(int nargs, char** args, std::vector<std::string>* expanded_args);
#endif /* _INIT_INIT_H */
diff --git a/init/signal_handler.cpp b/init/signal_handler.cpp
index 39a466dee..68931632f 100644
--- a/init/signal_handler.cpp
+++ b/init/signal_handler.cpp
@@ -136,7 +136,14 @@ static bool wait_for_one_process() {
struct listnode* node;
list_for_each(node, &svc->onrestart.commands) {
command* cmd = node_to_item(node, struct command, clist);
- cmd->func(cmd->nargs, cmd->args);
+ std::vector<std::string> arg_strs;
+ if (expand_command_arguments(cmd->nargs, cmd->args, &arg_strs)) {
+ std::vector<char*> args;
+ for (auto& s : arg_strs) {
+ args.push_back(&s[0]);
+ }
+ cmd->func(args.size(), &args[0]);
+ }
}
svc->NotifyStateChange("restarting");
return true;