Always init for resetprop

This commit is contained in:
topjohnwu 2017-06-11 20:22:10 +08:00
parent a5aa1b3917
commit 309b99eac0
3 changed files with 16 additions and 13 deletions

View File

@ -121,8 +121,7 @@ static int usage(char* arg0) {
return 1;
}
int init_resetprop() {
PRINT_D("resetprop: Initializing...\n");
static int init_resetprop() {
if (__system_properties_init2()) {
PRINT_E("resetprop: Initialize error\n");
return -1;
@ -130,15 +129,21 @@ int init_resetprop() {
return 0;
}
int prop_exist(const char *name) {
if (init_resetprop()) return 0;
return __system_property_find2(name) != NULL;
}
static void read_prop_info(void* cookie, const char *name, const char *value, uint32_t serial) {
strcpy((char *) cookie, value);
}
// Get prop by name, return string (should free manually!)
char *getprop(const char *name) {
if (init_resetprop()) return NULL;
const prop_info *pi = __system_property_find2(name);
if (pi == NULL) {
PRINT_D("resetprop: failed to get [%s]\n", name);
PRINT_D("resetprop: prop [%s] does not exist\n", name);
return NULL;
}
char value[PROP_VALUE_MAX];
@ -152,16 +157,16 @@ int setprop(const char *name, const char *value) {
}
int setprop2(const char *name, const char *value, const int trigger) {
if (init_resetprop()) return -1;
int ret;
char *check = getprop(name);
if (check) {
free(check);
prop_info *pi = (prop_info*) __system_property_find2(name);
if (pi != NULL) {
if (trigger) {
if (!strncmp(name, "ro.", 3)) deleteprop(name);
ret = __system_property_set2(name, value);
} else {
ret = __system_property_update2((prop_info*) __system_property_find2(name), value, strlen(value));
ret = __system_property_update2(pi, value, strlen(value));
}
} else {
PRINT_D("resetprop: New prop [%s]\n", name);
@ -182,6 +187,7 @@ int setprop2(const char *name, const char *value, const int trigger) {
}
int deleteprop(const char *name) {
if (init_resetprop()) return -1;
PRINT_D("resetprop: deleteprop [%s]\n", name);
if (__system_property_del(name)) {
PRINT_E("resetprop: delete prop: [%s] error\n", name);
@ -191,6 +197,7 @@ int deleteprop(const char *name) {
}
int read_prop_file(const char* filename, const int trigger) {
if (init_resetprop()) return -1;
PRINT_D("resetprop: Load prop file [%s]\n", filename);
FILE *fp = fopen(filename, "r");
if (fp == NULL) {
@ -277,8 +284,6 @@ int resetprop_main(int argc, char *argv[]) {
}
}
init_resetprop();
if (file) {
return read_prop_file(filename, trigger);
} else if (del) {

View File

@ -8,7 +8,7 @@
extern "C" {
#endif
int init_resetprop();
int prop_exist(const char *name);
int setprop(const char *name, const char *value);
int setprop2(const char *name, const char *value, const int trigger);
char *getprop(const char *name);

View File

@ -1149,9 +1149,7 @@ int __system_properties_init2() {
if (initialized) {
// list_foreach(contexts, [](context_node* l) { l->reset_access(); }); // resetprop remove
// return 0; // resetprop remove
free_and_unmap_contexts(); // resetprop add
initialized = false; // resetprop add
return 0;
}
if (is_dir(property_filename)) {
if (!initialize_properties()) {