Merge changes I7b4e1ed1,I8a91c3f7,If78d20a5,I55431ac7
* changes:
init: Add support for assigning system properties to system properties in init.rc
init: Fix the init.rc import command
init: Allow wildcards in property triggers by using * for property value
init: Add support for writing system property value to a file in init.rc
diff --git a/init/builtins.c b/init/builtins.c
index 23ef224..bfdd654 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -226,11 +226,6 @@
return do_insmod_inner(nargs, args, size);
}
-int do_import(int nargs, char **args)
-{
- return init_parse_config_file(args[1]);
-}
-
int do_mkdir(int nargs, char **args)
{
mode_t mode = 0755;
@@ -445,7 +440,24 @@
int do_setprop(int nargs, char **args)
{
- property_set(args[1], args[2]);
+ const char *name = args[1];
+ const char *value = args[2];
+
+ if (value[0] == '$') {
+ /* Use the value of a system property if value starts with '$' */
+ value++;
+ if (value[0] != '$') {
+ value = property_get(value);
+ if (!value) {
+ ERROR("property %s has no value for assigning to %s\n", value, name);
+ return -EINVAL;
+ }
+ } /* else fall through to support double '$' prefix for setting properties
+ * to string literals that start with '$'
+ */
+ }
+
+ property_set(name, value);
return 0;
}
@@ -527,7 +539,23 @@
int do_write(int nargs, char **args)
{
- return write_file(args[1], args[2]);
+ const char *path = args[1];
+ const char *value = args[2];
+ if (value[0] == '$') {
+ /* Write the value of a system property if value starts with '$' */
+ value++;
+ if (value[0] != '$') {
+ value = property_get(value);
+ if (!value) {
+ ERROR("property %s has no value for writing to %s\n", value, path);
+ return -EINVAL;
+ }
+ } /* else fall through to support double '$' prefix for writing
+ * string literals that start with '$'
+ */
+ }
+
+ return write_file(path, value);
}
int do_copy(int nargs, char **args)
diff --git a/init/init_parser.c b/init/init_parser.c
index e8e65ac..d9d3084 100644
--- a/init/init_parser.c
+++ b/init/init_parser.c
@@ -179,6 +179,14 @@
return;
}
break;
+ case K_import:
+ if (nargs != 2) {
+ ERROR("single argument needed for import\n");
+ } else {
+ int ret = init_parse_config_file(args[1]);
+ if (ret)
+ ERROR("could not import file %s\n", args[1]);
+ }
}
state->parse_line = parse_line_no_op;
}
@@ -347,7 +355,8 @@
if (!strncmp(name, test, name_length) &&
test[name_length] == '=' &&
- !strcmp(test + name_length + 1, value)) {
+ (!strcmp(test + name_length + 1, value) ||
+ !strcmp(test + name_length + 1, "*"))) {
action_add_queue_tail(act);
}
}
@@ -377,7 +386,8 @@
/* does the property exist, and match the trigger value? */
value = property_get(prop_name);
- if (value && !strcmp(equals + 1, value)) {
+ if (value && (!strcmp(equals + 1, value) ||
+ !strcmp(equals + 1, "*"))) {
action_add_queue_tail(act);
}
}
diff --git a/init/keywords.h b/init/keywords.h
index 95acd01..3e3733f 100644
--- a/init/keywords.h
+++ b/init/keywords.h
@@ -11,7 +11,6 @@
int do_hostname(int nargs, char **args);
int do_ifup(int nargs, char **args);
int do_insmod(int nargs, char **args);
-int do_import(int nargs, char **args);
int do_mkdir(int nargs, char **args);
int do_mount(int nargs, char **args);
int do_restart(int nargs, char **args);
@@ -54,7 +53,7 @@
KEYWORD(hostname, COMMAND, 1, do_hostname)
KEYWORD(ifup, COMMAND, 1, do_ifup)
KEYWORD(insmod, COMMAND, 1, do_insmod)
- KEYWORD(import, COMMAND, 1, do_import)
+ KEYWORD(import, SECTION, 1, 0)
KEYWORD(keycodes, OPTION, 0, 0)
KEYWORD(mkdir, COMMAND, 1, do_mkdir)
KEYWORD(mount, COMMAND, 3, do_mount)