summaryrefslogtreecommitdiffstats
path: root/init/property_service.c
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2014-03-19 20:18:01 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-03-19 20:18:01 +0000
commit36fb5fed1f4f2fea5dd2a8cd62f036f54e270f8a (patch)
treea60d05ad76e9d5c34e96c76600fc30b3934222a1 /init/property_service.c
parent8c40dc90c50b202be57be30f297a5ff3c7dc710f (diff)
parentf96b044551d7db8aaef9314e9a217f709749817f (diff)
downloadsystem_core-36fb5fed1f4f2fea5dd2a8cd62f036f54e270f8a.zip
system_core-36fb5fed1f4f2fea5dd2a8cd62f036f54e270f8a.tar.gz
system_core-36fb5fed1f4f2fea5dd2a8cd62f036f54e270f8a.tar.bz2
Merge "Add "import" support to system property files."
Diffstat (limited to 'init/property_service.c')
-rw-r--r--init/property_service.c79
1 files changed, 57 insertions, 22 deletions
diff --git a/init/property_service.c b/init/property_service.c
index cb3f082..10b1cc7 100644
--- a/init/property_service.c
+++ b/init/property_service.c
@@ -457,40 +457,73 @@ void get_property_workspace(int *fd, int *sz)
*sz = pa_workspace.size;
}
-static void load_properties(char *data, char *prefix)
+static void load_properties_from_file(const char *, const char *);
+
+/*
+ * Filter is used to decide which properties to load: NULL loads all keys,
+ * "ro.foo.*" is a prefix match, and "ro.foo.bar" is an exact match.
+ */
+static void load_properties(char *data, const char *filter)
{
- char *key, *value, *eol, *sol, *tmp;
- size_t plen;
+ char *key, *value, *eol, *sol, *tmp, *fn;
+ size_t flen = 0;
+
+ if (filter) {
+ flen = strlen(filter);
+ }
- if (prefix)
- plen = strlen(prefix);
sol = data;
- while((eol = strchr(sol, '\n'))) {
+ while ((eol = strchr(sol, '\n'))) {
key = sol;
*eol++ = 0;
sol = eol;
- value = strchr(key, '=');
- if(value == 0) continue;
- *value++ = 0;
+ while (isspace(*key)) key++;
+ if (*key == '#') continue;
- while(isspace(*key)) key++;
- if(*key == '#') continue;
- tmp = value - 2;
- while((tmp > key) && isspace(*tmp)) *tmp-- = 0;
+ tmp = eol - 2;
+ while ((tmp > key) && isspace(*tmp)) *tmp-- = 0;
- if (prefix && strncmp(key, prefix, plen))
- continue;
+ if (!strncmp(key, "import ", 7) && flen == 0) {
+ fn = key + 7;
+ while (isspace(*fn)) fn++;
- while(isspace(*value)) value++;
- tmp = eol - 2;
- while((tmp > value) && isspace(*tmp)) *tmp-- = 0;
+ key = strchr(fn, ' ');
+ if (key) {
+ *key++ = 0;
+ while (isspace(*key)) key++;
+ }
- property_set(key, value);
+ load_properties_from_file(fn, key);
+
+ } else {
+ value = strchr(key, '=');
+ if (!value) continue;
+ *value++ = 0;
+
+ tmp = value - 2;
+ while ((tmp > key) && isspace(*tmp)) *tmp-- = 0;
+
+ while (isspace(*value)) value++;
+
+ if (flen > 0) {
+ if (filter[flen - 1] == '*') {
+ if (strncmp(key, filter, flen - 1)) continue;
+ } else {
+ if (strcmp(key, filter)) continue;
+ }
+ }
+
+ property_set(key, value);
+ }
}
}
-static void load_properties_from_file(const char *fn, char *prefix)
+/*
+ * Filter is used to decide which properties to load: NULL loads all keys,
+ * "ro.foo.*" is a prefix match, and "ro.foo.bar" is an exact match.
+ */
+static void load_properties_from_file(const char *fn, const char *filter)
{
char *data;
unsigned sz;
@@ -498,7 +531,7 @@ static void load_properties_from_file(const char *fn, char *prefix)
data = read_file(fn, &sz);
if(data != 0) {
- load_properties(data, prefix);
+ load_properties(data, filter);
free(data);
}
}
@@ -611,8 +644,10 @@ void start_property_service(void)
load_properties_from_file(PROP_PATH_SYSTEM_BUILD, NULL);
load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT, NULL);
- load_properties_from_file(PROP_PATH_FACTORY, "ro.");
+ load_properties_from_file(PROP_PATH_FACTORY, "ro.*");
+
load_override_properties();
+
/* Read persistent properties after all default values have been loaded. */
load_persistent_properties();