Skip to content

Commit

Permalink
init: Add support for writing system property value to a file in init.rc
Browse files Browse the repository at this point in the history
The write command will write a property value if the value starts with a "$'

For example:
    write /sys/class/android_usb/iSerial $ro.serialno

Use double leading '$' if you need to write a string that starts with '$':

    write /data/foo $$hello

to write "$hello" to /data/foo

Change-Id: I55431ac7715a5347bb95c3a15aee97c575444dde
  • Loading branch information
mikeandroid committed Jun 9, 2011
1 parent b36f136 commit 2c4d5dc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion init/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,23 @@ int do_sysclktz(int nargs, char **args)

int do_write(int nargs, char **args)
{
return write_file(args[1], args[2]);
char *path = args[1];
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)
Expand Down

0 comments on commit 2c4d5dc

Please sign in to comment.