aboutsummaryrefslogtreecommitdiffstats
path: root/init/builtins.c
diff options
context:
space:
mode:
authorDima Zavin <dima@android.com>2011-12-20 13:44:41 -0800
committerDima Zavin <dima@android.com>2012-01-05 15:02:28 -0800
commitebe2cb312d36788fa9956ef6829c6aada495606f (patch)
tree416ba8964a1071bebf66e9d10bc4134dd78dd39a /init/builtins.c
parent304f12270dc0be564eb1b64624770aa72f25e59e (diff)
downloadsystem_core-ebe2cb312d36788fa9956ef6829c6aada495606f.tar.gz
system_core-ebe2cb312d36788fa9956ef6829c6aada495606f.tar.bz2
system_core-ebe2cb312d36788fa9956ef6829c6aada495606f.zip
init: use init's property expansion code for setprop/write
Change-Id: I3c284860cc8d5106ac2b086e62baeb6263873935 Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'init/builtins.c')
-rw-r--r--init/builtins.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/init/builtins.c b/init/builtins.c
index eccda3f8..3781dcdc 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -31,6 +31,7 @@
#include <sys/resource.h>
#include <linux/loop.h>
#include <cutils/partition_utils.h>
+#include <sys/system_properties.h>
#include "init.h"
#include "keywords.h"
@@ -448,22 +449,15 @@ int do_setprop(int nargs, char **args)
{
const char *name = args[1];
const char *value = args[2];
+ char prop_val[PROP_VALUE_MAX];
+ int ret;
- 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 '$'
- */
+ ret = expand_props(prop_val, value, sizeof(prop_val));
+ if (ret) {
+ ERROR("cannot expand '%s' while assigning to '%s'\n", value, name);
+ return -EINVAL;
}
-
- property_set(name, value);
+ property_set(name, prop_val);
return 0;
}
@@ -547,21 +541,15 @@ int do_write(int nargs, char **args)
{
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 '$'
- */
- }
+ char prop_val[PROP_VALUE_MAX];
+ int ret;
- return write_file(path, value);
+ ret = expand_props(prop_val, value, sizeof(prop_val));
+ if (ret) {
+ ERROR("cannot expand '%s' while writing to '%s'\n", value, path);
+ return -EINVAL;
+ }
+ return write_file(path, prop_val);
}
int do_copy(int nargs, char **args)