am c383c6d1: Merge "Add "import" support to system property files."

* commit 'c383c6d1d8b0541d18924c3ef63df9061ee5bd8f':
  Add "import" support to system property files.
This commit is contained in:
Colin Cross 2014-03-19 20:41:36 +00:00 committed by Android Git Automerger
commit 12e3639a6e

View file

@ -439,40 +439,73 @@ void get_property_workspace(int *fd, int *sz)
*sz = pa_workspace.size; *sz = pa_workspace.size;
} }
static void load_properties(char *data, char *prefix) static void load_properties_from_file(const char *, const char *);
{
char *key, *value, *eol, *sol, *tmp; /*
size_t plen; * 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, *fn;
size_t flen = 0;
if (filter) {
flen = strlen(filter);
}
if (prefix)
plen = strlen(prefix);
sol = data; sol = data;
while((eol = strchr(sol, '\n'))) { while ((eol = strchr(sol, '\n'))) {
key = sol; key = sol;
*eol++ = 0; *eol++ = 0;
sol = eol; sol = eol;
value = strchr(key, '='); while (isspace(*key)) key++;
if(value == 0) continue; if (*key == '#') continue;
*value++ = 0;
while(isspace(*key)) key++;
if(*key == '#') continue;
tmp = value - 2;
while((tmp > key) && isspace(*tmp)) *tmp-- = 0;
if (prefix && strncmp(key, prefix, plen))
continue;
while(isspace(*value)) value++;
tmp = eol - 2; tmp = eol - 2;
while((tmp > value) && isspace(*tmp)) *tmp-- = 0; while ((tmp > key) && isspace(*tmp)) *tmp-- = 0;
property_set(key, value); if (!strncmp(key, "import ", 7) && flen == 0) {
fn = key + 7;
while (isspace(*fn)) fn++;
key = strchr(fn, ' ');
if (key) {
*key++ = 0;
while (isspace(*key)) key++;
}
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; char *data;
unsigned sz; unsigned sz;
@ -480,7 +513,7 @@ static void load_properties_from_file(const char *fn, char *prefix)
data = read_file(fn, &sz); data = read_file(fn, &sz);
if(data != 0) { if(data != 0) {
load_properties(data, prefix); load_properties(data, filter);
free(data); free(data);
} }
} }
@ -592,8 +625,10 @@ void start_property_service(void)
load_properties_from_file(PROP_PATH_SYSTEM_BUILD, NULL); load_properties_from_file(PROP_PATH_SYSTEM_BUILD, NULL);
load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT, 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(); load_override_properties();
/* Read persistent properties after all default values have been loaded. */ /* Read persistent properties after all default values have been loaded. */
load_persistent_properties(); load_persistent_properties();